8
8
*
9
9
* @providesModule Image
10
10
* @flow
11
+ * @format
11
12
*/
12
13
'use strict' ;
13
14
@@ -32,9 +33,7 @@ var merge = require('merge');
32
33
var requireNativeComponent = require ( 'requireNativeComponent' ) ;
33
34
var resolveAssetSource = require ( 'resolveAssetSource' ) ;
34
35
35
- var {
36
- ImageLoader,
37
- } = NativeModules ;
36
+ var { ImageLoader} = NativeModules ;
38
37
39
38
let _requestId = 1 ;
40
39
function generateRequestId ( ) {
@@ -75,14 +74,16 @@ var ImageViewAttributes = merge(ReactNativeViewAttributes.UIView, {
75
74
} ) ;
76
75
77
76
var ViewStyleKeys = new Set ( Object . keys ( ViewStylePropTypes ) ) ;
78
- var ImageSpecificStyleKeys = new Set ( Object . keys ( ImageStylePropTypes ) . filter ( x => ! ViewStyleKeys . has ( x ) ) ) ;
77
+ var ImageSpecificStyleKeys = new Set (
78
+ Object . keys ( ImageStylePropTypes ) . filter ( x => ! ViewStyleKeys . has ( x ) ) ,
79
+ ) ;
79
80
80
81
var Image = createReactClass ( {
81
82
displayName : 'Image' ,
82
83
propTypes : {
83
84
...ViewPropTypes ,
84
85
style : StyleSheetPropType ( ImageStylePropTypes ) ,
85
- /**
86
+ /**
86
87
* `uri` is a string representing the resource identifier for the image, which
87
88
* could be an http address, a local file path, or a static image
88
89
* resource (which should be wrapped in the `require('./path/to/image.png')` function).
@@ -108,11 +109,12 @@ var Image = createReactClass({
108
109
width : PropTypes . number ,
109
110
height : PropTypes . number ,
110
111
headers : PropTypes . objectOf ( PropTypes . string ) ,
111
- } ) )
112
+ } ) ,
113
+ ) ,
112
114
] ) ,
113
115
/**
114
- * blurRadius: the blur radius of the blur filter added to the image
115
- */
116
+ * blurRadius: the blur radius of the blur filter added to the image
117
+ */
116
118
blurRadius : PropTypes . number ,
117
119
/**
118
120
* similarly to `source`, this property represents the resource used to render
@@ -202,9 +204,12 @@ var Image = createReactClass({
202
204
. then ( function ( sizes ) {
203
205
success ( sizes . width , sizes . height ) ;
204
206
} )
205
- . catch ( failure || function ( ) {
206
- console . warn ( 'Failed to get size for image: ' + url ) ;
207
- } ) ;
207
+ . catch (
208
+ failure ||
209
+ function ( ) {
210
+ console . warn ( 'Failed to get size for image: ' + url ) ;
211
+ } ,
212
+ ) ;
208
213
} ,
209
214
210
215
/**
@@ -231,7 +236,9 @@ var Image = createReactClass({
231
236
* @return a mapping from url to cache status, such as "disk" or "memory". If a requested URL is
232
237
* not in the mapping, it means it's not in the cache.
233
238
*/
234
- async queryCache ( urls : Array < string > ) : Promise < Map < string , 'memory' | 'disk' >> {
239
+ async queryCache (
240
+ urls : Array < string > ,
241
+ ) : Promise < Map < string , 'memory' | 'disk' > > {
235
242
return await ImageLoader . queryCache ( urls ) ;
236
243
} ,
237
244
@@ -255,12 +262,14 @@ var Image = createReactClass({
255
262
} ,
256
263
257
264
contextTypes : {
258
- isInAParentText : PropTypes . bool
265
+ isInAParentText : PropTypes . bool ,
259
266
} ,
260
267
261
268
render : function ( ) {
262
269
const source = resolveAssetSource ( this . props . source ) ;
263
- const loadingIndicatorSource = resolveAssetSource ( this . props . loadingIndicatorSource ) ;
270
+ const loadingIndicatorSource = resolveAssetSource (
271
+ this . props . loadingIndicatorSource ,
272
+ ) ;
264
273
265
274
// As opposed to the ios version, here we render `null` when there is no source, source.uri
266
275
// or source array.
@@ -270,11 +279,15 @@ var Image = createReactClass({
270
279
}
271
280
272
281
if ( this . props . src ) {
273
- console . warn ( 'The <Image> component requires a `source` property rather than `src`.' ) ;
282
+ console . warn (
283
+ 'The <Image> component requires a `source` property rather than `src`.' ,
284
+ ) ;
274
285
}
275
286
276
287
if ( this . props . children ) {
277
- throw new Error ( 'The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.' ) ;
288
+ throw new Error (
289
+ 'The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.' ,
290
+ ) ;
278
291
}
279
292
280
293
if ( source && ( source . uri || Array . isArray ( source ) ) ) {
@@ -292,20 +305,27 @@ var Image = createReactClass({
292
305
const { onLoadStart, onLoad, onLoadEnd, onError} = this . props ;
293
306
const nativeProps = merge ( this . props , {
294
307
style,
295
- shouldNotifyLoadEvents : ! ! ( onLoadStart || onLoad || onLoadEnd || onError ) ,
308
+ shouldNotifyLoadEvents : ! ! (
309
+ onLoadStart ||
310
+ onLoad ||
311
+ onLoadEnd ||
312
+ onError
313
+ ) ,
296
314
src : sources ,
297
315
headers : source . headers ,
298
- loadingIndicatorSrc : loadingIndicatorSource ? loadingIndicatorSource . uri : null ,
316
+ loadingIndicatorSrc : loadingIndicatorSource
317
+ ? loadingIndicatorSource . uri
318
+ : null ,
299
319
} ) ;
300
320
301
321
if ( this . context . isInAParentText ) {
302
- return < RCTTextInlineImage { ...nativeProps } /> ;
322
+ return < RCTTextInlineImage { ...nativeProps } /> ;
303
323
} else {
304
- return < RKImage { ...nativeProps } /> ;
324
+ return < RKImage { ...nativeProps } /> ;
305
325
}
306
326
}
307
327
return null ;
308
- }
328
+ } ,
309
329
} ) ;
310
330
311
331
var styles = StyleSheet . create ( {
@@ -323,6 +343,10 @@ var cfg = {
323
343
} ,
324
344
} ;
325
345
var RKImage = requireNativeComponent ( 'RCTImageView' , Image , cfg ) ;
326
- var RCTTextInlineImage = requireNativeComponent ( 'RCTTextInlineImage' , Image , cfg ) ;
346
+ var RCTTextInlineImage = requireNativeComponent (
347
+ 'RCTTextInlineImage' ,
348
+ Image ,
349
+ cfg ,
350
+ ) ;
327
351
328
352
module . exports = Image ;
0 commit comments