Add deprecation notice to ImageStore (#23330)
Summary: - Related: #23313 - ImageStore is **iOS only**. AFAIK there is no reason this functionality isn't available on Android. - base64 is very inefficient with the React Native bridge - Ideally the `FileSystem` solutions will integrate Turbo Modules to circumvent bridge issues by passing direct references to files. * [General][added] - A deprecation notice with info about third-party solutions for getting a base64-encoded string. * [General][fixed] - Missing warnings for unimplemented platform methods. Pull Request resolved: https://github.com/facebook/react-native/pull/23330 Differential Revision: D14022159 Pulled By: cpojer fbshipit-source-id: 2a026ebf47cb315e9a0cfe6e3697a1799c5cbe2c
This commit is contained in:
parent
d2fc19f4aa
commit
62599fa8ff
|
@ -11,6 +11,19 @@
|
|||
|
||||
const RCTImageStoreManager = require('NativeModules').ImageStoreManager;
|
||||
|
||||
const Platform = require('Platform');
|
||||
|
||||
const warnOnce = require('warnOnce');
|
||||
|
||||
function warnUnimplementedMethod(methodName: string): void {
|
||||
warnOnce(
|
||||
`imagestore-${methodName}`,
|
||||
`react-native: ImageStore.${methodName}() is not implemented on ${
|
||||
Platform.OS
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
class ImageStore {
|
||||
/**
|
||||
* Check if the ImageStore contains image data for the specified URI.
|
||||
|
@ -20,7 +33,7 @@ class ImageStore {
|
|||
if (RCTImageStoreManager.hasImageForTag) {
|
||||
RCTImageStoreManager.hasImageForTag(uri, callback);
|
||||
} else {
|
||||
console.warn('hasImageForTag() not implemented');
|
||||
warnUnimplementedMethod('hasImageForTag');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +49,7 @@ class ImageStore {
|
|||
if (RCTImageStoreManager.removeImageForTag) {
|
||||
RCTImageStoreManager.removeImageForTag(uri);
|
||||
} else {
|
||||
console.warn('removeImageForTag() not implemented');
|
||||
warnUnimplementedMethod('removeImageForTag');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +69,15 @@ class ImageStore {
|
|||
success: (uri: string) => void,
|
||||
failure: (error: any) => void,
|
||||
) {
|
||||
RCTImageStoreManager.addImageFromBase64(base64ImageData, success, failure);
|
||||
if (RCTImageStoreManager.addImageFromBase64) {
|
||||
RCTImageStoreManager.addImageFromBase64(
|
||||
base64ImageData,
|
||||
success,
|
||||
failure,
|
||||
);
|
||||
} else {
|
||||
warnUnimplementedMethod('addImageFromBase64');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +96,11 @@ class ImageStore {
|
|||
success: (base64ImageData: string) => void,
|
||||
failure: (error: any) => void,
|
||||
) {
|
||||
RCTImageStoreManager.getBase64ForTag(uri, success, failure);
|
||||
if (RCTImageStoreManager.getBase64ForTag) {
|
||||
RCTImageStoreManager.getBase64ForTag(uri, success, failure);
|
||||
} else {
|
||||
warnUnimplementedMethod('getBase64ForTag');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,13 @@ module.exports = {
|
|||
return require('ImageEditor');
|
||||
},
|
||||
get ImageStore() {
|
||||
warnOnce(
|
||||
'imagestore-deprecation',
|
||||
'ImageStore is deprecated and will be removed in a future release. ' +
|
||||
'To get a base64-encoded string from a local image use either of the following third-party libraries:' +
|
||||
"* expo-file-system: `readAsStringAsync(filepath, 'base64')`" +
|
||||
"* react-native-fs: `readFile(filepath, 'base64')`",
|
||||
);
|
||||
return require('ImageStore');
|
||||
},
|
||||
get InputAccessoryView() {
|
||||
|
|
Loading…
Reference in New Issue