/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow * @format */ 'use strict'; const Image = require('Image'); const React = require('React'); const StyleSheet = require('StyleSheet'); const View = require('View'); const ensureComponentIsNative = require('ensureComponentIsNative'); /** * 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 * * ); * } * } * * // App registration and rendering * AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground); * ``` */ class ImageBackground extends React.Component<$FlowFixMeProps> { setNativeProps(props: Object) { // Work-around flow const viewRef = this._viewRef; if (viewRef) { ensureComponentIsNative(viewRef); viewRef.setNativeProps(props); } } _viewRef: ?React.ElementRef = null; _captureRef = ref => { this._viewRef = ref; }; render() { const {children, style, imageStyle, imageRef, ...props} = this.props; 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 . width: style.width, height: style.height, }, imageStyle, ]} ref={imageRef} /> {children} ); } } module.exports = ImageBackground;