2015-06-14 61 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'}); 
相關問題