-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to avoid flickering when Image re-render ? #981
Comments
Are you changing the image URL? If so, then you can layer multiple images on top of each other with transparent backgrounds (and |
hi, @sahrens There is a example, maybe re-render by 'use strict'
var React = require('react-native')
var {
AppRegistry,
ScrollView,
View,
Text,
StyleSheet,
Image,
} = React
var test = React.createClass({
getInitialState() {
return {
i: 1
}
},
componentDidMount() {
var that = this
setInterval(function () {
that.setState({
i: that.state.i + 1
})
}, 500)
},
render() {
var content = <Image style={{width: 300, height: 300,}} source={{uri: 'https://tse1-mm.cn.bing.net/th?id=RlT8VmiyzVdVy5tpPgcU1bAlnhtSrwZb3vxI1r2lWH9Yg&w=272&h=272&c=7&rs=1&qlt=90&o=4&pid=1.9'}} />
return (
<ScrollView style={{marginTop: 100}} key={this.state.i}>
<View>{content}</View>
</ScrollView>
)
}
})
AppRegistry.registerComponent('swiper', () => test) |
Why are you changing the key? That could definitely cause flickering because it will bypass the react diffing algorithm and force the view to be destroyed and a fresh one replace it. Usually that will happen seamlessly within one frame, but it might not in all cases. If you're doing it to refresh scroll position, I'd recommend using something like
|
thanks @sahrens I see, |
I am using ImageBackground component on a login form and changing any state of form field or when the from receives props the image flickers, at first I thought it might be due to me using high resolution image but changing resolution did not solve the issue. |
I had flickering issues with I don't know why, but replacing <Image
style={styles.logoImage}
resizeMethod="scale"
resizeMode="contain"
// source={Logo}
defaultSource={Logo}
/> But in Android there is no
<Image
style={styles.logoImage}
resizeMethod="scale"
resizeMode="cover"
source={Logo}
defaultSource={Logo}
/> |
@MacKentoch Your solution worked perfectly for me developing an iOS Build. |
@MacKentoch what did you do for Android regarding "get back source prop"? |
@MacKentoch thank you so much, works like charm |
@MacKentoch is that only solution for android, I mean defaultSource not supported at android, can I use "... platform" thing if android source, if ios defaultSource or something like that :D |
Is there something wrong?
Maybe I should do some cache first like image render with canvas?
Any help, thanks
The text was updated successfully, but these errors were encountered: