futurice/pepperoni-app-kit

BackAndroid is deprecated

khanetor opened this issue · 2 comments

BackAndroid deprecated

We need to update with BackHandler.

I ma using RN 0.43.4, for RN 0.44 BackAndroid needs to be replaced

For my specific configuration I use this:

// Navigator.js
const StackA = StackNavigator({
   Module1: {screen: SomeView1}
})
const StackB = StackNavigator({
   Module2: {screen: SomeView2}
})
const StackC = StackNavigator({
   Module3: {screen: SomeView3}
})
export const Tabs = TabNavigator({
    Tab1: {screen: StackA},
    Tab2:   {screen: StackB},
    Tab3: {screen: StackC},
})

const AppNavigator = StackNavigator({
    Home: {screen: Tabs},
}, {
    headerMode: 'none',
})
export default AppNavigator

//index.android.js
navigateBack() {
        const navigator = store.getState().get('navigator')
        const currentStackScreen = navigator.getIn(['routes', 0, 'routes', 0, 'index'])
        const currentTab = navigator.getIn(['routes', 0, 'index'])

        // if we are in the beginning of our tab stack
        store.dispatch(NavigationActions.back())
        if (currentTab !== 0 || currentStackScreen !== 0) {
            return true
        }

        // otherwise let OS handle the back button action
        return false
    },

This has been changed over to use BackHandler now - see #223