1
- import React , { forwardRef } from 'react'
1
+ import React , { forwardRef , memo } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import {
4
4
View ,
@@ -11,59 +11,61 @@ import {
11
11
12
12
const FastImageViewNativeModule = NativeModules . FastImageView
13
13
14
- const FastImage = forwardRef (
15
- (
16
- {
17
- source,
18
- onLoadStart,
19
- onProgress,
20
- onLoad,
21
- onError,
22
- onLoadEnd,
23
- style,
24
- children,
25
- fallback,
26
- ...props
27
- } ,
28
- ref ,
29
- ) => {
30
- const resolvedSource = Image . resolveAssetSource ( source )
31
-
32
- if ( fallback ) {
33
- return (
34
- < View style = { [ styles . imageContainer , style ] } ref = { ref } >
35
- < Image
36
- { ...props }
37
- style = { StyleSheet . absoluteFill }
38
- source = { resolvedSource }
39
- onLoadStart = { onLoadStart }
40
- onProgress = { onProgress }
41
- onLoad = { onLoad }
42
- onError = { onError }
43
- onLoadEnd = { onLoadEnd }
44
- />
45
- { children }
46
- </ View >
47
- )
48
- }
14
+ function FastImageBase ( {
15
+ source,
16
+ onLoadStart,
17
+ onProgress,
18
+ onLoad,
19
+ onError,
20
+ onLoadEnd,
21
+ style,
22
+ children,
23
+ fallback,
24
+ forwardedRef,
25
+ ...props
26
+ } ) {
27
+ const resolvedSource = Image . resolveAssetSource ( source )
49
28
29
+ if ( fallback ) {
50
30
return (
51
- < View style = { [ styles . imageContainer , style ] } ref = { ref } >
52
- < FastImageView
31
+ < View style = { [ styles . imageContainer , style ] } ref = { forwardedRef } >
32
+ < Image
53
33
{ ...props }
54
34
style = { StyleSheet . absoluteFill }
55
35
source = { resolvedSource }
56
- onFastImageLoadStart = { onLoadStart }
57
- onFastImageProgress = { onProgress }
58
- onFastImageLoad = { onLoad }
59
- onFastImageError = { onError }
60
- onFastImageLoadEnd = { onLoadEnd }
36
+ onLoadStart = { onLoadStart }
37
+ onProgress = { onProgress }
38
+ onLoad = { onLoad }
39
+ onError = { onError }
40
+ onLoadEnd = { onLoadEnd }
61
41
/>
62
42
{ children }
63
43
</ View >
64
44
)
65
- } ,
66
- )
45
+ }
46
+
47
+ return (
48
+ < View style = { [ styles . imageContainer , style ] } ref = { forwardedRef } >
49
+ < FastImageView
50
+ { ...props }
51
+ style = { StyleSheet . absoluteFill }
52
+ source = { resolvedSource }
53
+ onFastImageLoadStart = { onLoadStart }
54
+ onFastImageProgress = { onProgress }
55
+ onFastImageLoad = { onLoad }
56
+ onFastImageError = { onError }
57
+ onFastImageLoadEnd = { onLoadEnd }
58
+ />
59
+ { children }
60
+ </ View >
61
+ )
62
+ }
63
+
64
+ const FastImageMemo = memo ( FastImageBase )
65
+
66
+ const FastImage = forwardRef ( ( props , ref ) => (
67
+ < FastImageMemo forwardedRef = { ref } { ...props } />
68
+ ) )
67
69
68
70
FastImage . displayName = 'FastImage'
69
71
0 commit comments