import * as React from 'react'; import { Image, ImageBackgroundProps, ImageProps, StyleSheet, View } from 'react-native'; /** * DISCLAIMER: This component has been pretty-much copied from react-native's source code * https://github.com/facebook/react-native/blob/main/Libraries/Image/ImageBackground.js * Few modifications have been done such as converting to functional component, removing ref related logic (since its not required). * Also support for prop `ImageComponent` has been introduced to allow rendering custom * component instead of `Image`. * * * Very simple drop-in replacement for which supports nesting views. * * ```ReactNativeWebPlayer * import React, { Component } from 'react'; * import { AppRegistry, View, ImageBackground, Text } from 'react-native'; * * class DisplayAnImageBackground extends Component { * render() { * return ( * * React * * ); * } * } * */ export const ImageBackground: React.ComponentType< ImageBackgroundProps & { ImageComponent?: React.ComponentType; } > = (props) => { const { children, ImageComponent = Image, imageStyle, importantForAccessibility, style, ...rest } = props; const flattenedStyle = StyleSheet.flatten(style); return ( 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 . height: flattenedStyle?.height, width: flattenedStyle?.width, }, imageStyle, ]} /> {children} ); };