Skip to content

Instantly share code, notes, and snippets.

@haikyuu
Created January 16, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikyuu/63e2afc126016b5a5c06b58a72480647 to your computer and use it in GitHub Desktop.
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.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