Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native webview loading indicator

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} /> 
like image 247
Alex Aung Avatar asked Jul 22 '17 16:07

Alex Aung


People also ask

How do I make Webview faster in react native?

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.


1 Answers

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>   ); } 
like image 81
AdamG Avatar answered Sep 19 '22 13:09

AdamG