2016-11-20 20:19:20 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-11-20 20:19:20 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2018-01-15 03:32:26 +00:00
|
|
|
* @format
|
2016-11-20 20:19:20 +00:00
|
|
|
*/
|
2018-02-02 07:38:33 +00:00
|
|
|
|
2016-11-20 20:19:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Platform = require('Platform');
|
|
|
|
|
2018-02-02 07:38:33 +00:00
|
|
|
// TODO: Change `nativeImageSource` to return this type.
|
|
|
|
export type NativeImageSource = {|
|
|
|
|
+deprecated: true,
|
|
|
|
+height: number,
|
|
|
|
+uri: string,
|
|
|
|
+width: number,
|
|
|
|
|};
|
|
|
|
|
|
|
|
type NativeImageSourceSpec = {|
|
|
|
|
+android?: string,
|
|
|
|
+ios?: string,
|
2016-11-20 20:19:20 +00:00
|
|
|
|
|
|
|
// For more details on width and height, see
|
|
|
|
// http://facebook.github.io/react-native/docs/images.html#why-not-automatically-size-everything
|
2018-02-02 07:38:33 +00:00
|
|
|
+height: number,
|
|
|
|
+width: number,
|
|
|
|
|};
|
2016-11-20 20:19:20 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-02 07:38:33 +00:00
|
|
|
* 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.
|
2016-11-20 20:19:20 +00:00
|
|
|
*
|
2018-02-02 07:38:33 +00:00
|
|
|
* 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.
|
2016-11-20 20:19:20 +00:00
|
|
|
*
|
2018-02-02 07:38:33 +00:00
|
|
|
* 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:
|
2016-11-20 20:19:20 +00:00
|
|
|
*
|
|
|
|
* http://facebook.github.io/react-native/docs/images.html
|
|
|
|
*
|
|
|
|
*/
|
2018-02-02 07:38:33 +00:00
|
|
|
function nativeImageSource(spec: NativeImageSourceSpec): Object {
|
|
|
|
let uri = Platform.select(spec);
|
|
|
|
if (uri == null) {
|
2018-01-15 03:32:26 +00:00
|
|
|
console.warn(
|
2018-02-02 07:38:33 +00:00
|
|
|
'nativeImageSource(...): No image name supplied for `%s`:\n%s',
|
|
|
|
Platform.OS,
|
|
|
|
JSON.stringify(spec, null, 2),
|
2018-01-15 03:32:26 +00:00
|
|
|
);
|
2018-02-02 07:38:33 +00:00
|
|
|
uri = '';
|
2016-11-20 20:19:20 +00:00
|
|
|
}
|
|
|
|
return {
|
2018-02-02 07:38:33 +00:00
|
|
|
deprecated: true,
|
|
|
|
height: spec.height,
|
2016-11-20 20:19:20 +00:00
|
|
|
uri,
|
|
|
|
width: spec.width,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = nativeImageSource;
|