Skip to content

Commit d99ba70

Browse files
yungstersfacebook-github-bot
authored andcommittedFeb 2, 2018
RN: Add NativeImageSource Flow Type
Reviewed By: TheSavior Differential Revision: D6869985 fbshipit-source-id: 836134ae0919d49b161d1a75d5743e977e6eb3f4
1 parent 6c4ef28 commit d99ba70

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed
 

‎Libraries/Image/nativeImageSource.js

+33-20
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,60 @@
1010
* @flow
1111
* @format
1212
*/
13+
1314
'use strict';
1415

1516
const Platform = require('Platform');
1617

17-
type SourceSpec = {
18-
ios?: string,
19-
android?: string,
18+
// TODO: Change `nativeImageSource` to return this type.
19+
export type NativeImageSource = {|
20+
+deprecated: true,
21+
+height: number,
22+
+uri: string,
23+
+width: number,
24+
|};
25+
26+
type NativeImageSourceSpec = {|
27+
+android?: string,
28+
+ios?: string,
2029

2130
// For more details on width and height, see
2231
// http://facebook.github.io/react-native/docs/images.html#why-not-automatically-size-everything
23-
width: number,
24-
height: number,
25-
};
32+
+height: number,
33+
+width: number,
34+
|};
2635

2736
/**
28-
* In hybrid apps, use `nativeImageSource` to access images that are already available
29-
* on the native side, for example in Xcode Asset Catalogs or Android's drawable folder.
37+
* In hybrid apps, use `nativeImageSource` to access images that are already
38+
* available on the native side, for example in Xcode Asset Catalogs or
39+
* Android's drawable folder.
3040
*
31-
* However, keep in mind that React Native Packager does not guarantee that the image exists. If
32-
* the image is missing you'll get an empty box. When adding new images your app needs to be
33-
* recompiled.
41+
* However, keep in mind that React Native Packager does not guarantee that the
42+
* image exists. If the image is missing you'll get an empty box. When adding
43+
* new images your app needs to be recompiled.
3444
*
35-
* Prefer Static Image Resources system which provides more guarantees, automates measurements and
36-
* allows adding new images without rebuilding the native app. For more details visit:
45+
* Prefer Static Image Resources system which provides more guarantees,
46+
* automates measurements and allows adding new images without rebuilding the
47+
* native app. For more details visit:
3748
*
3849
* http://facebook.github.io/react-native/docs/images.html
3950
*
4051
*/
41-
function nativeImageSource(spec: SourceSpec): Object {
42-
const uri = Platform.select(spec);
43-
if (!uri) {
52+
function nativeImageSource(spec: NativeImageSourceSpec): Object {
53+
let uri = Platform.select(spec);
54+
if (uri == null) {
4455
console.warn(
45-
`No image name given for ${Platform.OS}: ${JSON.stringify(spec)}`,
56+
'nativeImageSource(...): No image name supplied for `%s`:\n%s',
57+
Platform.OS,
58+
JSON.stringify(spec, null, 2),
4659
);
60+
uri = '';
4761
}
48-
4962
return {
63+
deprecated: true,
64+
height: spec.height,
5065
uri,
5166
width: spec.width,
52-
height: spec.height,
53-
deprecated: true,
5467
};
5568
}
5669

0 commit comments

Comments
 (0)
Please sign in to comment.