2016-07-19 3 views
2

私は、次のTabBarIOS.Itemを設定している:どのようにして、反応ネイティブを使用してナビゲーションスタックの一番上にTabBarIOSをポップすることができますか?

  <TabBarIOS.Item 
      selected={this.state.selectedTab === 'tab1'} 
      title='Tab 1' 
      icon={require('./Components/Icons/IconImages/Tab1Icon.png')} 
      onPress={() => { 
       this.setState({ 
       selectedTab: 'tab1' 
       }); 

      }}> 
      <MyNavigatorIOS client={this.state.client} initialStep={this.state.initialStep} /> 

      </TabBarIOS.Item> 

私はthis example in the react native docsあたりとしてthis.props.navigator.popToTop();火にonPressイベントを使用しようとしています。ただし、TabBarIOS onPressイベントがpopToTop()というイベントを発生させ、子のイベントMyNavigatorIOSは発生しないようにしたいという違いがあります。どうすればこれを達成できますか?

答えて

2

私はあなたが何ができるか、同じ問題が、そうのように、あなたのビューにし、その中のナビゲーターに参照を追加されました:

  this.refs.timeline.refs.timelineNavigator.popToTop() 

だから、TabBarのコードは次のようになります

<TabBarIOS.Item 
     systemIcon="history" 
     title="Timeline" 
     badge={this.state.timelineBadge} 
     selected={this.state.selectedTab === 'timeline'} 
     onPress={() => { 
     if (this.state.selectedTab === 'timeline') { 
      this.refs.timeline.refs.timelineNavigator.popToTop() 
     } else { 
      this.setState({ selectedTab: 'timeline' }) 
     } 
     }}> 
     <Timeline 
     ref="timeline" 
     /> 
    </TabBarIOS.Item> 
+0

これはうまくいくようです。私は 'EventEmitter'を使って解決し、適切な子画面でイベントを処理しました。しかし、これはより良く見える=) –

関連する問題