252 lines
5.9 KiB
TypeScript
252 lines
5.9 KiB
TypeScript
/*
|
|
* File: navigationUtils.ts
|
|
* Description: Navigation utility functions for AI Prediction module
|
|
* Design & Developed by Tech4Biz Solutions
|
|
* Copyright (c) Spurrin Innovations. All rights reserved.
|
|
*/
|
|
|
|
import { CommonActions } from '@react-navigation/native';
|
|
import type { AIPredictionStackParamList } from './navigationTypes';
|
|
|
|
// ============================================================================
|
|
// NAVIGATION UTILITY FUNCTIONS
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Navigate to AI Prediction Details
|
|
*
|
|
* Purpose: Navigate to AI prediction case details screen
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param caseId - AI prediction case ID
|
|
*/
|
|
export const navigateToAIPredictionDetails = (
|
|
navigation: any,
|
|
caseId: string
|
|
) => {
|
|
navigation.navigate('AIPredictionDetails', { caseId });
|
|
};
|
|
|
|
/**
|
|
* Navigate to AI Prediction Filters
|
|
*
|
|
* Purpose: Navigate to advanced filters screen
|
|
*
|
|
* @param navigation - Navigation object
|
|
*/
|
|
export const navigateToAIPredictionFilters = (navigation: any) => {
|
|
navigation.navigate('AIPredictionFilters');
|
|
};
|
|
|
|
/**
|
|
* Navigate to AI Prediction Statistics
|
|
*
|
|
* Purpose: Navigate to detailed statistics screen
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param timeRange - Optional time range filter
|
|
*/
|
|
export const navigateToAIPredictionStats = (
|
|
navigation: any,
|
|
timeRange?: 'today' | 'week' | 'month'
|
|
) => {
|
|
navigation.navigate('AIPredictionStats', { timeRange });
|
|
};
|
|
|
|
/**
|
|
* Go Back to AI Prediction List
|
|
*
|
|
* Purpose: Navigate back to AI prediction list screen
|
|
*
|
|
* @param navigation - Navigation object
|
|
*/
|
|
export const goBackToAIPredictionList = (navigation: any) => {
|
|
navigation.navigate('AIPredictionList');
|
|
};
|
|
|
|
/**
|
|
* Reset to AI Prediction List
|
|
*
|
|
* Purpose: Reset navigation stack to AI prediction list
|
|
*
|
|
* @param navigation - Navigation object
|
|
*/
|
|
export const resetToAIPredictionList = (navigation: any) => {
|
|
navigation.dispatch(
|
|
CommonActions.reset({
|
|
index: 0,
|
|
routes: [{ name: 'AIPredictionList' }],
|
|
})
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Can Go Back
|
|
*
|
|
* Purpose: Check if navigation can go back
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @returns Boolean indicating if can go back
|
|
*/
|
|
export const canGoBack = (navigation: any): boolean => {
|
|
return navigation.canGoBack();
|
|
};
|
|
|
|
/**
|
|
* Get Current Route Name
|
|
*
|
|
* Purpose: Get the current route name
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @returns Current route name or undefined
|
|
*/
|
|
export const getCurrentRouteName = (navigation: any): string | undefined => {
|
|
return navigation.getCurrentRoute()?.name;
|
|
};
|
|
|
|
/**
|
|
* Get Current Route Params
|
|
*
|
|
* Purpose: Get the current route parameters
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @returns Current route params or undefined
|
|
*/
|
|
export const getCurrentRouteParams = (navigation: any): any => {
|
|
return navigation.getCurrentRoute()?.params;
|
|
};
|
|
|
|
/**
|
|
* Navigate with Replace
|
|
*
|
|
* Purpose: Navigate to a screen by replacing the current one
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param routeName - Route name to navigate to
|
|
* @param params - Optional route parameters
|
|
*/
|
|
export const navigateWithReplace = (
|
|
navigation: any,
|
|
routeName: keyof AIPredictionStackParamList,
|
|
params?: any
|
|
) => {
|
|
navigation.replace(routeName, params);
|
|
};
|
|
|
|
/**
|
|
* Navigate with Push
|
|
*
|
|
* Purpose: Navigate to a screen by pushing it onto the stack
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param routeName - Route name to navigate to
|
|
* @param params - Optional route parameters
|
|
*/
|
|
export const navigateWithPush = (
|
|
navigation: any,
|
|
routeName: keyof AIPredictionStackParamList,
|
|
params?: any
|
|
) => {
|
|
navigation.push(routeName, params);
|
|
};
|
|
|
|
/**
|
|
* Pop Navigation Stack
|
|
*
|
|
* Purpose: Pop the specified number of screens from the stack
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param count - Number of screens to pop (default: 1)
|
|
*/
|
|
export const popNavigationStack = (navigation: any, count: number = 1) => {
|
|
navigation.pop(count);
|
|
};
|
|
|
|
/**
|
|
* Pop to Top
|
|
*
|
|
* Purpose: Pop to the top of the navigation stack
|
|
*
|
|
* @param navigation - Navigation object
|
|
*/
|
|
export const popToTop = (navigation: any) => {
|
|
navigation.popToTop();
|
|
};
|
|
|
|
/**
|
|
* Set Navigation Params
|
|
*
|
|
* Purpose: Set parameters for the current screen
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param params - Parameters to set
|
|
*/
|
|
export const setNavigationParams = (navigation: any, params: any) => {
|
|
navigation.setParams(params);
|
|
};
|
|
|
|
/**
|
|
* Add Navigation Listener
|
|
*
|
|
* Purpose: Add a navigation event listener
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param eventName - Event name to listen for
|
|
* @param callback - Callback function
|
|
* @returns Unsubscribe function
|
|
*/
|
|
export const addNavigationListener = (
|
|
navigation: any,
|
|
eventName: string,
|
|
callback: (e: any) => void
|
|
) => {
|
|
return navigation.addListener(eventName, callback);
|
|
};
|
|
|
|
/**
|
|
* Remove Navigation Listener
|
|
*
|
|
* Purpose: Remove a navigation event listener
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @param eventName - Event name
|
|
* @param callback - Callback function
|
|
*/
|
|
export const removeNavigationListener = (
|
|
navigation: any,
|
|
eventName: string,
|
|
callback: (e: any) => void
|
|
) => {
|
|
navigation.removeListener(eventName, callback);
|
|
};
|
|
|
|
/**
|
|
* Check if Screen is Focused
|
|
*
|
|
* Purpose: Check if the current screen is focused
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @returns Boolean indicating if screen is focused
|
|
*/
|
|
export const isScreenFocused = (navigation: any): boolean => {
|
|
return navigation.isFocused();
|
|
};
|
|
|
|
/**
|
|
* Get Navigation State
|
|
*
|
|
* Purpose: Get the current navigation state
|
|
*
|
|
* @param navigation - Navigation object
|
|
* @returns Navigation state
|
|
*/
|
|
export const getNavigationState = (navigation: any) => {
|
|
return navigation.getState();
|
|
};
|
|
|
|
/*
|
|
* End of File: navigationUtils.ts
|
|
* Design & Developed by Tech4Biz Solutions
|
|
* Copyright (c) Spurrin Innovations. All rights reserved.
|
|
*/
|