1
- import React , { Component } from 'react'
1
+ import React , { forwardRef } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import {
4
4
View ,
@@ -11,15 +11,9 @@ import {
11
11
12
12
const FastImageViewNativeModule = NativeModules . FastImageView
13
13
14
- class FastImage extends Component {
15
- setNativeProps ( nativeProps ) {
16
- this . _root . setNativeProps ( nativeProps )
17
- }
18
-
19
- captureRef = e => ( this . _root = e )
20
-
21
- render ( ) {
22
- const {
14
+ const FastImage = forwardRef (
15
+ (
16
+ {
23
17
source,
24
18
onLoadStart,
25
19
onProgress,
@@ -30,16 +24,14 @@ class FastImage extends Component {
30
24
children,
31
25
fallback,
32
26
...props
33
- } = this . props
34
-
27
+ } ,
28
+ ref ,
29
+ ) => {
35
30
const resolvedSource = Image . resolveAssetSource ( source )
36
31
37
32
if ( fallback ) {
38
33
return (
39
- < View
40
- style = { [ styles . imageContainer , style ] }
41
- ref = { this . captureRef }
42
- >
34
+ < View style = { [ styles . imageContainer , style ] } ref = { ref } >
43
35
< Image
44
36
{ ...props }
45
37
style = { StyleSheet . absoluteFill }
@@ -56,7 +48,7 @@ class FastImage extends Component {
56
48
}
57
49
58
50
return (
59
- < View style = { [ styles . imageContainer , style ] } ref = { this . captureRef } >
51
+ < View style = { [ styles . imageContainer , style ] } ref = { ref } >
60
52
< FastImageView
61
53
{ ...props }
62
54
style = { StyleSheet . absoluteFill }
@@ -70,8 +62,10 @@ class FastImage extends Component {
70
62
{ children }
71
63
</ View >
72
64
)
73
- }
74
- }
65
+ } ,
66
+ )
67
+
68
+ FastImage . displayName = 'FastImage'
75
69
76
70
const styles = StyleSheet . create ( {
77
71
imageContainer : {
0 commit comments