|
10 | 10 | * @flow
|
11 | 11 | * @format
|
12 | 12 | */
|
| 13 | + |
13 | 14 | 'use strict';
|
14 | 15 |
|
15 | 16 | const Platform = require('Platform');
|
16 | 17 |
|
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, |
20 | 29 |
|
21 | 30 | // For more details on width and height, see
|
22 | 31 | // 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 | +|}; |
26 | 35 |
|
27 | 36 | /**
|
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. |
30 | 40 | *
|
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. |
34 | 44 | *
|
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: |
37 | 48 | *
|
38 | 49 | * http://facebook.github.io/react-native/docs/images.html
|
39 | 50 | *
|
40 | 51 | */
|
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) { |
44 | 55 | 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), |
46 | 59 | );
|
| 60 | + uri = ''; |
47 | 61 | }
|
48 |
| - |
49 | 62 | return {
|
| 63 | + deprecated: true, |
| 64 | + height: spec.height, |
50 | 65 | uri,
|
51 | 66 | width: spec.width,
|
52 |
| - height: spec.height, |
53 |
| - deprecated: true, |
54 | 67 | };
|
55 | 68 | }
|
56 | 69 |
|
|
0 commit comments