88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { BackHandler, Platform } from "react-native";
|
|
import {
|
|
ActionMetaData,
|
|
BaseActionTypes,
|
|
GenericActionPayload,
|
|
} from "../actions/GenericAction";
|
|
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, ctaData) => {
|
|
if (navigationRef?.canGoBack()) {
|
|
navigationRef?.goBack();
|
|
} else if (Platform.OS === OsTypeConstants.IOS) {
|
|
NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator(
|
|
JSON.stringify(ctaData),
|
|
);
|
|
} else {
|
|
BackHandler.exitApp();
|
|
}
|
|
},
|
|
push: (navigationRef, ctaData) => {
|
|
navigationRef?.push(BASE_SCREEN, { ctaData });
|
|
},
|
|
};
|
|
|
|
export const Router = {
|
|
handleAction(actionPayload: GenericActionPayload, navigation?: any): void {
|
|
switch (actionPayload.baseActionType) {
|
|
case BaseActionTypes.WIDGET_ACTION: {
|
|
actionPayload.metaData?.forEach(
|
|
(widgetMetaData: ActionMetaData, _: number) => {
|
|
if (!!actionPayload.setScreenData) {
|
|
WidgetActionHandler.handleWidgetAction(
|
|
!!widgetMetaData ? widgetMetaData : {},
|
|
actionPayload.setScreenData,
|
|
actionPayload.setErrorMetaData,
|
|
actionPayload.screenData,
|
|
actionPayload.ctaData,
|
|
navigation,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
break;
|
|
}
|
|
case BaseActionTypes.SCREEN_ACTION: {
|
|
actionPayload.metaData?.forEach(
|
|
(screenMetaData: ActionMetaData, _: number) => {
|
|
if (!!actionPayload.setScreenData) {
|
|
ScreenActionHandler.handleScreenAction(
|
|
!!screenMetaData ? screenMetaData : {},
|
|
actionPayload.setScreenData,
|
|
actionPayload.screenData,
|
|
navigation,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
break;
|
|
}
|
|
default: {
|
|
sendAsAnalyticsEvent({
|
|
name: AnalyticsEventNameConstants.HI_RN_NAVIGATION_ERROR,
|
|
properties: {
|
|
errorType: EVENT_NAMES.BASE_ACTION_TYPE_INVALID_ERROR,
|
|
error: `${actionPayload.baseActionType}`,
|
|
methodName: "Router.handleAction",
|
|
},
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
};
|