2015-06-14 60 views
3

我在我的应用程序中有一个NavigatorIOS和TabBarIOS。选择选项卡时,我想更改当前路线的标题。如何更改NavigatorIOS的标题而不更改React Native中的路线

在创建NavigatorIOS没有工作

第一种方式,我在用户状态对象一个变量,但更新的状态并没有改变标题。 (即使渲染被再次调用)

onTabChanged: function (title) { 
    this.setState({ 
    selectedTab: title, 
    }); 
}, 

render() { 
    return (
    <NavigatorIOS 
    ... 
    initialRoute={{ 
     component: Tabs, 
     title: this.state.selectedTab, 
     passProps: { 
     onTabChanged: this.onTabChanged 
     } 
    }} 
    /> 
); 
}, 

没有工作

我也尝试过更新的NavigatorIOS的,我称之为导航状态的第二种方式。 NavigatorIOS的状态中有一个routeStack对象,该对象保留一组路由项目。所以我通过NavigatorIOS的setState更新了阵列,但它也没有工作。

我试图标题从Objective C的改变机模块但我不能达到从NSObject的特定导航栏没有工作的第三条道路。

我希望有人能帮忙。

+0

你解决了吗? –

+0

没有。我不能。我打算用Navigator替换NavigatorIOS,但我现在不在这个项目上工作。导航器更加灵活。 – eluleci

回答

2
var route = this.props.navigator.navigationContext.currentRoute; 
route.title = "newTitle"; 
route.rightButtonTitle = "newRightButtonTitle", 
route.onRightButtonPress =() => { 
    ; 
}; 
this.props.navigator.replace(route); 

顺便说一句,你也可以改变NavigatorIOS的tintColor通过下面的代码...

var app = React.createClass({ 
    getInitialState: function() { 
     return { 
      shadowHidden: false, 
      barTintColor: '#f04f46', 
      titleTextColor: '#fff', 
      tintColor: '#fff', 
     } 
    }, 
    _navigator : function(navigatorProps){ 
     this.setState(navigatorProps); 
    }, 
    render: function(){ 
     return <NavigatorIOS ref='nav' style={styles.container} 
      shadowHidden={this.state.shadowHidden} 
      barTintColor={this.state.barTintColor} 
      titleTextColor={this.state.titleTextColor} 
      tintColor={this.state.tintColor} 
      translucent={false} 
      initialRoute={{ 
      title: title, 
      component: component, 
      passProps: Object.assign({ 
       navigatorHook: this._navigator, 
      }, this.props), 
      }} 
     />; 
    } 
}); 

现在,在明年及部件

this.props.navigatorHook({tintColor: 'red'}); 
相关问题