Skip to content

Instantly share code, notes, and snippets.

@VictorKoenders
Created July 10, 2015 14:01
Show Gist options
  • Save VictorKoenders/75fc8c5bfcf47ffd197a to your computer and use it in GitHub Desktop.
Save VictorKoenders/75fc8c5bfcf47ffd197a to your computer and use it in GitHub Desktop.
Memory leak React-Native
// This works
renderPage: function (Page, index) {
var isLast = index == this.props.pages.length - 1;
var pageStyles = [styles.page];
if (isLast) {
pageStyles.push(styles.last);
}
var arguments = this.props.arguments[index] || {};
console.log(pageStyles);
return <React.View key={index}>
<Page {...arguments} />
</React.View>;
},
// But this doesn't
// notice the added styles={pageStyles} in the React.View component
renderPage: function (Page, index) {
var isLast = index == this.props.pages.length - 1;
var pageStyles = [styles.page];
if (isLast) {
pageStyles.push(styles.last);
}
var arguments = this.props.arguments[index] || {};
console.log(pageStyles);
return <React.View key={index} style={pageStyles}>
<Page {...arguments} />
</React.View>;
},
// The value of pageStyles is [styles.page, styles.last], or [86, 88] as actual values
// The styles are listed below
var styles = React.StyleSheet.create({
page: {
flex: 0,
flexWrap: 'wrap',
backgroundColor: 'transparent',
shadowColor: '#000000',
shadowOpacity: 0.4,
shadowRadius: 1,
shadowOffset: {
height: 0,
width: 1
}
},
last: {
flex: 1,
borderRightWidth: 0
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment