Skip to content

Commit 62599fa

Browse files
EvanBaconfacebook-github-bot
authored andcommitted
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: #23330 Differential Revision: D14022159 Pulled By: cpojer fbshipit-source-id: 2a026ebf47cb315e9a0cfe6e3697a1799c5cbe2c
1 parent d2fc19f commit 62599fa

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

Libraries/Image/ImageStore.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
const RCTImageStoreManager = require('NativeModules').ImageStoreManager;
1313

14+
const Platform = require('Platform');
15+
16+
const warnOnce = require('warnOnce');
17+
18+
function warnUnimplementedMethod(methodName: string): void {
19+
warnOnce(
20+
`imagestore-${methodName}`,
21+
`react-native: ImageStore.${methodName}() is not implemented on ${
22+
Platform.OS
23+
}`,
24+
);
25+
}
26+
1427
class ImageStore {
1528
/**
1629
* Check if the ImageStore contains image data for the specified URI.
@@ -20,7 +33,7 @@ class ImageStore {
2033
if (RCTImageStoreManager.hasImageForTag) {
2134
RCTImageStoreManager.hasImageForTag(uri, callback);
2235
} else {
23-
console.warn('hasImageForTag() not implemented');
36+
warnUnimplementedMethod('hasImageForTag');
2437
}
2538
}
2639

@@ -36,7 +49,7 @@ class ImageStore {
3649
if (RCTImageStoreManager.removeImageForTag) {
3750
RCTImageStoreManager.removeImageForTag(uri);
3851
} else {
39-
console.warn('removeImageForTag() not implemented');
52+
warnUnimplementedMethod('removeImageForTag');
4053
}
4154
}
4255

@@ -56,7 +69,15 @@ class ImageStore {
5669
success: (uri: string) => void,
5770
failure: (error: any) => void,
5871
) {
59-
RCTImageStoreManager.addImageFromBase64(base64ImageData, success, failure);
72+
if (RCTImageStoreManager.addImageFromBase64) {
73+
RCTImageStoreManager.addImageFromBase64(
74+
base64ImageData,
75+
success,
76+
failure,
77+
);
78+
} else {
79+
warnUnimplementedMethod('addImageFromBase64');
80+
}
6081
}
6182

6283
/**
@@ -75,7 +96,11 @@ class ImageStore {
7596
success: (base64ImageData: string) => void,
7697
failure: (error: any) => void,
7798
) {
78-
RCTImageStoreManager.getBase64ForTag(uri, success, failure);
99+
if (RCTImageStoreManager.getBase64ForTag) {
100+
RCTImageStoreManager.getBase64ForTag(uri, success, failure);
101+
} else {
102+
warnUnimplementedMethod('getBase64ForTag');
103+
}
79104
}
80105
}
81106

Libraries/react-native/react-native-implementation.js

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ module.exports = {
5050
return require('ImageEditor');
5151
},
5252
get ImageStore() {
53+
warnOnce(
54+
'imagestore-deprecation',
55+
'ImageStore is deprecated and will be removed in a future release. ' +
56+
'To get a base64-encoded string from a local image use either of the following third-party libraries:' +
57+
"* expo-file-system: `readAsStringAsync(filepath, 'base64')`" +
58+
"* react-native-fs: `readFile(filepath, 'base64')`",
59+
);
5360
return require('ImageStore');
5461
},
5562
get InputAccessoryView() {

0 commit comments

Comments
 (0)