Created
January 16, 2020 13:02
-
-
Save haikyuu/63e2afc126016b5a5c06b58a72480647 to your computer and use it in GitHub Desktop.
how to display a loading spinner while the webview page is loading in react-native
This file contains hidden or 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
{this.state.isLoading ? ( | |
<ActivityIndicator size="large" style={{ alignSelf: 'center', marginTop: 150 }} /> | |
) : null} | |
<WebView | |
useWebKit | |
style={{ width: '100%', display: !this.state.isLoading ? 'flex' : 'none' }} | |
source={{ uri: 'https://google.com' }} | |
injectedJavaScript={` | |
window.ReactNativeWebView.postMessage('loaded') | |
`} | |
onMessage={event => { | |
if (event.nativeEvent.data === 'loaded') { | |
this.setState({ | |
isLoading: false, | |
}); | |
} | |
}} | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment