Created
April 28, 2017 17:30
-
-
Save thekevinscott/0b2ba3dbd3e3c0b2efd9fd91a08a7696 to your computer and use it in GitHub Desktop.
Example of an absolutely positioned <Image /> with text overlaid in React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
Image, | |
Text, | |
} from 'react-native'; | |
const remote = 'https://s15.postimg.org/tw2qkvmcb/400px.png'; | |
export default class BackgroundImage extends Component { | |
render() { | |
const resizeMode = 'center'; | |
const text = 'This is some text inlaid in an <Image />'; | |
return ( | |
<Image | |
style={{ | |
backgroundColor: '#ccc', | |
flex: 1, | |
resizeMode, | |
position: 'absolute', | |
width: '100%', | |
height: '100%', | |
justifyContent: 'center', | |
}} | |
source={{ uri: remote }} | |
> | |
<Text | |
style={{ | |
backgroundColor: 'transparent', | |
textAlign: 'center', | |
fontSize: 30, | |
padding: 40, | |
}} | |
> | |
{text} | |
</Text> | |
</Image> | |
); | |
} | |
} | |
AppRegistry.registerComponent('BackgroundImage', () => BackgroundImage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is deprecated.. use instead
ImageBackground
.