Created
May 12, 2017 14:24
-
-
Save sobstel/202590b13e1121ef66eb15de81032b30 to your computer and use it in GitHub Desktop.
React Native ScrollView repeated background
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, { PropTypes, PureComponent } from 'react'; | |
import { Image, ScrollView, } from 'react-native'; | |
export default class ScrollViewWithBg extends PureComponent { | |
constructor (props) { | |
super(props); | |
this.state = {contentSize: {width: 0, height: 0}} | |
} | |
render () { | |
const bgStyles = { | |
position: 'absolute', | |
resizeMode: 'repeat', | |
width: this.state.contentSize.width, | |
height: this.state.contentSize.height, | |
}; | |
return ( | |
<ScrollView | |
onContentSizeChange={(width, height) => this.setState({contentSize: {width, height}})}> | |
<Image | |
source={require('../images/bg.jpg')} | |
style={bgStyles} /> | |
{this.props.children} | |
</ScrollView> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment