Skip to content

Commit

Permalink
rename onHardwareBackPress to onBack to clarify behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Feb 16, 2023
1 parent 70c77fc commit 310401b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/frontend/screens/PhotosModal/ConfirmDeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ConfirmDeleteModal = ({
isOpen={isOpen}
disableBackrop={disableBackdrop}
onDismiss={closeSheet}
onHardwareBackPress={closeSheet}
onBack={closeSheet}
>
<BottomSheetContent
buttonConfigs={[
Expand Down
22 changes: 9 additions & 13 deletions src/frontend/sharedComponents/BottomSheetModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ export const useBottomSheetModal = ({

// Handles cases where Android hardware backpress button is used to trigger navigation events
// not covered by usePreventNavigationBack
const usePreventHardwareBackPressHandler = (
enable: boolean,
onHardwareBackPress?: () => void
) => {
const useBackHandler = (enable: boolean, onBack?: () => void) => {
React.useEffect(() => {
let subscription: NativeEventSubscription;

if (enable) {
// This event is triggered by both Android hardware back press and gesture back swipe
subscription = BackHandler.addEventListener("hardwareBackPress", () => {
if (onHardwareBackPress) {
onHardwareBackPress();
if (onBack) {
onBack();
}

return true;
Expand All @@ -74,7 +72,7 @@ const usePreventHardwareBackPressHandler = (
return () => {
if (subscription) subscription.remove();
};
}, [enable, onHardwareBackPress]);
}, [enable, onBack]);
};

const useSnapPointsCalculator = () => {
Expand Down Expand Up @@ -107,17 +105,15 @@ const useSnapPointsCalculator = () => {
interface Props extends React.PropsWithChildren<{}> {
isOpen: boolean;
onDismiss?: () => void;
onHardwareBackPress?: () => void;
// Triggered by: Android hardware back press and gesture back swipe
onBack?: () => void;
snapPoints?: (string | number)[];
disableBackrop?: boolean;
}

export const BottomSheetModal = React.forwardRef<RNBottomSheetModal, Props>(
(
{ children, isOpen, onDismiss, onHardwareBackPress, disableBackrop },
ref
) => {
usePreventHardwareBackPressHandler(isOpen, onHardwareBackPress);
({ children, isOpen, onDismiss, onBack, disableBackrop }, ref) => {
useBackHandler(isOpen, onBack);

const { snapPoints, updateSheetHeight } = useSnapPointsCalculator();

Expand Down

0 comments on commit 310401b

Please sign in to comment.