11import { LoadingState , NavigationProps , NavigatorProps } from '@bluebase/components' ;
2- import { useComponent , useConfig , useTheme } from '@bluebase/core' ;
3- import { LinkingOptions , NavigationContainer } from '@react-navigation/native' ;
2+ import { useBlueBase , useComponent , useConfig , useTheme } from '@bluebase/core' ;
3+ import { getPathFromState , getStateFromPath , LinkingOptions , NavigationContainer } from '@react-navigation/native' ;
44import * as Linking from 'expo-linking' ;
55import React from 'react' ;
66
77import { useBlueBaseContextPack } from '../../useBlueBaseContextPack' ;
88import { createLinkingConfigs } from './createLinkingConfigs' ;
99import { usePersistentState } from './usePersistentState' ;
1010
11+ export type getStateFromPathConfigFn =
12+ ( defaultState : any , path : string , options ?: any ) => any ;
13+
14+ export type getPathFromStateConfigFn =
15+ ( defaultPath : string , state : any , options ?: any ) => any ;
16+
1117/**
1218 * Navigation (V5)
1319 * This serves as an entry point where BlueBase passes routes and navigation
1420 * configs to this component.
1521 */
1622export const Navigation = ( props : NavigationProps ) => {
17- const { navigator , ... rest } = props ;
23+ const BB = useBlueBase ( ) ;
1824 const { theme } = useTheme ( ) ;
25+ const { navigator, ...rest } = props ;
1926
2027 const contextPack = useBlueBaseContextPack ( ) ;
2128 const Navigator = useComponent < NavigatorProps > ( 'Navigator' ) ;
@@ -29,7 +36,23 @@ export const Navigation = (props: NavigationProps) => {
2936
3037 const linking : LinkingOptions < any > = {
3138 config : createLinkingConfigs ( navigator . routes , contextPack ) ,
32- prefixes : [ Linking . createURL ( '/' ) , ...prefixes ]
39+ prefixes : [ Linking . createURL ( '/' ) , ...prefixes ] ,
40+ getStateFromPath : ( path , options ) => {
41+ const getStateFromPathConfig = BB . Configs . getValue ( 'navigation.linking.getStateFromPath' ) ;
42+ const defaultState = getStateFromPath ( path , options ) ;
43+
44+ return getStateFromPathConfig
45+ ? getStateFromPathConfig ( defaultState , path , options )
46+ : defaultState ;
47+ } ,
48+ getPathFromState : ( state , options ?) => {
49+ const getPathFromStateConfig = BB . Configs . getValue ( 'navigation.linking.getPathFromState' ) ;
50+ const path = getPathFromState ( state , options ) ;
51+
52+ return getPathFromStateConfig
53+ ? getPathFromStateConfig ( path , state , options )
54+ : path ;
55+ } ,
3356 } ;
3457
3558 return (
0 commit comments