Skip to content
Permalink
Browse files

RN: Add NativeImageSource Flow Type

Reviewed By: TheSavior

Differential Revision: D6869985

fbshipit-source-id: 836134ae0919d49b161d1a75d5743e977e6eb3f4
  • Loading branch information...
yungsters authored and facebook-github-bot committed Feb 2, 2018
1 parent 6c4ef28 commit d99ba70c492d3cd15ef6aded3f8712976d251f88
Showing with 33 additions and 20 deletions.
  1. +33 −20 Libraries/Image/nativeImageSource.js
@@ -10,47 +10,60 @@
* @flow
* @format
*/

'use strict';

const Platform = require('Platform');

type SourceSpec = {
ios?: string,
android?: string,
// TODO: Change `nativeImageSource` to return this type.
export type NativeImageSource = {|
+deprecated: true,
+height: number,
+uri: string,
+width: number,
|};

type NativeImageSourceSpec = {|
+android?: string,
+ios?: string,

// For more details on width and height, see
// http://facebook.github.io/react-native/docs/images.html#why-not-automatically-size-everything
width: number,
height: number,
};
+height: number,
+width: number,
|};

/**
* In hybrid apps, use `nativeImageSource` to access images that are already available
* on the native side, for example in Xcode Asset Catalogs or Android's drawable folder.
* In hybrid apps, use `nativeImageSource` to access images that are already
* available on the native side, for example in Xcode Asset Catalogs or
* Android's drawable folder.
*
* However, keep in mind that React Native Packager does not guarantee that the image exists. If
* the image is missing you'll get an empty box. When adding new images your app needs to be
* recompiled.
* However, keep in mind that React Native Packager does not guarantee that the
* image exists. If the image is missing you'll get an empty box. When adding
* new images your app needs to be recompiled.
*
* Prefer Static Image Resources system which provides more guarantees, automates measurements and
* allows adding new images without rebuilding the native app. For more details visit:
* Prefer Static Image Resources system which provides more guarantees,
* automates measurements and allows adding new images without rebuilding the
* native app. For more details visit:
*
* http://facebook.github.io/react-native/docs/images.html
*
*/
function nativeImageSource(spec: SourceSpec): Object {
const uri = Platform.select(spec);
if (!uri) {
function nativeImageSource(spec: NativeImageSourceSpec): Object {
let uri = Platform.select(spec);
if (uri == null) {
console.warn(
`No image name given for ${Platform.OS}: ${JSON.stringify(spec)}`,
'nativeImageSource(...): No image name supplied for `%s`:\n%s',
Platform.OS,
JSON.stringify(spec, null, 2),
);
uri = '';
}

return {
deprecated: true,
height: spec.height,
uri,
width: spec.width,
height: spec.height,
deprecated: true,
};
}

0 comments on commit d99ba70

Please sign in to comment.
You can’t perform that action at this time.