|
8 | 8 | * @format |
9 | 9 | */ |
10 | 10 |
|
11 | | -import type {HostInstance} from '../../src/private/types/HostInstance'; |
12 | 11 | import type {ImageBackgroundProps} from './ImageProps'; |
13 | 12 |
|
14 | 13 | import View from '../Components/View/View'; |
@@ -43,68 +42,58 @@ export type {ImageBackgroundProps} from './ImageProps'; |
43 | 42 | * AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground); |
44 | 43 | * ``` |
45 | 44 | */ |
46 | | -class ImageBackground extends React.Component<ImageBackgroundProps> { |
47 | | - setNativeProps(props: {...}) { |
48 | | - // Work-around flow |
49 | | - const viewRef = this._viewRef; |
50 | | - if (viewRef) { |
51 | | - viewRef.setNativeProps(props); |
52 | | - } |
53 | | - } |
54 | 45 |
|
55 | | - _viewRef: ?React.ElementRef<typeof View> = null; |
56 | | - |
57 | | - _captureRef = (ref: null | HostInstance) => { |
58 | | - this._viewRef = ref; |
59 | | - }; |
60 | | - |
61 | | - render(): React.Node { |
62 | | - const { |
63 | | - children, |
64 | | - style, |
65 | | - imageStyle, |
66 | | - imageRef, |
67 | | - importantForAccessibility, |
68 | | - ...props |
69 | | - } = this.props; |
70 | | - |
71 | | - // $FlowFixMe[underconstrained-implicit-instantiation] |
72 | | - const flattenedStyle = flattenStyle(style); |
73 | | - return ( |
74 | | - <View |
75 | | - accessibilityIgnoresInvertColors={true} |
| 46 | +const ImageBackground: component( |
| 47 | + ref?: React.RefSetter<React.ElementRef<typeof View>>, |
| 48 | + ...props: ImageBackgroundProps |
| 49 | +) = ({ |
| 50 | + ref, |
| 51 | + children, |
| 52 | + style, |
| 53 | + imageStyle, |
| 54 | + imageRef, |
| 55 | + importantForAccessibility, |
| 56 | + ...props |
| 57 | +}: { |
| 58 | + ref?: React.RefSetter<React.ElementRef<typeof View>>, |
| 59 | + ...ImageBackgroundProps, |
| 60 | +}): React.Node => { |
| 61 | + // $FlowFixMe[underconstrained-implicit-instantiation] |
| 62 | + const flattenedStyle = flattenStyle(style); |
| 63 | + return ( |
| 64 | + <View |
| 65 | + accessibilityIgnoresInvertColors={true} |
| 66 | + importantForAccessibility={importantForAccessibility} |
| 67 | + style={style} |
| 68 | + ref={ref}> |
| 69 | + {/* $FlowFixMe[incompatible-use] */} |
| 70 | + <Image |
| 71 | + {...props} |
76 | 72 | importantForAccessibility={importantForAccessibility} |
77 | | - style={style} |
78 | | - ref={this._captureRef}> |
79 | | - {/* $FlowFixMe[incompatible-use] */} |
80 | | - <Image |
81 | | - {...props} |
82 | | - importantForAccessibility={importantForAccessibility} |
83 | | - style={[ |
84 | | - StyleSheet.absoluteFill, |
85 | | - { |
86 | | - // Temporary Workaround: |
87 | | - // Current (imperfect yet) implementation of <Image> overwrites width and height styles |
88 | | - // (which is not quite correct), and these styles conflict with explicitly set styles |
89 | | - // of <ImageBackground> and with our internal layout model here. |
90 | | - // So, we have to proxy/reapply these styles explicitly for actual <Image> component. |
91 | | - // This workaround should be removed after implementing proper support of |
92 | | - // intrinsic content size of the <Image>. |
93 | | - // $FlowFixMe[prop-missing] |
94 | | - width: flattenedStyle?.width, |
95 | | - // $FlowFixMe[prop-missing] |
96 | | - height: flattenedStyle?.height, |
97 | | - }, |
98 | | - imageStyle, |
99 | | - ]} |
100 | | - ref={imageRef} |
101 | | - /> |
102 | | - {children} |
103 | | - </View> |
104 | | - ); |
105 | | - } |
106 | | -} |
| 73 | + style={[ |
| 74 | + StyleSheet.absoluteFill, |
| 75 | + { |
| 76 | + // Temporary Workaround: |
| 77 | + // Current (imperfect yet) implementation of <Image> overwrites width and height styles |
| 78 | + // (which is not quite correct), and these styles conflict with explicitly set styles |
| 79 | + // of <ImageBackground> and with our internal layout model here. |
| 80 | + // So, we have to proxy/reapply these styles explicitly for actual <Image> component. |
| 81 | + // This workaround should be removed after implementing proper support of |
| 82 | + // intrinsic content size of the <Image>. |
| 83 | + // $FlowFixMe[prop-missing] |
| 84 | + width: flattenedStyle?.width, |
| 85 | + // $FlowFixMe[prop-missing] |
| 86 | + height: flattenedStyle?.height, |
| 87 | + }, |
| 88 | + imageStyle, |
| 89 | + ]} |
| 90 | + ref={imageRef} |
| 91 | + /> |
| 92 | + {children} |
| 93 | + </View> |
| 94 | + ); |
| 95 | +}; |
107 | 96 |
|
108 | | -export type ImageBackgroundInstance = ImageBackground; |
| 97 | +ImageBackground.displayName = 'ImageBackground'; |
109 | 98 |
|
110 | 99 | export default ImageBackground; |
0 commit comments