Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created May 12, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sobstel/202590b13e1121ef66eb15de81032b30 to your computer and use it in GitHub Desktop.
Save sobstel/202590b13e1121ef66eb15de81032b30 to your computer and use it in GitHub Desktop.
React Native ScrollView repeated background
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