Skip to content

Commit

Permalink
add spec for ImageStore (facebook#25101)
Browse files Browse the repository at this point in the history
Summary:
This PR solves part of this issue: facebook#24875

## Changelog

[General] [Added] - add TM spec for ImageStore
Pull Request resolved: facebook#25101

Reviewed By: hramos

Differential Revision: D15583463

Pulled By: fkgozali

fbshipit-source-id: 17e87e8fecb35d42a981b1fb348e40d2b1e91cc6
  • Loading branch information
mitulsavani authored and M-i-k-e-l committed Mar 10, 2020
1 parent 87ccf58 commit 65546ae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Libraries/Image/ImageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
*/
'use strict';

const RCTImageStoreManager = require('../BatchedBridge/NativeModules')
.ImageStoreManager;
import NativeImageStore from './NativeImageStore';

const Platform = require('../Utilities/Platform');

Expand All @@ -31,8 +30,8 @@ class ImageStore {
* @platform ios
*/
static hasImageForTag(uri: string, callback: (hasImage: boolean) => void) {
if (RCTImageStoreManager.hasImageForTag) {
RCTImageStoreManager.hasImageForTag(uri, callback);
if (NativeImageStore.hasImageForTag) {
NativeImageStore.hasImageForTag(uri, callback);
} else {
warnUnimplementedMethod('hasImageForTag');
}
Expand All @@ -47,8 +46,8 @@ class ImageStore {
* @platform ios
*/
static removeImageForTag(uri: string) {
if (RCTImageStoreManager.removeImageForTag) {
RCTImageStoreManager.removeImageForTag(uri);
if (NativeImageStore.removeImageForTag) {
NativeImageStore.removeImageForTag(uri);
} else {
warnUnimplementedMethod('removeImageForTag');
}
Expand All @@ -70,12 +69,8 @@ class ImageStore {
success: (uri: string) => void,
failure: (error: any) => void,
) {
if (RCTImageStoreManager.addImageFromBase64) {
RCTImageStoreManager.addImageFromBase64(
base64ImageData,
success,
failure,
);
if (NativeImageStore.addImageFromBase64) {
NativeImageStore.addImageFromBase64(base64ImageData, success, failure);
} else {
warnUnimplementedMethod('addImageFromBase64');
}
Expand All @@ -97,8 +92,8 @@ class ImageStore {
success: (base64ImageData: string) => void,
failure: (error: any) => void,
) {
if (RCTImageStoreManager.getBase64ForTag) {
RCTImageStoreManager.getBase64ForTag(uri, success, failure);
if (NativeImageStore.getBase64ForTag) {
NativeImageStore.getBase64ForTag(uri, success, failure);
} else {
warnUnimplementedMethod('getBase64ForTag');
}
Expand Down
34 changes: 34 additions & 0 deletions Libraries/Image/NativeImageStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';

export interface Spec extends TurboModule {
// Common
+getBase64ForTag: (
uri: string,
success: (base64ImageData: string) => void,
failure: (error: Object) => void,
) => void;

// iOS-only
+hasImageForTag: (uri: string, callback: (hasImage: boolean) => void) => void;
+removeImageForTag: (uri: string) => void;
+addImageFromBase64: (
base64ImageData: string,
success: (uri: string) => void,
failure: (error: Object) => void,
) => void;
}

export default TurboModuleRegistry.getEnforcing<Spec>('ImageStoringManager');

0 comments on commit 65546ae

Please sign in to comment.