Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 50 additions & 61 deletions packages/react-native/Libraries/Image/ImageBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @format
*/

import type {HostInstance} from '../../src/private/types/HostInstance';
import type {ImageBackgroundProps} from './ImageProps';

import View from '../Components/View/View';
Expand Down Expand Up @@ -43,68 +42,58 @@ export type {ImageBackgroundProps} from './ImageProps';
* AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground);
* ```
*/
class ImageBackground extends React.Component<ImageBackgroundProps> {
setNativeProps(props: {...}) {
// Work-around flow
const viewRef = this._viewRef;
if (viewRef) {
viewRef.setNativeProps(props);
}
}

_viewRef: ?React.ElementRef<typeof View> = 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 (
<View
accessibilityIgnoresInvertColors={true}
const ImageBackground: component(
ref?: React.RefSetter<React.ElementRef<typeof View>>,
...props: ImageBackgroundProps
) = ({
ref,
children,
style,
imageStyle,
imageRef,
importantForAccessibility,
...props
}: {
ref?: React.RefSetter<React.ElementRef<typeof View>>,
...ImageBackgroundProps,
}): React.Node => {
// $FlowFixMe[underconstrained-implicit-instantiation]
const flattenedStyle = flattenStyle(style);
return (
<View
accessibilityIgnoresInvertColors={true}
importantForAccessibility={importantForAccessibility}
style={style}
ref={ref}>
{/* $FlowFixMe[incompatible-use] */}
<Image
{...props}
importantForAccessibility={importantForAccessibility}
style={style}
ref={this._captureRef}>
{/* $FlowFixMe[incompatible-use] */}
<Image
{...props}
importantForAccessibility={importantForAccessibility}
style={[
StyleSheet.absoluteFill,
{
// Temporary Workaround:
// Current (imperfect yet) implementation of <Image> overwrites width and height styles
// (which is not quite correct), and these styles conflict with explicitly set styles
// of <ImageBackground> and with our internal layout model here.
// So, we have to proxy/reapply these styles explicitly for actual <Image> component.
// This workaround should be removed after implementing proper support of
// intrinsic content size of the <Image>.
// $FlowFixMe[prop-missing]
width: flattenedStyle?.width,
// $FlowFixMe[prop-missing]
height: flattenedStyle?.height,
},
imageStyle,
]}
ref={imageRef}
/>
{children}
</View>
);
}
}
style={[
StyleSheet.absoluteFill,
{
// Temporary Workaround:
// Current (imperfect yet) implementation of <Image> overwrites width and height styles
// (which is not quite correct), and these styles conflict with explicitly set styles
// of <ImageBackground> and with our internal layout model here.
// So, we have to proxy/reapply these styles explicitly for actual <Image> component.
// This workaround should be removed after implementing proper support of
// intrinsic content size of the <Image>.
// $FlowFixMe[prop-missing]
width: flattenedStyle?.width,
// $FlowFixMe[prop-missing]
height: flattenedStyle?.height,
},
imageStyle,
]}
ref={imageRef}
/>
{children}
</View>
);
};

export type ImageBackgroundInstance = ImageBackground;
ImageBackground.displayName = 'ImageBackground';

export default ImageBackground;
Loading