Created
September 18, 2019 10:04
-
-
Save nikilarigela/78cfa88e445bcfaa4f45d62e359b416d to your computer and use it in GitHub Desktop.
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
class AsyncImage extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { loaded: false }; | |
} | |
onLoad = () => { | |
this.setState(() => ({ loaded: true })); | |
}; | |
render() { | |
const { source, placeholder, style, ...rest } = this.props; | |
const { loaded } = this.state; | |
return ( | |
<> | |
<Image | |
source={source} | |
style={loaded ? style : {}} | |
{...rest} | |
onLoad={this.onLoad} | |
/> | |
{!loaded && placeholder} | |
</> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment