Skip to content

Commit 3e5effa

Browse files
authored
fix: android hardware back button and gesture behavior on Profile tab (#12591)
* fix: android hardware back button navigation on Profile tab * chore: update comments for clarity on back button behavior in MyProfileSettings * revert changes * fix: properly clean up back button event listeners in AutomountedBottomSheetModal and useBackHandler * chore: update Podfile.lock with new checksum * chore: update Podfile.lock with new checksum
1 parent a676e2c commit 3e5effa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/app/Components/BottomSheet/AutomountedBottomSheetModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export const AutomountedBottomSheetModal: FC<AutomountedBottomSheetModalProps> =
5252
}, [visible])
5353

5454
useEffect(() => {
55-
BackHandler.addEventListener("hardwareBackPress", androidBackHandler)
55+
const subscription = BackHandler.addEventListener("hardwareBackPress", androidBackHandler)
56+
57+
return () => subscription.remove()
5658
}, [androidBackHandler])
5759

5860
const renderBackdrop = useCallback(

src/app/utils/hooks/useBackHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { BackHandler } from "react-native"
1212
export function useBackHandler(handler: () => boolean) {
1313
useFocusEffect(
1414
useCallback(() => {
15-
BackHandler.addEventListener("hardwareBackPress", handler)
15+
const subscription = BackHandler.addEventListener("hardwareBackPress", handler)
16+
17+
// Return cleanup function to remove listener when component unmounts or loses focus
18+
return () => subscription.remove()
1619
}, [handler])
1720
)
1821
}

0 commit comments

Comments
 (0)