diff --git a/packages/react-native/Libraries/Image/ImageBackground.js b/packages/react-native/Libraries/Image/ImageBackground.js index 628c7cbebd4c..04819776c41b 100644 --- a/packages/react-native/Libraries/Image/ImageBackground.js +++ b/packages/react-native/Libraries/Image/ImageBackground.js @@ -8,7 +8,6 @@ * @format */ -import type {HostInstance} from '../../src/private/types/HostInstance'; import type {ImageBackgroundProps} from './ImageProps'; import View from '../Components/View/View'; @@ -43,68 +42,58 @@ export type {ImageBackgroundProps} from './ImageProps'; * AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground); * ``` */ -class ImageBackground extends React.Component { - setNativeProps(props: {...}) { - // Work-around flow - const viewRef = this._viewRef; - if (viewRef) { - viewRef.setNativeProps(props); - } - } - _viewRef: ?React.ElementRef = null; - - _captureRef = (ref: null | HostInstance) => { - this._viewRef = ref; - }; - - render(): React.Node { - const { - children, - style, - imageStyle, - imageRef, - importantForAccessibility, - ...props - } = this.props; - - // $FlowFixMe[underconstrained-implicit-instantiation] - const flattenedStyle = flattenStyle(style); - return ( - >, + ...props: ImageBackgroundProps +) = ({ + ref, + children, + style, + imageStyle, + imageRef, + importantForAccessibility, + ...props +}: { + ref?: React.RefSetter>, + ...ImageBackgroundProps, +}): React.Node => { + // $FlowFixMe[underconstrained-implicit-instantiation] + const flattenedStyle = flattenStyle(style); + return ( + + {/* $FlowFixMe[incompatible-use] */} + - {/* $FlowFixMe[incompatible-use] */} - overwrites width and height styles - // (which is not quite correct), and these styles conflict with explicitly set styles - // of and with our internal layout model here. - // So, we have to proxy/reapply these styles explicitly for actual component. - // This workaround should be removed after implementing proper support of - // intrinsic content size of the . - // $FlowFixMe[prop-missing] - width: flattenedStyle?.width, - // $FlowFixMe[prop-missing] - height: flattenedStyle?.height, - }, - imageStyle, - ]} - ref={imageRef} - /> - {children} - - ); - } -} + style={[ + StyleSheet.absoluteFill, + { + // Temporary Workaround: + // Current (imperfect yet) implementation of overwrites width and height styles + // (which is not quite correct), and these styles conflict with explicitly set styles + // of and with our internal layout model here. + // So, we have to proxy/reapply these styles explicitly for actual component. + // This workaround should be removed after implementing proper support of + // intrinsic content size of the . + // $FlowFixMe[prop-missing] + width: flattenedStyle?.width, + // $FlowFixMe[prop-missing] + height: flattenedStyle?.height, + }, + imageStyle, + ]} + ref={imageRef} + /> + {children} + + ); +}; -export type ImageBackgroundInstance = ImageBackground; +ImageBackground.displayName = 'ImageBackground'; export default ImageBackground;