wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

Android HardwareBackButtonOptions not working #7555

Closed huynqjmango360 closed 2 years ago

huynqjmango360 commented 2 years ago

I try to use HardwareBackButtonOptions config but instead of pop stack, android back hardware minimize app to back ground.

Navigation.push<ProductDetailProps>( componentId, { component: { name: Screens.ProductDetail, passProps: { product, }, options: { statusBar: { style: 'dark', animated: true, }, topBar: { visible: false, height: 0, }, layout: { componentBackgroundColor: 'transparent', }, hardwareBackButton: { popStackOnPress: true, dismissModalOnPress: true, }, animations: buildSharedElementAnimations(product.id), }, }, } );

Did i missing something here?

Im using RNN 7.28.0, RN 0.68.1, google pixel 5, android 13

sashansk3 commented 2 years ago

Hey, @huynqjmango360 are you using the hardware back button inside the bottom tab? Or are you using the hardware back button on the first stack screen?

huynqjmango360 commented 2 years ago

@sashansk3 my ProductDetail screen is push from ProductList, it's child of bottom tab stack.

bottomTabs: { id: BottomTabs, options: { bottomTabs: { testID: 'Button-Tabs', }, }, children: [ { stack: { id: Screens.HomeStack, children: [ { component: { name: Screens.HomeScreen, options: { topBar: { visible: false, }, }, }, },

sashansk3 commented 2 years ago

I have the same problem, after a few days of research I found a problem in the StackController.java on line 407.

Try to replace return stack.size() > 1; with return stack.size() >= 1;. This change fixed the hardware back button issue in my case.