Even though I can get a screen orientation change to update state and re-render, the ImageBackground component still will not update its width.
I have the following code:
<View
onLayout={event => this.mylayoutchange(event)}
style={{ flex: 1, backgroundColor: 'green' }}
>
<ImageBackground
style={{ flex: 1, width: this.state.width, height: this.state.height }}
imageStyle={{ resizeMode: 'repeat' }}
source={require('../assets/images/my_background.jpg')}
>
<View>
<Text>.... Other code here....</Text>
</View>
</ImageBackground>
</View>;
When the user changes the orientation of the device the mylayoutchange() function gets called. It updates state correctly. The render function will update. Width and height are correctly changed as can be seen in console.log()
. However, for whatever reason, the <ImageBackground>
does not update its correct width and height.
When the screen is rotated, the background image no longer fills the entire size of the screen and I instead see the green background color.
What am I doing wrong?
My environment:
"react": "16.13.1",
"react-native": "0.63.2",