Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware button on android stops working when dismissing Dialog #3075

Closed
rasck opened this issue Feb 3, 2022 · 5 comments
Closed

Hardware button on android stops working when dismissing Dialog #3075

rasck opened this issue Feb 3, 2022 · 5 comments

Comments

@rasck
Copy link

rasck commented Feb 3, 2022

Current behaviour

When we dismiss a dialog by pressing outside the dialog the hardware back button on android stops working, but pressing back on the navigation header works.

Expected behaviour

When we dismiss a dialog by pressing outside the dialog e.g. by setting visible to false, we still expect the hardware back button on android to work

{visible && <TestDialog visible={visible} onDismiss={onDismiss} />}

Code sample

Full code sample
Expo snack
A summary of the code:

const TestDialog = ({ visible, onDismiss } : { visible: boolean, onDismiss: () => void }) => {
    return (
        <Dialog
            visible={visible}
            onDismiss={onDismiss}
            style={{ padding: 30}}
        >
            <View>
                <Text style={{ fontSize: 20 }}>
                    Hello to the dialog
                </Text>
            </View>
        </Dialog>
    );
};

export default function ModalScreen() {
  const [visible, setVisible] = useState(false);
  const onDismiss = useCallback(() => { setVisible(false) }, [])
  return (
    <View style={styles.container}>
      <Pressable onPress={() => setVisible(vis => !vis)}>
        <Text style={styles.title}>Toggle dialog</Text>
       </Pressable>
      {visible && <TestDialog visible={visible} onDismiss={onDismiss} />}
    </View>
  );
}

What have you tried

If i change
{visible && <TestDialog visible={visible} onDismiss={onDismiss} />}
to
<TestDialog visible={visible} onDismiss={onDismiss} />
it works.

But we have some cases where we would like to able to just do like this
{visible && <TestDialog visible={visible} onDismiss={onDismiss} />}

Your Environment

Moto G7 Android Version 10
we used a virtual hardware button in this example. But our customers have the issue as well on devices with real hardware buttons

Deps from the expo snack:

"react-native-paper": "4.9.2",
"@expo/vector-icons": "^12.0.0",
"expo-constants": "~12.1.3",
"@react-navigation/native": "6.0.2",
"@react-navigation/stack": "6.0.7",
"react-native-gesture-handler": "~1.10.2",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.8.0",
"expo-web-browser": "~10.0.3",
"expo-font": "~10.0.3",
"expo-splash-screen": "~0.13.5",
"expo-status-bar": "~1.1.0",
"@react-navigation/bottom-tabs": "*",
"@react-navigation/native-stack": "*",
"@babel/core": "^7.12.9",
"@types/react": "~17.0.21",
"@types/react-native": "0.64.12",
"typescript": "~4.3.5",
"expo-linking": "~2.4.2",
"react-native": "0.64.3",
"react-native-vector-icons" : "unknown",
 "expo": "43.0.0"
@github-actions
Copy link

github-actions bot commented Feb 3, 2022

Couldn't find version numbers for the following packages in the issue:

  • react-native
  • react-native-vector-icons
  • expo

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • react-native-paper (found: 4.9.2, latest: 4.11.2)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@github-actions
Copy link

github-actions bot commented Feb 4, 2022

Couldn't find version numbers for the following packages in the issue:

  • react-native-vector-icons

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • react-native-paper (found: 4.9.2, latest: 4.11.2)
  • react-native (found: 0.64.3, latest: 0.67.2)
  • expo (found: 43.0.0, latest: 44.0.6)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@rasck
Copy link
Author

rasck commented Feb 4, 2022

I can verify the the issue still persists in react-native-paper v. 4.11.2

In addition, after dismissing the dialog by pressing outside the dialog (in the grey area); the hardware back button works if i press it two timess in a row fast. It seems like the dialog screen still hangs somehow

@rasck
Copy link
Author

rasck commented Feb 4, 2022

I think a PR has just been merged to fix this: #3049

@rasck
Copy link
Author

rasck commented Feb 4, 2022

I can confirmed it is fixed:
Tried upgrading my snack with the alpha version, "react-native-paper": "4.12.0-alpha.0",
https://snack.expo.dev/MtcQOT4hZ

And it works! 🎉

@rasck rasck closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant