From 9637dd4a1b78d5f6da510b1b4ad10d45d67badbf Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 24 May 2017 11:19:31 -0700 Subject: [PATCH] Introducing , replacement for which supports nesting views Summary: We are removing support of nesting views inside component. We decided to do this because having this feature makes supporting `intrinsinc content size` of the `` impossible; so when the transition process is complete, there will be no need to specify image size explicitly, it can be inferred from actual image bitmap. And this is the step #0. is very simple drop-in replacement which implements this functionality via very simple styling. Please, use instead of if you want to put something inside. Reviewed By: yungsters Differential Revision: D5100021 fbshipit-source-id: 640c0fb2d1066e166d974efba39b4cfaaee7dd45 --- Libraries/Image/ImageBackground.js | 64 +++++++++++++++++++ .../react-native-implementation.js | 1 + RNTester/js/ImageExample.js | 9 +-- 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 Libraries/Image/ImageBackground.js diff --git a/Libraries/Image/ImageBackground.js b/Libraries/Image/ImageBackground.js new file mode 100644 index 000000000..aff1632e9 --- /dev/null +++ b/Libraries/Image/ImageBackground.js @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule ImageBackground + * @flow + * @format + */ +'use strict'; + +const Image = require('Image'); +const React = require('React'); +const View = require('View'); + +/** + * 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 { + render() { + const {children, style, ...props} = this.props; + return ( + + + {children} + + ); + } +} + +module.exports = ImageBackground; diff --git a/Libraries/react-native/react-native-implementation.js b/Libraries/react-native/react-native-implementation.js index f5c6b0a96..bb8820234 100644 --- a/Libraries/react-native/react-native-implementation.js +++ b/Libraries/react-native/react-native-implementation.js @@ -24,6 +24,7 @@ const ReactNative = { get DrawerLayoutAndroid() { return require('DrawerLayoutAndroid'); }, get FlatList() { return require('FlatList'); }, get Image() { return require('Image'); }, + get ImageBackground() { return require('ImageBackground'); }, get ImageEditor() { return require('ImageEditor'); }, get ImageStore() { return require('ImageStore'); }, get KeyboardAvoidingView() { return require('KeyboardAvoidingView'); }, diff --git a/RNTester/js/ImageExample.js b/RNTester/js/ImageExample.js index 580b98875..b30efc2be 100644 --- a/RNTester/js/ImageExample.js +++ b/RNTester/js/ImageExample.js @@ -20,6 +20,7 @@ var { StyleSheet, Text, View, + ImageBackground, } = ReactNative; var base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdoRp0iOQEiDzgZPnG6DbldcomadViflnl/cL93tOoVbsOLVM2jylvdWjXolWX1hmfZbGR/wjypDjFLSZIRov09BgYmtUqPQPlQrPapecLgTIy0jMgPKtTeob2zWtrGH3xvjUkPCtNg/tm1rjwrMa+mdUkPd3hWbH0jArPGiU9ufCsNNWFZ40wpwn+62/66R2RUtoso1OB34tnLOcy7YB1fUdc9e0q3yru8PGM773vXsuZ5YIZX+5xmHwHGVvlrGPN6ZSiP1smOsMMde40wKv2VmwPPVXNut4sVpUreZiLBHi0qln/VQeI/LTMYXpsJtFiclUN+5HVZazim+Ky+7sAvxWnvjXrJFneVtLWLyPJu9K3cXLWeOlbMTlrIelbMDlrLenrjEQOtIF+fuI9xRp9ZBFp6+b6WT8RrxEpdK64BuvHgDk+vUy+b5hYk6zfyfs051gRoNO1usU12WWRWL73/MMEy9pMi9qIrR4ZpV16Rrvduxazmy1FSvuFXRkqTnE7m2kdb5U8xGjLw/spRr1uTov4uOgQE+0N/DvFrG/Jt7i/FzwxbA9kDanhf2w+t4V97G8lrT7wc08aA2QNUkuTfW/KimT01wdlfK4yEw030VfT0RtZbzjeMprNq8m8tnSTASrTLti64oBNdpmMQm0eEwvfPwRbUBywG5TzjPCsdwk3IeAXjQblLCoXnDVeoAz6SfJNk5TTzytCNZk/POtTSV40NwOFWzw86wNJRpubpXsn60NJFlHeqlYRbslqZm2jnEZ3qcSKgm0kTli3zZVS7y/iivZTweYXJ26Y+RTbV1zh3hYkgyFGSTKPfRVbRqWWVReaxYeSLarYv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg=='; @@ -117,7 +118,7 @@ var NetworkImageExample = React.createClass({ : null; return this.state.error ? {this.state.error} : - this.setState({loading: true})} @@ -125,7 +126,7 @@ var NetworkImageExample = React.createClass({ onProgress={(e) => this.setState({progress: Math.round(100 * e.nativeEvent.loaded / e.nativeEvent.total)})} onLoad={() => this.setState({loading: false, error: false})}> {loader} - ; + ; } }); @@ -436,13 +437,13 @@ exports.examples = [ title: 'Nesting', render: function() { return ( - React - + ); }, },