|
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'; |
@@ -53,68 +52,58 @@ export type {ImageBackgroundProps} from './ImageProps'; |
53 | 52 | * @see https://reactnative.dev/docs/imagebackground |
54 | 53 | * @deprecated |
55 | 54 | */ |
56 | | -class ImageBackground extends React.Component<ImageBackgroundProps> { |
57 | | - setNativeProps(props: {...}) { |
58 | | - // Work-around flow |
59 | | - const viewRef = this._viewRef; |
60 | | - if (viewRef) { |
61 | | - viewRef.setNativeProps(props); |
62 | | - } |
63 | | - } |
64 | 55 |
|
65 | | - _viewRef: ?React.ElementRef<typeof View> = null; |
66 | | - |
67 | | - _captureRef = (ref: null | HostInstance) => { |
68 | | - this._viewRef = ref; |
69 | | - }; |
70 | | - |
71 | | - render(): React.Node { |
72 | | - const { |
73 | | - children, |
74 | | - style, |
75 | | - imageStyle, |
76 | | - imageRef, |
77 | | - importantForAccessibility, |
78 | | - ...props |
79 | | - } = this.props; |
80 | | - |
81 | | - // $FlowFixMe[underconstrained-implicit-instantiation] |
82 | | - const flattenedStyle = flattenStyle(style); |
83 | | - return ( |
84 | | - <View |
85 | | - accessibilityIgnoresInvertColors={true} |
| 56 | +const ImageBackground: component( |
| 57 | + ref?: React.RefSetter<React.ElementRef<typeof View>>, |
| 58 | + ...props: ImageBackgroundProps |
| 59 | +) = ({ |
| 60 | + ref, |
| 61 | + children, |
| 62 | + style, |
| 63 | + imageStyle, |
| 64 | + imageRef, |
| 65 | + importantForAccessibility, |
| 66 | + ...props |
| 67 | +}: { |
| 68 | + ref?: React.RefSetter<React.ElementRef<typeof View>>, |
| 69 | + ...ImageBackgroundProps, |
| 70 | +}): React.Node => { |
| 71 | + // $FlowFixMe[underconstrained-implicit-instantiation] |
| 72 | + const flattenedStyle = flattenStyle(style); |
| 73 | + return ( |
| 74 | + <View |
| 75 | + accessibilityIgnoresInvertColors={true} |
| 76 | + importantForAccessibility={importantForAccessibility} |
| 77 | + style={style} |
| 78 | + ref={ref}> |
| 79 | + {/* $FlowFixMe[incompatible-use] */} |
| 80 | + <Image |
| 81 | + {...props} |
86 | 82 | importantForAccessibility={importantForAccessibility} |
87 | | - style={style} |
88 | | - ref={this._captureRef}> |
89 | | - {/* $FlowFixMe[incompatible-use] */} |
90 | | - <Image |
91 | | - {...props} |
92 | | - importantForAccessibility={importantForAccessibility} |
93 | | - style={[ |
94 | | - StyleSheet.absoluteFill, |
95 | | - { |
96 | | - // Temporary Workaround: |
97 | | - // Current (imperfect yet) implementation of <Image> overwrites width and height styles |
98 | | - // (which is not quite correct), and these styles conflict with explicitly set styles |
99 | | - // of <ImageBackground> and with our internal layout model here. |
100 | | - // So, we have to proxy/reapply these styles explicitly for actual <Image> component. |
101 | | - // This workaround should be removed after implementing proper support of |
102 | | - // intrinsic content size of the <Image>. |
103 | | - // $FlowFixMe[prop-missing] |
104 | | - width: flattenedStyle?.width, |
105 | | - // $FlowFixMe[prop-missing] |
106 | | - height: flattenedStyle?.height, |
107 | | - }, |
108 | | - imageStyle, |
109 | | - ]} |
110 | | - ref={imageRef} |
111 | | - /> |
112 | | - {children} |
113 | | - </View> |
114 | | - ); |
115 | | - } |
116 | | -} |
| 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 | +}; |
117 | 106 |
|
118 | | -export type ImageBackgroundInstance = ImageBackground; |
| 107 | +ImageBackground.displayName = 'ImageBackground'; |
119 | 108 |
|
120 | 109 | export default ImageBackground; |
0 commit comments