croul
V2EX  ›  React

React Native 中嵌套 Webview,网页跳转后如何动态改变顶部导航栏?

  •  
  •   croul · Jan 12, 2021 · 2350 views
    This topic created in 1949 days ago, the information mentioned may be changed or developed.
    我在 React Native 中用了一个 Webview,webview 显示首页的时候,顶部导航栏只有一个 title,网页跳转后,我想让顶部导航栏加一个返回按钮,请问如何实现?
    1 replies    2021-01-12 11:20:59 +08:00
    croul
        1
    croul  
    OP
       Jan 12, 2021
    搞定了。
    获取 navigationOptions 的时候,加一个参数。let backButtonEnabled = navigation.getParam("backButtonEnabled");
    backButtonEnabled 为 true 的时候,设置 headerLeft 为返回按钮。
    在组件中,初始化的时候设置该参数为 false 。this.props.navigation.setParams({backButtonEnabled: false});
    需要显示返回按钮的时候,再设置为 true 。this.props.navigation.setParams({backButtonEnabled: true});
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3813 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:58 · PVG 12:58 · LAX 21:58 · JFK 00:58
    ♥ Do have faith in what you're doing.