Skip to content

Commit 298d524

Browse files
committed
Fix removing shared screen docs for static API
1 parent 992cbf3 commit 298d524

File tree

1 file changed

+15
-49
lines changed

1 file changed

+15
-49
lines changed

versioned_docs/version-7.x/auth-flow.md

+15-49
Original file line numberDiff line numberDiff line change
@@ -854,18 +854,19 @@ const RootStack = createNativeStackNavigator({
854854
screens: {
855855
Home: HomeScreen,
856856
Profile: ProfileScreen,
857-
Help: HelpScreen,
858857
},
859858
},
860859
LoggedOut: {
861860
if: useIsSignedOut,
862861
screens: {
863862
SignIn: SignInScreen,
864863
SignUp: SignUpScreen,
865-
Help: HelpScreen,
866864
},
867865
},
868866
},
867+
screens: {
868+
Help: HelpScreen,
869+
},
869870
});
870871
```
871872

@@ -891,15 +892,17 @@ isSignedIn ? (
891892
</TabItem>
892893
</Tabs>
893894

894-
Here we have specific screens such as `SignIn`, `Home` etc. which are only shown depending on the sign in state. But we also have the `Help` screen which can be shown in both cases. This also means that if the signin state changes when the user is in the `Help` screen, they'll stay on the `Help` screen.
895-
896-
This can be a problem, we probably want the user to be taken to the `SignIn` screen or `Home` screen instead of keeping them on the `Help` screen. To make this work, we can use [`navigationKey`](screen.md#navigation-key). When the `navigationKey` changes, React Navigation will remove all the screen.
895+
Here we have specific screens such as `SignIn`, `Home` etc. which are only shown depending on the sign in state. But we also have the `Help` screen which can be shown regardless of the login status. This also means that if the sign in state changes when the user is in the `Help` screen, they'll stay on the `Help` screen.
897896

898-
So our updated code will look like following:
897+
This can be a problem, we probably want the user to be taken to the `SignIn` screen or `Home` screen instead of keeping them on the `Help` screen.
899898

900899
<Tabs groupId="config" queryString="config">
901900
<TabItem value="static" label="Static" default>
902901

902+
To make this work, we can move the `Help` screen to both of the groups instead of keeping it outside. This will ensure that the [`navigationKey`](screen.md#navigation-key) (the name of the group) for the screen changes when the sign in state changes.
903+
904+
So our updated code will look like the following:
905+
903906
```js
904907
const RootStack = createNativeStackNavigator({
905908
groups: {
@@ -908,28 +911,28 @@ const RootStack = createNativeStackNavigator({
908911
screens: {
909912
Home: HomeScreen,
910913
Profile: ProfileScreen,
914+
Help: HelpScreen,
911915
},
912916
},
913917
LoggedOut: {
914918
if: useIsSignedOut,
915919
screens: {
916920
SignIn: SignInScreen,
917921
SignUp: SignUpScreen,
922+
Help: HelpScreen,
918923
},
919924
},
920925
},
921-
screens: {
922-
Help: {
923-
screen: HelpScreen,
924-
navigationKey: isSignedIn ? 'user' : 'guest',
925-
},
926-
},
927926
});
928927
```
929928

930929
</TabItem>
931930
<TabItem value="dynamic" label="Dynamic">
932931

932+
To make this work, we can use [`navigationKey`](screen.md#navigation-key). When the `navigationKey` changes, React Navigation will remove all the screen.
933+
934+
So our updated code will look like the following:
935+
933936
```js
934937
<>
935938
{isSignedIn ? (
@@ -951,45 +954,8 @@ const RootStack = createNativeStackNavigator({
951954
</>
952955
```
953956

954-
</TabItem>
955-
</Tabs>
956-
957957
If you have a bunch of shared screens, you can also use [`navigationKey` with a `Group`](group.md#navigation-key) to remove all of the screens in the group. For example:
958958

959-
<Tabs groupId="config" queryString="config">
960-
<TabItem value="static" label="Static" default>
961-
962-
```js
963-
const RootStack = createNativeStackNavigator({
964-
groups: {
965-
LoggedIn: {
966-
if: useIsSignedIn,
967-
screens: {
968-
Home: HomeScreen,
969-
Profile: ProfileScreen,
970-
},
971-
},
972-
LoggedOut: {
973-
if: useIsSignedOut,
974-
screens: {
975-
SignIn: SignInScreen,
976-
SignUp: SignUpScreen,
977-
},
978-
},
979-
Common: {
980-
navigationKey: isSignedIn ? 'user' : 'guest',
981-
screens: {
982-
Help: HelpScreen,
983-
About: AboutScreen,
984-
},
985-
},
986-
},
987-
});
988-
```
989-
990-
</TabItem>
991-
<TabItem value="dynamic" label="Dynamic">
992-
993959
```js
994960
<>
995961
{isSignedIn ? (

0 commit comments

Comments
 (0)