2017-05-29 74 views
0

我想在react-navigation中創建一個自定義left按鈕。我需要此left按鈕的onPress事件才能轉到特定屏幕;我該怎麼做呢?理想情況下,我想遠離編寫我自己的redux導航,因爲它變得複雜。我可以不用REDX做到這一點嗎?反應導航和自定義左按鈕onPress?

回答

1

它很容易得到這個,試試這個:

const stackNavigatorConfiguration = { 
    // set first Screen 
    initialRouteName: 'Login', 
    // headerMode: 'none'(disable header) 
    // style of switching screens(options: modal/card) 
    mode: Platform.OS === 'ios' ? 'card' : 'card', 
    navigationOptions: ({navigation}) => ({ 
    headerRight: <DrawerButton navigation={navigation} />, 
    headerBackTitle: null, 
    headerStyle: { 
     backgroundColor: '#282b3a' 
    }, 
    headerTitleStyle: { 
     color: 'white' 
    }, 
    // color of the back button 
    headerTintColor: 'white', 
    headerBackTitleStyle: { 
     color: 'white' 
    } 
    }) 
} 

...

const DrawerButton = ({ navigation }) => (
    <TouchableOpacity> 
    <Ionicons 
     style={styles.drawerIcon} 
     name='ios-menu-outline' 
     size={32} 
     onPress={() => navigation.navigate('DrawerOpen')} 
    /> 
    </TouchableOpacity> 
) 

您可以navigationOptions定義按鈕 - headerRight 有你的進口組件(見DrawerButton)