Skip to content

Commit 780c08e

Browse files
committed
Supported function props in rsc, e.g., shared els
Can't pass a function from a server component (App) to a client component, so lots of NavigationStack props didn't work, e.g., shared elements. Moved the NavigationStack out of server component (App) into client component (RootProvider) so all props work, including the function ones like shared elements
1 parent 625ecea commit 780c08e

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

NavigationReactMobile/sample/rsc/src/App.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use server-entry';
22
import './client';
3-
import { NavigationStack, Scene } from 'navigation-react-mobile';
3+
import { Scene } from 'navigation-react-mobile';
44
import RootProvider from './RootProvider';
55
import People from './People';
66
import Person from './Person';
@@ -13,22 +13,12 @@ const App = async ({url}: any) => {
1313
</head>
1414
<body>
1515
<RootProvider url={url}>
16-
<NavigationStack
17-
unmountStyle={[{transform: 'translateX(100%)'}, {transform: 'translateX(0)'}]}
18-
crumbStyle={[{transform: 'translateX(5%) scale(0.9)', opacity: 0},{transform: 'translateX(0) scale(1)', opacity: 1}]}
19-
style={{
20-
position: 'fixed',
21-
left: '0',
22-
right: '0',
23-
top: '0',
24-
bottom: '0',
25-
overflow: 'auto',
26-
backgroundColor: '#fff',
27-
margin: '8px',
28-
}}>
29-
<Scene stateKey="people"><People /></Scene>
30-
<Scene stateKey="person" dataKeyDeps={['id']}><Person /></Scene>
31-
</NavigationStack>
16+
<Scene stateKey="people">
17+
<People />
18+
</Scene>
19+
<Scene stateKey="person" dataKeyDeps={['id']}>
20+
<Person />
21+
</Scene>
3222
</RootProvider>
3323
</body>
3424
</html>

NavigationReactMobile/sample/rsc/src/RootProvider.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useMemo, useContext, useEffect } from "react";
33
import { fetchRSC } from '@parcel/rsc/client';
44
import { StateNavigator } from 'navigation';
55
import { NavigationHandler } from "navigation-react";
6-
import { MobileHistoryManager } from 'navigation-react-mobile';
6+
import { NavigationStack, MobileHistoryManager } from 'navigation-react-mobile';
77
import stateNavigator from "./stateNavigator";
88
import HmrContext from "./HmrContext";
99

@@ -42,7 +42,21 @@ const RootProvider = ({url, children}: any) => {
4242
});
4343
return (
4444
<NavigationHandler stateNavigator={clientNavigator} fetchRSC={fetchRSC}>
45-
{children}
45+
<NavigationStack
46+
unmountStyle={[{transform: 'translateX(100%)'}, {transform: 'translateX(0)'}]}
47+
crumbStyle={[{transform: 'translateX(5%) scale(0.9)', opacity: 0},{transform: 'translateX(0) scale(1)', opacity: 1}]}
48+
style={{
49+
position: 'fixed',
50+
left: '0',
51+
right: '0',
52+
top: '0',
53+
bottom: '0',
54+
overflow: 'auto',
55+
backgroundColor: '#fff',
56+
margin: '8px',
57+
}}>
58+
{children}
59+
</NavigationStack>
4660
</NavigationHandler>
4761
)
4862
}

0 commit comments

Comments
 (0)