diff --git a/App/Container/Navi-Insurance/screen/benefit-screen/BenefitScreen.tsx b/App/Container/Navi-Insurance/screen/benefit-screen/BenefitScreen.tsx index 6fcf98d30f..96574f9d4d 100644 --- a/App/Container/Navi-Insurance/screen/benefit-screen/BenefitScreen.tsx +++ b/App/Container/Navi-Insurance/screen/benefit-screen/BenefitScreen.tsx @@ -28,6 +28,7 @@ import { isValidHexColor } from "../../../../common/utilities/ValidateColors"; import QuoteOfferErrorScreen from "../quote-offer-screen/error-screen/QuoteOfferErrorScreen"; import WaitingPeriodShimmerScreen from "../waiting-period-screen/shimmer-screen/WaitingPeriodShimmerScreen"; import styles from "./BenefitScreenStyles"; +import { useBackSwipeListener } from "../../../../common/hooks"; const BenefitScreen = ({ ctaData, @@ -84,7 +85,7 @@ const BenefitScreen = ({ handleClick && backCta && handleClick(backCta); return true; }; - + useBackSwipeListener(navigation, backCta, BENEFIT_SCREEN); useEffect(() => { if (backCta) { BackHandler.addEventListener(HARDWARE_BACK_PRESS, handleBackButtonClick); diff --git a/App/Container/Navi-Insurance/screen/generic-error-screen/GenericErrorScreen.tsx b/App/Container/Navi-Insurance/screen/generic-error-screen/GenericErrorScreen.tsx index 1bcfdba46c..057100e565 100644 --- a/App/Container/Navi-Insurance/screen/generic-error-screen/GenericErrorScreen.tsx +++ b/App/Container/Navi-Insurance/screen/generic-error-screen/GenericErrorScreen.tsx @@ -14,12 +14,19 @@ import { import { CtaData } from "../../../../common/interface"; import { globalHandleClick } from "../../../../common/utilities/NavigationUtil"; import { styles } from "./GenericErrorScreenStyle"; +import { useBackSwipeListener } from "../../../../common/hooks"; const GenericErrorScreen = () => { const navigation = useNavigation(); const handleClick = (cta?: CtaData) => { globalHandleClick(navigation, cta, GENERIC_ERROR_SCREEN); }; + useBackSwipeListener( + navigation, + ConstantCta.STATIC_HEADER_LEFT_ICON_CTA, + GENERIC_ERROR_SCREEN, + ); + return ( { if (backCta) { BackHandler.addEventListener(HARDWARE_BACK_PRESS, handleBackButtonClick); diff --git a/App/common/constants/EventNameConstants.ts b/App/common/constants/EventNameConstants.ts index ac4e7cbb6f..cbaa40f835 100644 --- a/App/common/constants/EventNameConstants.ts +++ b/App/common/constants/EventNameConstants.ts @@ -1,4 +1,5 @@ export enum NativeEventNameConstants { - reloadPage = "reloadPage", - reloadPageWithCtaData = "reloadPageWithCtaData", -} \ No newline at end of file + reloadPage = "reloadPage", + reloadPageWithCtaData = "reloadPageWithCtaData", + BackSwipe = "BackSwipe", +} diff --git a/App/common/hooks/index.ts b/App/common/hooks/index.ts index 01b1260799..73778b01bc 100644 --- a/App/common/hooks/index.ts +++ b/App/common/hooks/index.ts @@ -1 +1,2 @@ export { useAnalyticsEvent } from "./useAnalyticsEvent"; +export { useBackSwipeListener } from "./useBackSwipeListener"; diff --git a/App/common/hooks/useBackSwipeListener.ts b/App/common/hooks/useBackSwipeListener.ts new file mode 100644 index 0000000000..fd377f6581 --- /dev/null +++ b/App/common/hooks/useBackSwipeListener.ts @@ -0,0 +1,38 @@ +import { useRef } from "react"; +import { NativeEventEmitter, NativeModules, Platform } from "react-native"; +import React from "react"; +import { NavigationProp, useFocusEffect } from "@react-navigation/native"; +import { NativeEventNameConstants, OsTypeConstants } from "../constants"; +import { CtaData } from "../interface"; +import { globalHandleClick } from "../utilities/NavigationUtil"; + +const nativeEventListener = new NativeEventEmitter( + NativeModules.DeviceEventEmitterModule, +); + +export const useBackSwipeListener = ( + navigation: NavigationProp, + cta?: CtaData, + screenName?: string, +) => { + if (Platform.OS === OsTypeConstants.ANDROID) { + return; + } + const backSwipeListenerRef = useRef(null); + useFocusEffect( + React.useCallback(() => { + backSwipeListenerRef.current = nativeEventListener.addListener( + NativeEventNameConstants.BackSwipe, + () => { + globalHandleClick(navigation, cta, screenName); + }, + ); + return () => { + if (backSwipeListenerRef.current) { + backSwipeListenerRef.current.remove(); + backSwipeListenerRef.current = null; + } + }; + }, [navigation, cta, screenName]), + ); +}; diff --git a/components/widgets/HeaderWithAssetsWidget.tsx b/components/widgets/HeaderWithAssetsWidget.tsx index ccd0683d3b..61cd1243f2 100644 --- a/components/widgets/HeaderWithAssetsWidget.tsx +++ b/components/widgets/HeaderWithAssetsWidget.tsx @@ -14,7 +14,10 @@ import { HeaderWithAssetsWidgetData } from "../../App/common/interface/widgets/w import { StyledImage } from "../StyledImage"; import { StyledLottie } from "./styled-lottie/StyledLottie"; import { StyledText } from "./styled-text/StyledText"; +import { useNavigation } from "@react-navigation/native"; +import { useBackSwipeListener } from "../../App/common/hooks"; +const navigation = useNavigation(); const HeaderWithAssetsWidget = ({ widgetData, widgetStyle, @@ -38,6 +41,7 @@ const HeaderWithAssetsWidget = ({ handleClick(widgetData?.leftIcon?.cta); return true; }; + useBackSwipeListener(navigation, widgetData?.leftIcon?.cta, ""); useEffect(() => { BackHandler.addEventListener(HARDWARE_BACK_PRESS, handleBackButtonClick);