Skip to content

Commit

Permalink
fix: no multiple suspense containers for bottom tabs stack itself (?)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLindhout committed Jan 4, 2025
1 parent 4a86f06 commit 28c8c51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
20 changes: 10 additions & 10 deletions src/NavigationNestedProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ function NavigationNestedProvider({ children }: { children: any }) {
const id = React.useId();
const rootKey = 'navigationModalProvider_' + id.replace(':', '--');
const { theme } = React.useContext(OptimizedContext);
const { screens, navigationRoot, ...rest } = React.useContext(
RidgeNavigationContext
);
const { screens, navigationRoot, SuspenseContainer, ...rest } =
React.useContext(RidgeNavigationContext);

const rootNavigator = React.useMemo(() => {
const stateInfos = [
Expand All @@ -36,7 +35,11 @@ function NavigationNestedProvider({ children }: { children: any }) {
route: makeVariablesNavigationFriendly(
rootKeyAndPaths(rootKey, screen.path)
),
renderScene: () => <screen.element />,
renderScene: () => (
<SuspenseContainer>
<screen.element />
</SuspenseContainer>
),
trackCrumbTrail: true,
preloadId: screen.path,
})),
Expand All @@ -48,7 +51,7 @@ function NavigationNestedProvider({ children }: { children: any }) {
navigator.navigate(rootKey);

return navigator;
}, [rootKey, screens]);
}, [SuspenseContainer, rootKey, screens]);

const navigationRootWithModal = React.useMemo(
() => ({
Expand All @@ -67,6 +70,7 @@ function NavigationNestedProvider({ children }: { children: any }) {
value={{
screens,
...rest,
SuspenseContainer,
rootNavigator,
navigationRoot: navigationRootWithModal,
}}
Expand All @@ -81,11 +85,7 @@ function NavigationNestedProvider({ children }: { children: any }) {
return (
<>
<HiddenNavbarWithSwipeBack />
<OptimizedContextProvider
withSuspenseContainer={false}
state={state}
data={data}
>
<OptimizedContextProvider state={state} data={data}>
{state.key === rootKey ? children : state.renderScene()}
</OptimizedContextProvider>
</>
Expand Down
26 changes: 17 additions & 9 deletions src/NavigationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export default function NavigationProvider<ScreenItems extends BaseScreen[]>({
route: makeVariablesNavigationFriendly(
getScreenKey(rootKey, tab, screen.path)
),
renderScene: () => <screen.element />,
renderScene: () => (
<SuspenseContainer>
<screen.element />
</SuspenseContainer>
),
trackCrumbTrail: !isTheSame,
screen,
preloadId: screen.path,
Expand All @@ -171,7 +175,11 @@ export default function NavigationProvider<ScreenItems extends BaseScreen[]>({
key: rootKey,
route: rootKey,
trackCrumbTrail: false,
renderScene: () => <root.child.element />,
renderScene: () => (
<SuspenseContainer>
<root.child.element />
</SuspenseContainer>
),
screen: root.child,
preload: () => preloadRoot(rootKey),
preloadId: root.child.path,
Expand All @@ -181,7 +189,11 @@ export default function NavigationProvider<ScreenItems extends BaseScreen[]>({
route: makeVariablesNavigationFriendly(
rootKeyAndPaths(rootKey, screen.path)
),
renderScene: () => <screen.element />,
renderScene: () => (
<SuspenseContainer>
<screen.element />
</SuspenseContainer>
),
trackCrumbTrail: true,
screen,
preloadId: screen.path,
Expand All @@ -191,7 +203,7 @@ export default function NavigationProvider<ScreenItems extends BaseScreen[]>({
})
.flat();
return new StateNavigator(navigators, getHistoryManager(basePath));
}, [basePath, navigationRoot, preloadRoot, screens]);
}, [SuspenseContainer, basePath, navigationRoot, preloadRoot, screens]);

const preloadLink = React.useCallback(
(url: string) => {
Expand Down Expand Up @@ -333,11 +345,7 @@ export default function NavigationProvider<ScreenItems extends BaseScreen[]>({
<NavigationHandler stateNavigator={rootNavigator}>
<NavigationStackWrapper>
{children && (
<OptimizedContextProvider
state={null}
data={undefined}
withSuspenseContainer={false}
>
<OptimizedContextProvider state={null} data={undefined}>
{children}
</OptimizedContextProvider>
)}
Expand Down
9 changes: 1 addition & 8 deletions src/contexts/OptimizedContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export function OptimizedContextProvider({
data,
state,
children,
withSuspenseContainer = true,
}: {
data: any;
state: State | null;
children: any;
withSuspenseContainer?: boolean;
}) {
const {
preloadedCache,
Expand All @@ -37,7 +35,6 @@ export function OptimizedContextProvider({
preloadScreen,
preloadElement,
theme,
SuspenseContainer,
} = React.useContext(RidgeNavigationContext);
const {
stateNavigator,
Expand Down Expand Up @@ -73,11 +70,7 @@ export function OptimizedContextProvider({
);
return (
<OptimizedContext.Provider value={value}>
{withSuspenseContainer ? (
<SuspenseContainer>{children}</SuspenseContainer>
) : (
<React.Suspense fallback={null}>{children}</React.Suspense>
)}
<React.Suspense fallback={null}>{children}</React.Suspense>
</OptimizedContext.Provider>
);
}
Expand Down

0 comments on commit 28c8c51

Please sign in to comment.