react-native-webview-crosswalk icon indicating copy to clipboard operation
react-native-webview-crosswalk copied to clipboard

add renderLoading callback to CrosswalkWebview

Open iapolog2u opened this issue 8 years ago • 2 comments

This modification is based on this repo and offical webview

renderLoading:

image

renderError:

image

iapolog2u avatar Dec 20 '16 11:12 iapolog2u

I would prefer this library to remain agnostic of any styling of the WebView, error display, or any other determinations of visual appearance. In my opinion, we should render an unstyled WebView only, and communicate errors to the parent component so it can choose what to show and how it will look. What do you think about that strategy, and is there a way you could see updating this pull request to do that?

jordaaash avatar Jan 02 '17 04:01 jordaaash

Thanks for your reply, I agree with you. But I don't know how to optimize it : ) In my usage scenario I want my webview on Android behave like iOS.

Below is the code of parent component, it use startInLoadingState, renderLoading and renderError to do the stuff (to choose what to show and how it will look)


import {
  WebView,
  BackAndroid,
  Dimensions,
  Text,
  Image,
  TouchableOpacity,
  TouchableWithoutFeedback,
  View,
  Modal,
  Platform,
} from 'react-native';

import WebViewAndroid from 'react-native-webview-crosswalk';

...

import LoadingView from '../Components/LoadingView';
import LoadingErrorView from '../Components/LoadingErrorView';

...

  renderLoading() {
    const loadingText = 'v' + JsConfig['VERSION_NAME'][Platform.OS] + ' 加载中';
    return <LoadingView desc={loadingText} />;
  }

  renderError(domain, code, message) {
    return <LoadingErrorView
            errorDomain={domain}
            errorCode={code}
            errorDesc={message}
            />;
  }

  renderWebviewAndroid() {
    return (
      <WebViewAndroid
        ref={(ref) => { this.webview = ref; }}
        automaticallyAdjustContentInsets={false}
        style={styles.base}
        source={{ uri: this.props.lastUrl }}
        javaScriptEnabled
        domStorageEnabled
        startInLoadingState
        scalesPageToFit
        decelerationRate="normal"
        onShouldStartLoadWithRequest={() => {
          const shouldStartLoad = true;
          return shouldStartLoad;
        }}
        onNavigationStateChange={this.onNavigationStateChange}
        onLoad={this.onload}
        renderLoading={this.renderLoading}
        renderError={this.renderError}
      />
    );
  }

  renderWebviewIOS() {
    return (
      <WebView
        ref={(ref) => { this.webview = ref; }}
        automaticallyAdjustContentInsets={false}
        style={styles.base}
        source={{ uri: this.props.lastUrl }}
        javaScriptEnabled
        domStorageEnabled
        startInLoadingState
        scalesPageToFit
        decelerationRate="normal"
        onShouldStartLoadWithRequest={() => {
          const shouldStartLoad = true;
          return shouldStartLoad;
        }}
        onNavigationStateChange={this.onNavigationStateChange}
        onLoad={this.onload}
        renderLoading={this.renderLoading}
        renderError={this.renderError}
      />
    );
  }

  renderWebView() {
    if (Platform.OS === 'ios') {
      return this.renderWebviewIOS();
    } else {
      return this.renderWebviewAndroid();
    }
  };

iapolog2u avatar Jan 03 '17 12:01 iapolog2u