react-native中ref用法

  • 用法一
import Loading from 'react-native-loading-w';

//view
render() {
    return (
        
            test loading
            
        
    );
}

getLoading() {
    return this.refs['loading'];
}

//usage
this.getLoading().show();
//or
this.getLoading().show('uploading...');
//or
this.getLoading().show('uploading...', true);
this.getLoading().dismiss();
  • 用法二
  1. 创建
  this.webview = webview}
       source={{ uri: this.state.url }}
       style = {styles.webView_style}
       startInLoadingState={true}
       onNavigationStateChange={(e) => this.onNavChange(e)}
       />

2.全局引用

goBack() {

    if (this.state.canGoBack)
    {
      this.webview.goBack();
    }
    else
    {
      NavigationUtil.goBack(this.props.navigation);
    }
    
  }

你可能感兴趣的:(react-native中ref用法)