Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lean Core] Add deprecation notice to ImageStore #23330

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions Libraries/Image/ImageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,7 +33,7 @@ class ImageStore {
if (RCTImageStoreManager.hasImageForTag) {
RCTImageStoreManager.hasImageForTag(uri, callback);
} else {
console.warn('hasImageForTag() not implemented');
warnUnimplementedMethod('hasImageForTag');
}
}

Expand All @@ -36,7 +49,7 @@ class ImageStore {
if (RCTImageStoreManager.removeImageForTag) {
RCTImageStoreManager.removeImageForTag(uri);
} else {
console.warn('removeImageForTag() not implemented');
warnUnimplementedMethod('removeImageForTag');
}
}

Expand All @@ -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');
}
}

/**
Expand All @@ -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');
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions Libraries/react-native/react-native-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down