What's the best way to add a full screen background image What's the best way to add a full screen background image javascript javascript

What's the best way to add a full screen background image


(This has been deprecated now you can use ImageBackground)

This is how I've done it. The main deal was getting rid of the static fixed sizes.

class ReactStrap extends React.Component {  render() {    return (      <Image source={require('image!background')} style={styles.container}>        ... Your Content ...      </Image>    );  }}var styles = StyleSheet.create({  container: {    flex: 1,    // remove width and height to override fixed static size    width: null,    height: null,  }};


You can use flex: 1 styling on an <Image> element to have it fill the whole screen. You can then use one of the Image resize modes to have the image completely fill the element:

<Image source={require('image!egg')} style={styles.backgroundImage} />

Style:

import React from 'react-native';let { StyleSheet } = React;let styles = StyleSheet.create({  backgroundImage: {    flex: 1,    resizeMode: 'cover', // or 'stretch'  }});

I'm pretty sure you can get rid of the <View> wrapping your image and this will work.


Note: This solution is old. Please refer to https://facebook.github.io/react-native/docs/images.html#background-image-via-nesting instead

Try this solution. It is officially supported. I have just tested it and works flawlessly.

var styles = StyleSheet.create({  backgroundImage: {    flex: 1,    alignSelf: 'stretch',    width: null,  }});

And as for using it as Background image, just do the following.

<Image style={styles.backgroundImage}>  <View>    <Text>All your stuff</Text>  </View></Image>