diff --git a/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx b/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx index b7e0ff4728..b523d3c267 100644 --- a/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx +++ b/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx @@ -4,8 +4,10 @@ import React, { useCallback, useEffect } from "react"; import { EmitterSubscription, NativeEventEmitter, + NativeModules, NativeScrollEvent, NativeSyntheticEvent, + Platform, View, } from "react-native"; import Animated, { @@ -32,6 +34,7 @@ import { HOME, INITIAL_Y_VALUE, NativeEventNameConstants, + OsTypeConstants, QUOTE_OFFER_SCREEN, } from "../../../../common/constants"; import { sendAsAnalyticsEvent } from "../../../../common/hooks/useAnalyticsEvent"; @@ -61,7 +64,10 @@ const QuoteOfferScreen = ({ const y = useSharedValue(0); const lastScrollPosition = useSharedValue(0); const navigation = useNavigation(); - const nativeEventListener = new NativeEventEmitter(); + const nativeEventListener = + Platform.OS === OsTypeConstants.ANDROID + ? new NativeEventEmitter() + : new NativeEventEmitter(NativeModules.DeviceEventEmitterModule); const derivedY = useDerivedValue(() => y.value); let reloadPageEventListener = {} as EmitterSubscription; const animationConfig = { diff --git a/App/common/constants/BuildConfigConstants.ts b/App/common/constants/BuildConfigConstants.ts index 5b6855667e..31ade15c69 100644 --- a/App/common/constants/BuildConfigConstants.ts +++ b/App/common/constants/BuildConfigConstants.ts @@ -12,3 +12,8 @@ export const ApiMethod = { DELETE: "DELETE", PATCH: "PATCH", }; + +export enum OsTypeConstants { + IOS = "ios", + ANDROID = "android", +} diff --git a/App/common/hooks/useBottomSheet.tsx b/App/common/hooks/useBottomSheet.tsx index 3b188e93b8..db8be26d53 100644 --- a/App/common/hooks/useBottomSheet.tsx +++ b/App/common/hooks/useBottomSheet.tsx @@ -43,6 +43,8 @@ export const useBottomSheet = ( const replaceBottomSheet = (modalView: ModalView) => { setTimeout(() => { removeBottomSheet(); + }, BOTTOMSHEET_ANIMATION_DURATION); + setTimeout(() => { addBottomSheet(modalView); }, BOTTOMSHEET_ANIMATION_DURATION); // BOTTOMSHEET_ANIMATION_DURATION is for allowing the current bottomsheet to close animatically before opening the new one. diff --git a/App/common/interface/index.ts b/App/common/interface/index.ts index c80f86ac17..3908b536a1 100644 --- a/App/common/interface/index.ts +++ b/App/common/interface/index.ts @@ -25,7 +25,7 @@ type LineItem = { export interface BaseNavigator { navigate(navigationRef: any, ctaData: CtaData): any; - goBack(navigationRef: any): any; + goBack(navigationRef: any, ctaData: CtaData): any; push(navigationRef: any, ctaData: CtaData): any; } diff --git a/App/common/navigator/NavigationRouter.ts b/App/common/navigator/NavigationRouter.ts index 5955260e8e..e94a9cfe26 100644 --- a/App/common/navigator/NavigationRouter.ts +++ b/App/common/navigator/NavigationRouter.ts @@ -1,26 +1,32 @@ -import { BackHandler } from "react-native"; +import { BackHandler, Platform } from "react-native"; import { ActionMetaData, BaseActionTypes, GenericActionPayload, } from "../actions/GenericAction"; -import { BASE_SCREEN } from "../constants/ScreenNameConstants"; -import { sendAsAnalyticsEvent } from "../hooks/useAnalyticsEvent"; -import { BaseNavigator, NavigationType } from "../interface"; -import { ScreenActionHandler } from "../screen/ScreenActionHandler"; -import WidgetActionHandler from "../widgets/widget-actions/WidgetActionHandler"; import { AnalyticsEventNameConstants, EVENT_NAMES, } from "../constants/AnalyticsEventsConstant"; +import { BASE_SCREEN } from "../constants/ScreenNameConstants"; +import { sendAsAnalyticsEvent } from "../hooks/useAnalyticsEvent"; +import { BaseNavigator } from "../interface"; +import { NativeDeeplinkNavigatorModule } from "../native-module/NativeModules"; +import { ScreenActionHandler } from "../screen/ScreenActionHandler"; +import WidgetActionHandler from "../widgets/widget-actions/WidgetActionHandler"; +import { OsTypeConstants } from "../constants"; export const CtaNavigator: BaseNavigator = { navigate: (navigationRef, ctaData) => { navigationRef?.navigate(BASE_SCREEN, { ctaData }); }, - goBack: navigationRef => { + goBack: (navigationRef, ctaData) => { if (navigationRef?.canGoBack()) { navigationRef?.goBack(); + } else if (Platform.OS === OsTypeConstants.IOS) { + NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator( + JSON.stringify(ctaData), + ); } else { BackHandler.exitApp(); } diff --git a/App/common/utilities/NavigationUtil.ts b/App/common/utilities/NavigationUtil.ts index 7695c4a53a..e5f575b3fc 100644 --- a/App/common/utilities/NavigationUtil.ts +++ b/App/common/utilities/NavigationUtil.ts @@ -41,7 +41,7 @@ export const globalHandleClick = ( CtaNavigator.navigate(navigation, cta); break; case CtaType.GO_BACK: - CtaNavigator.goBack(navigation); + CtaNavigator.goBack(navigation, cta); break; default: NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator( diff --git a/components/bottomsheet/BaseBottomSheetComponent.tsx b/components/bottomsheet/BaseBottomSheetComponent.tsx index 28e22edcdf..51d6fe3a28 100644 --- a/components/bottomsheet/BaseBottomSheetComponent.tsx +++ b/components/bottomsheet/BaseBottomSheetComponent.tsx @@ -1,13 +1,15 @@ import React, { useEffect, useRef, useState } from "react"; -import { View, findNodeHandle } from "react-native"; +import { Platform, View, findNodeHandle } from "react-native"; import Modal from "react-native-modal"; import { GenericActionPayload } from "../../App/common/actions/GenericAction"; import { AnalyticsEventNameConstants, AnalyticsMethodNameConstant, + BOTTOMSHEET_ANIMATION_DURATION, NAVIGATION_ERROR, + OsTypeConstants, + TimeoutConstants, } from "../../App/common/constants"; -import { BOTTOMSHEET_ANIMATION_DURATION } from "../../App/common/constants/NumericalConstants"; import { sendAsAnalyticsEvent } from "../../App/common/hooks/useAnalyticsEvent"; import { CtaData, CtaType } from "../../App/common/interface"; import { ModalView } from "../../App/common/interface/modals/ModalView"; @@ -49,20 +51,30 @@ const BaseBottomSheetComponent = ({ closeModal(); break; default: - try { - NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator( - JSON.stringify(cta), - ); - } catch (error) { - sendAsAnalyticsEvent({ - name: AnalyticsEventNameConstants.HI_INVALID_SCREEN_CTA, - properties: { - methodName: - AnalyticsMethodNameConstant.HANDLE_CTA_CLICK_BOTTOMSHEET, - reason: error?.toString() || NAVIGATION_ERROR, - }, - }); + if (Platform.OS === OsTypeConstants.IOS) { + closeModal(); } + setTimeout( + () => { + try { + NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator( + JSON.stringify(cta), + ); + } catch (error) { + sendAsAnalyticsEvent({ + name: AnalyticsEventNameConstants.HI_INVALID_SCREEN_CTA, + properties: { + methodName: + AnalyticsMethodNameConstant.HANDLE_CTA_CLICK_BOTTOMSHEET, + reason: error?.toString() || NAVIGATION_ERROR, + }, + }); + } + }, + Platform.OS === OsTypeConstants.IOS + ? TimeoutConstants.TIMEOUT_1000 + : 0, + ); } }; diff --git a/components/widgets/fab/FAB.tsx b/components/widgets/fab/FAB.tsx index 5185978c7f..c10f9362f8 100644 --- a/components/widgets/fab/FAB.tsx +++ b/components/widgets/fab/FAB.tsx @@ -4,6 +4,8 @@ import { StyledLottie } from "../styled-lottie/StyledLottie"; import { NativeEventEmitter, + NativeModules, + Platform, ViewStyle, useWindowDimensions, } from "react-native"; @@ -24,9 +26,10 @@ import { GenericActionPayload } from "../../../App/common/actions/GenericAction" import { NativeEventNameConstants } from "../../../App/common/constants/EventNameConstants"; import { CtaData } from "../../../App/common/interface"; import { FabWidgetData } from "../../../App/common/interface/widgets/widgetData/FabWidgetData"; -import { FAB_HEIGHT, styles } from "./FABStyle"; -import { StyledImage } from "../../StyledImage"; import { getTextWithHtmlSpace } from "../../../App/common/utilities/MiscUtils"; +import { StyledImage } from "../../StyledImage"; +import { FAB_HEIGHT, styles } from "./FABStyle"; +import { OsTypeConstants } from "../../../App/common/constants"; const FAB = ({ widgetData, @@ -37,7 +40,7 @@ const FAB = ({ widgetData: FabWidgetData; handleActions: ( value: any | undefined | null, - actionPayloadList: GenericActionPayload | undefined + actionPayloadList: GenericActionPayload | undefined, ) => void; handleClick?: (cta: CtaData) => void; scrollStyle?: ViewStyle; @@ -45,18 +48,21 @@ const FAB = ({ const [enabled, setEnabled] = useState(true); const { height } = useWindowDimensions(); useEffect(() => { - const nativeEventListener = new NativeEventEmitter(); + const nativeEventListener = + Platform.OS === OsTypeConstants.ANDROID + ? new NativeEventEmitter() + : new NativeEventEmitter(NativeModules.DeviceEventEmitterModule); let reloadPageEventListener = nativeEventListener.addListener( NativeEventNameConstants.reloadPage, - (event) => { + event => { if (event === true) { setEnabled(false); } - } + }, ); return () => { nativeEventListener.removeAllListeners( - NativeEventNameConstants.reloadPage + NativeEventNameConstants.reloadPage, ); setEnabled(true); }; @@ -86,7 +92,7 @@ const FAB = ({ const maxY = 0; fabPositionY.value = clamp(newY, minY, maxY); }, - onEnd: (_) => {}, + onEnd: _ => {}, }); const animatedRootStyles = useAnimatedStyle(() => { @@ -96,7 +102,7 @@ const FAB = ({ }); const isDraggable = widgetData?.properties?.isDraggable ?? true; - const buttonText = getTextWithHtmlSpace(widgetData?.buttonTitle?.text) + const buttonText = getTextWithHtmlSpace(widgetData?.buttonTitle?.text); const fabContent = ( diff --git a/network/NetworkService.ts b/network/NetworkService.ts index 4777ee687c..bbbb97f47f 100644 --- a/network/NetworkService.ts +++ b/network/NetworkService.ts @@ -1,8 +1,9 @@ -import { handleError, handleSuccess } from "./ApiClient"; -import { AxiosRequestConfig } from "axios"; -import { BASE_URL } from "./NetworkConstant"; -import axios from "axios"; +import axios, { AxiosRequestConfig } from "axios"; +import { Platform } from "react-native"; +import { OsTypeConstants } from "../App/common/constants"; import { getBuildConfigDetails } from "../App/common/utilities/CacheUtils"; +import { getDefaultHeaderData, handleError, handleSuccess } from "./ApiClient"; +import { BASE_URL } from "./NetworkConstant"; import { addBundleVersionToHeader } from "./NetworkUtils"; function newAbortSignal(timeoutMs: number): AbortSignal { @@ -28,11 +29,16 @@ export const get = async ( headers: requestConfig.headers, signal: newAbortSignal(11000), }); - if (params) { requestConfig.params = params; } - + if (Platform.OS === OsTypeConstants.IOS) { + const nativeHeaders = await getDefaultHeaderData(); + requestConfig.headers = { + ...requestConfig, + ...nativeHeaders, + }; + } addBundleVersionToHeader(axiosInstance); const response = await axiosInstance.get(baseUrl + url, requestConfig); @@ -59,7 +65,13 @@ export const post = async ( headers: requestConfig.headers, signal: newAbortSignal(11000), }); - + if (Platform.OS === OsTypeConstants.IOS) { + const nativeHeaders = await getDefaultHeaderData(); + requestConfig.headers = { + ...requestConfig, + ...nativeHeaders, + }; + } addBundleVersionToHeader(axiosInstance); const response = await axiosInstance.post( @@ -90,7 +102,13 @@ export const patch = async ( headers: requestConfig.headers, signal: newAbortSignal(11000), }); - + if (Platform.OS === OsTypeConstants.IOS) { + const nativeHeaders = await getDefaultHeaderData(); + requestConfig.headers = { + ...requestConfig, + ...nativeHeaders, + }; + } addBundleVersionToHeader(axiosInstance); const response = await axiosInstance.patch(