美文网首页
react-native中ref用法

react-native中ref用法

作者: 喜剧收尾_XWX | 来源:发表于2020-07-13 12:42 被阅读0次
  • 用法一
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);
    }
    
  }

相关文章

网友评论

      本文标题:react-native中ref用法

      本文链接:https://www.haomeiwen.com/subject/thracktx.html