Created
February 6, 2017 22:31
-
-
Save jamesreggio/0d9896836cdee3fbbba7ac53ef77021a to your computer and use it in GitHub Desktop.
Repro for an uninitialized memory issue in React Native 0.41.1
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
// The underlying issue pertains to uninitialized memory and is inherently non-deterministic. | |
// This will consistently reproduce for me using React Native 0.41.1 on iOS 9.3, but it will not reproduce on iOS 10.2. | |
// If the app launches and does not immediately display a redbox with an error, the bug did not reproduce. | |
import React, { Component } from 'react'; | |
import { AppRegistry, View } from 'react-native'; | |
export default class App extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
firstLayout: true, | |
rowStyle: { | |
flex: 1, | |
}, | |
}; | |
} | |
onLayout(e) { | |
const { firstLayout } = this.state; | |
const { height } = e.nativeEvent.layout; | |
if (firstLayout) { | |
this.setState({ | |
firstLayout: false, | |
rowStyle: { | |
height: height + 1, // Trigger one more layout. | |
}, | |
}); | |
} else { | |
if (height === Infinity) { | |
console.error('Test failed. Received layout with infinite height.'); | |
} else { | |
console.log('Test passed. Layout is stable.'); | |
} | |
} | |
} | |
render() { | |
const { rowStyle } = this.state; | |
return ( | |
<View style={{flex: 1}}> | |
<View | |
onLayout={this.onLayout.bind(this)} | |
style={rowStyle} | |
/> | |
</View> | |
); | |
} | |
} | |
AppRegistry.registerComponent('repro', () => App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment