2017-07-10 7 views
0

react-navigationを反応ネイティブアプリケーションを制御するために使用しています。 Chatタブでネイティブの反応ナビゲーション、TabNavigatorに反応し、タブ画面を変更したときにリクエストを送信する方法

const MainTab = TabNavigator({ 
    Home: tabscreen(HomeScreen, '/home', 'home', 'home'), 
    Chat: tabscreen(ChatScreen, '/chat', 'chat', 'chat'), 
    Find: tabscreen(FindScreen, '/find', 'find', 'find'), 
    Profile: tabscreen(ProfileScreen, '/profile', 'profile', 'profile') 
}, { 
    tabBarPosition: 'bottom', 
    swipeEnabled: false, 
    animationEnabled: false, 
    lazy: true, 
    //...other configs 
    tabBarOptions: { 
    // tint color is passed to text and icons (if enabled) on the tab bar 
    activeTintColor: '#1BBC9B', 
    inactiveTintColor: '#9B9B9B', 
    showIcon: true, 
    style: { 
     backgroundColor: '#F4F4F4', 
     borderTopWidth: 0, 
     height: 49 
    }, 
    labelStyle: { 
     marginTop: 0, 
     marginLeft: 0, 
     marginRight: 0, 
     marginBottom: 1.5 
    } 
    } 
}); 



    const AppNavigator = StackNavigator({ 
    Main: { 
    screen: MainTab , 
    path: '/', 
    navigationOptions: { 
     // header: null, 
     headerVisible: false, 
     gesturesEnabled: false, 
    } 
    }, 

    .... 

    { 
    initialRouteName: 'Main', 
    mode: 'card', 
    headerMode: 'screen', 
    navigationOptions: { 
     headerVisible: false, 
     gesturesEnabled: true, 
     headerStyle: styles.headerStyle, 
     headerTitleStyle: styles.headerTitleStyle, 
     headerTintColor: 'white', 
     headerBackTitle: null, 
    } 
}); 

、私はChatScreenさんcomponentDidMount関数内のリストデータを取得するために、バックエンドにリクエストを送信します。それはうまくいく。 ChatScreenから別の画面をナビゲートするときは、何かをしてから別の画面の左上隅にある戻るボタンをクリックしてChatScreenに戻ります。リストのデータをバックエンドから再度リクエストする必要がありますが、componentDidMount doesnもう一度実行しないでください。

ChatScreenが「A」という名前の別の画面にナビゲートする場合。 「A」画面のナビゲートはChatScreenに戻ります。この場合、ChatScreencomponentDidMount関数を実行しません。

私が画面をChatScreenに変更すると、リストデータを要求しています。 react lifecycle function

もう1つ、私は状態を制御するためにreduxを使用しています。

+0

uはまた反応し、ナビゲーションタグを追加することができますか? – icemelt

答えて

0

これはまだサポートされていません。問題は#51です。

、それは#723

回避策として、あなたはタブがフォーカスされているかどうかを知るために、高次成分を使用し、このpmachawoski'sを使用することができ、安定V1にロードマップにだが、これに伴う問題は、それはいつもですさ一度実行されたcomponentDidMountとは異なります。

+0

ありがとうございました。 – jiexishede

関連する問題