From 660d955f6f0bab025a4701594a5a1796dbd59efa Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 25 Jan 2024 21:16:26 +0100 Subject: [PATCH] feat: [IOBP-502] Disable swipe back while payment outcome showed (#5434) ## Short description This PR disables the swipe-back on iOS devices and the Android hardware back button when the payment outcome screen is shown. ## List of changes proposed in this pull request - In the payment outcome screen has been added the custom hook `useAvoidHardwareBackButton` in order to disable the Android back button; - In the payment outcome screen has added a hook that disables the gestures both on the current navigation and the parent navigation (This is a workaround that can be solved by introducing react-navigation v6) ## How to test If you complete a new payment flow until you reach the outcome screen, you shouldn't be able to return to the previous screen. --------- Co-authored-by: Martino Cesari Tomba <60693085+forrest57@users.noreply.github.com> --- .../screens/WalletPaymentOutcomeScreen.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ts/features/walletV3/payment/screens/WalletPaymentOutcomeScreen.tsx b/ts/features/walletV3/payment/screens/WalletPaymentOutcomeScreen.tsx index 6654b6bb063..2019e066ea5 100644 --- a/ts/features/walletV3/payment/screens/WalletPaymentOutcomeScreen.tsx +++ b/ts/features/walletV3/payment/screens/WalletPaymentOutcomeScreen.tsx @@ -25,6 +25,7 @@ import { WalletPaymentOutcome, WalletPaymentOutcomeEnum } from "../types/PaymentOutcomeEnum"; +import { useAvoidHardwareBackButton } from "../../../../utils/useAvoidHardwareBackButton"; type WalletPaymentOutcomeScreenNavigationParams = { outcome: WalletPaymentOutcome; @@ -36,6 +37,8 @@ type WalletPaymentOutcomeRouteProps = RouteProp< >; const WalletPaymentOutcomeScreen = () => { + useAvoidHardwareBackButton(); + const { params } = useRoute(); const { outcome } = params; @@ -47,6 +50,18 @@ const WalletPaymentOutcomeScreen = () => { outcome }); + // TODO: This is a workaround to disable swipe back gesture on this screen + // .. it should be removed as soon as the migration to react-navigation v6 is completed (https://pagopa.atlassian.net/browse/IOBP-522) + React.useEffect(() => { + // Disable swipe + navigation.setOptions({ gestureEnabled: false }); + navigation.getParent()?.setOptions({ gestureEnabled: false }); + // Re-enable swipe after going back + return () => { + navigation.getParent()?.setOptions({ gestureEnabled: true }); + }; + }, [navigation]); + const paymentAmount = pipe( paymentDetailsPot, pot.toOption,