react-native中ref用法

2020-07-13  本文已影响0人  喜剧收尾_XWX
import Loading from 'react-native-loading-w';

//view
render() {
    return (
        <View>
            <Text>test loading</Text>
            <Loading ref={'loading'} text={'Loading...'} />
        </View>
    );
}

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

//usage
this.getLoading().show();
//or
this.getLoading().show('uploading...');
//or
this.getLoading().show('uploading...', true);
this.getLoading().dismiss();
  1. 创建
 <WebView 
       ref = {(webview) => 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);
    }
    
  }
上一篇 下一篇

猜你喜欢

热点阅读