I am trying to show loading indicator in webweb as follow. Loading indicator is showing but there is white background show after page is loaded. If I change to startInLoadingState to false, web content is showing but loading indicator does not show. It is happing in "react-native": "0.46.3" on ios
renderLoadingView() { return ( <ActivityIndicator animating = {this.state.visible} color = '#bc2b78' size = "large" style = {styles.activityIndicator} hidesWhenStopped={true} /> ); }
<WebView source={source} renderLoading={this.renderLoadingView} startInLoadingState={true} />
For faster loading by pre loaded data, You should fetch data by WebView instance of fetch api. You can create a hidden WebView by setting width and height 0 and load your site on that. This will load your site on ViewView and keep cache, that will available for next time loading.
I like this approach which shows the activity indicator overlayed on the loading Webview so you don't have to wait until the entire page is loaded to start seeing content.
constructor(props) { super(props); this.state = { visible: true }; } hideSpinner() { this.setState({ visible: false }); } render() { return ( <View style={{ flex: 1 }}> <WebView onLoad={() => this.hideSpinner()} style={{ flex: 1 }} source={{ uri: this.props.navigation.state.params.url }} /> {this.state.visible && ( <ActivityIndicator style={{ position: "absolute", top: height / 2, left: width / 2 }} size="large" /> )} </View> ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With