2017-10-19 118 views
0

我使用react-navigation來構建嵌套的TabNavigator。無法在TabNavigator中切換選項卡(react-navigation)

enter image description here

我的問題是我無法瀏覽到其他選項卡,直到我點擊搜索按鈕。這太奇怪了。

UPDATE)我剛剛發現,當我更改標籤時,它只會更改「關注」或「熱門」標題。它不呈現seconrd選項卡,「常用」,並且不會切換選項卡。

這裏是第一StackNavigator(附加到根)

export default StackNavigator ({ 
    Feedo: { 
    screen: FeedMainTabNavigator, 
    navigationOptions: { 
     title: 'Title', 
    }, 
    }, 
    Searcho: { 
    screen: SearchScreen, // if I click second tab, it doesn't show the second tab. 
      //But then I navigate to SearchScreen and goback to FeedScreen, 
      //I can see the second tab was selected. 
    } 
}, { 
    lazy: true 
}); 

這裏是FeedMainTabNavigator

export default TabNavigator({ 
    UserFeed: { 
    screen: UserFeedScreen 
    }, 
    PopularPost: { 
    screen: PopularPostScreen 
    }, 
}, { 
    tabBarOptions: { 
     style: { 
     backgroundColor: "#7E50CE", 
     overflow: "hidden" 
     }, 
     activeTintColor: "white", 
     inactiveTintColor: "white", 
     tabStyle: { width: 120 }, 
     indicatorStyle: { backgroundColor: 'white' } 
    } 
    } 
); 

這裏是UserFeedScreen(也許問題就在這裏?)

import {withRkTheme, RkText} from 'react-native-ui-kitten' 
let ThemedNavigationBar = withRkTheme(NavBar); 
import { FontAwesome } from '../../assets/icons' 

class UserFeedScreen extends Component { 
    static navigationOptions = ({navigation}) => ({ 
    title: 'Follow', 
    headerRight: (
     <RkText 
     rkType='awesome small' 
     style={{color: 'white'}} 
     onPress={() => {navigation.navigate('Searcho')}}>{FontAwesome.search}</RkText> 
    ), 
    header: (headerProps) => { 
     return <ThemedNavigationBar navigation={navigation} headerProps={headerProps}/> 
    }, 
    }) 

回答

1

你需要一個重置,因爲Searcho是在一個水平aobve。試試這個

import { NavigationActions } from 'react-navigation'; 

onPress={() => { 
    const resetAction = NavigationActions.reset({ 
     index: 0, 
     actions: [ 
     NavigationActions.navigate({ routeName: 'Searcho'}) 
     ] 
    }); 
    navigation.dispatch(resetAction); 
    }} 
+0

更換onPress={() => {navigation.navigate('Searcho')}}我想你可以解決這個問題(+200賞金):https://stackoverflow.com/questions/47930049/how-to-reset-tabnavigator - 當用戶-日誌中取距其它屏 –