-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split JS spec for image loader module
Summary: It turns out the ImageLoader native module has different method signatures on iOS than on Android, so the JS spec we currently have won't work for ANdroid. In this diff I'm splitting up the spec for NativeImageLoader into an Android & iOS versions (similar to PlatformConstants), and updating the Android spec to match the native implementation. I'm also changing `RCTImageLoader` to use the new generated spec, and updating the JS callers (`Image.android.js` and `Image.ios.js`) to use the right one for the platform (instead of importing the untyped `ImageLoader` native module from `react-native`, like we were on Android :-/). This will be a breaking change for anyone who's directly using `NativeImageLoader.js`, but I think most callsites should be using the `Image` component instead. Changelog: [General] [Changed] Split NativeImageLoader into NativeImageLoaderAndroid and NativeImageLoaderIOS Reviewed By: RSNara Differential Revision: D18439538 fbshipit-source-id: 94c796d3fd27800ea17053e963bee51aca921718
- Loading branch information
1 parent
390546f
commit d37baa7
Showing
9 changed files
with
220 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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 { | ||
+abortRequest: (requestId: number) => void; | ||
+getConstants: () => {||}; | ||
+getSize: ( | ||
uri: string, | ||
) => Promise<$ReadOnly<{width: number, height: number}>>; | ||
+getSizeWithHeaders: ( | ||
uri: string, | ||
headers: Object, | ||
) => Promise<{width: number, height: number}>; | ||
+prefetchImage: (uri: string, requestId: number) => Promise<boolean>; | ||
+queryCache: (uris: Array<string>) => Promise<Object>; | ||
} | ||
|
||
export default (TurboModuleRegistry.getEnforcing<Spec>('ImageLoader'): Spec); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeImageLoaderAndroidSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root | ||
* directory of this source tree. | ||
* | ||
* <p>Generated by an internal genrule from Flow types. | ||
* | ||
* @generated | ||
* @nolint | ||
*/ | ||
|
||
package com.facebook.fbreact.specs; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReactModuleWithSpec; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.turbomodule.core.interfaces.TurboModule; | ||
|
||
public abstract class NativeImageLoaderAndroidSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { | ||
public NativeImageLoaderAndroidSpec(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@ReactMethod | ||
public abstract void getSize(String uri, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void abortRequest(double requestId); | ||
|
||
@ReactMethod | ||
public abstract void prefetchImage(String uri, double requestId, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void queryCache(ReadableArray uris, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void getSizeWithHeaders(String uri, ReadableMap headers, Promise promise); | ||
} |
40 changes: 40 additions & 0 deletions
40
ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeImageLoaderIOSSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root | ||
* directory of this source tree. | ||
* | ||
* <p>Generated by an internal genrule from Flow types. | ||
* | ||
* @generated | ||
* @nolint | ||
*/ | ||
|
||
package com.facebook.fbreact.specs; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReactModuleWithSpec; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.turbomodule.core.interfaces.TurboModule; | ||
|
||
public abstract class NativeImageLoaderIOSSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { | ||
public NativeImageLoaderIOSSpec(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@ReactMethod | ||
public abstract void getSize(String uri, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void prefetchImage(String uri, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void queryCache(ReadableArray uris, Promise promise); | ||
|
||
@ReactMethod | ||
public abstract void getSizeWithHeaders(String uri, ReadableMap headers, Promise promise); | ||
} |