Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28476

React Navigation + Redux close App on Back Pressed

$
0
0

After converting the app to redux, my react-navigation got some problem. Previously, before integrating with redux, when I press back button (Physical button) react-navigation back to the previous screen. After integrating with redux, the back button will close the app. But, it's still working with goBack() function.

And, this is my Navigator configuration

export const AppNavigator = StackNavigator(
    {
        Home: { screen: HomeScreen },
        ChatDetail: { screen: ChatDetail },
        PulsaDetail: { screen: PulsaDetailScreen },
        Pulsa: { screen: Pulsa }
    },
    {
        headerMode: 'none',
    }
)

class AppWithNavigation extends Component {
    render(){
        return(
            <AppNavigator navigation={ addNavigationHelpers({
                dispatch: this.props.dispatch,
                state: this.props.nav,
            })} />
        )
    }
}

const mapStateToProps = (state) => ({
  nav: state.nav
})

export default connect(mapStateToProps)(AppWithNavigation)

EDIT: It's can be done with manual handle & dispatch back action, but it's can't do it automaticlly? just like before using redux?

BackHandler.addEventListener('hardwareBackPress',() => {
    this.props.goBack()
    return true
})

Viewing all articles
Browse latest Browse all 28476

Trending Articles