Skip to content

Commit

Permalink
feat: [IOBP-502] Disable swipe back while payment outcome showed (#5434)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
Hantex9 and forrest57 authored Jan 25, 2024
1 parent 51caedd commit 660d955
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
WalletPaymentOutcome,
WalletPaymentOutcomeEnum
} from "../types/PaymentOutcomeEnum";
import { useAvoidHardwareBackButton } from "../../../../utils/useAvoidHardwareBackButton";

type WalletPaymentOutcomeScreenNavigationParams = {
outcome: WalletPaymentOutcome;
Expand All @@ -36,6 +37,8 @@ type WalletPaymentOutcomeRouteProps = RouteProp<
>;

const WalletPaymentOutcomeScreen = () => {
useAvoidHardwareBackButton();

const { params } = useRoute<WalletPaymentOutcomeRouteProps>();
const { outcome } = params;

Expand All @@ -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,
Expand Down

0 comments on commit 660d955

Please sign in to comment.