import React from 'react'; import { StackView } from './stack/StackView'; import { TabView } from './tabs/TabView'; import type { NavigatorState, RouterInstance, Action, StackEntry, TabEntry, TabBarRenderProps, } from './types'; interface NavigatorRendererProps { state: NavigatorState; router: RouterInstance; components: Record>; layouts: Record>; customTabBars: Record React.ReactNode>; navigatorName?: string; dispatch: (action: Action) => void; } /** * Recursive component that renders either a StackView or TabView based on the * current state node type, and recurses into nested navigators via `renderContent`. */ export function NavigatorRenderer({ state, router, components, layouts, customTabBars, navigatorName, dispatch, }: NavigatorRendererProps) { const Layout = navigatorName ? layouts[navigatorName] : undefined; let content: React.ReactNode = null; if (state.type === 'stack') { content = ( dispatch({ type: 'DISMISS', key })} renderContent={(entry: StackEntry) => { if (entry.nestedState) { return ( ); } return null; }} /> ); } else if (state.type === 'tabs') { content = ( dispatch({ type: 'SWITCH_TAB', tabKey })} customTabBar={navigatorName ? customTabBars[navigatorName] : undefined} renderContent={(tab: TabEntry, key: string) => { if (tab.nestedState) { return ( ); } return null; }} /> ); } if (Layout && content) { return {content}; } return content; }