Skip to content

Commit 5b36bbe

Browse files
committed
Change Static and Dynamic tabs in Define our screens sections to make more sense
1 parent f7c0198 commit 5b36bbe

File tree

1 file changed

+7
-50
lines changed

1 file changed

+7
-50
lines changed

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

+7-50
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,6 @@ const RootStack = createNativeStackNavigator({
319319
});
320320
```
321321

322-
:::tip
323-
324-
If you have both your login-related screens and rest of the screens in Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
325-
326-
:::
327-
328322
</TabItem>
329323
<TabItem value="dynamic" label="Dynamic">
330324

@@ -334,11 +328,12 @@ if (isLoading) {
334328
return <SplashScreen />;
335329
}
336330

331+
const isSignedIn = userToken != null;
332+
337333
return (
338334
<NavigationContainer>
339335
<Stack.Navigator>
340-
{userToken == null ? (
341-
// No token found, user isn't signed in
336+
{isSignedIn ? (
342337
<Stack.Screen
343338
name="SignIn"
344339
component={SimpleSignInScreen}
@@ -348,17 +343,13 @@ return (
348343
initialParams={{ setUserToken }}
349344
/>
350345
) : (
351-
// User is signed in
352346
<Stack.Screen name="Home" component={HomeScreen} />
353347
)}
354348
</Stack.Navigator>
355349
</NavigationContainer>
356350
);
357351
```
358352

359-
</TabItem>
360-
</Tabs>
361-
362353
In the above snippet, `isLoading` means that we're still checking if we have a token. This can usually be done by checking if we have a token in `SecureStore` and validating the token. After we get the token and if it's valid, we need to set the `userToken`. We also have another state called `isSignout` to have a different animation on sign out.
363354

364355
The main thing to notice is that we're conditionally defining screens based on these state variables:
@@ -368,40 +359,6 @@ The main thing to notice is that we're conditionally defining screens based on t
368359

369360
Here, we're conditionally defining one screen for each case. But you could also define multiple screens. For example, you probably want to define password reset, signup, etc screens as well when the user isn't signed in. Similarly, for the screens accessible after signing in, you probably have more than one screen. We can use `React.Fragment` to define multiple screens:
370361

371-
<Tabs groupId="config" queryString="config">
372-
<TabItem value="static" label="Static" default>
373-
374-
```js
375-
const SignInContext = React.createContext();
376-
377-
function useIsSignedIn() {
378-
const isSignedIn = React.useContext(SignInContext);
379-
return isSignedIn;
380-
}
381-
382-
function useIsSignedOut() {
383-
const isSignedIn = React.useContext(SignInContext);
384-
return !isSignedIn;
385-
}
386-
387-
/* content */
388-
389-
export default function App() {
390-
/* content */
391-
392-
const isSignedIn = userToken != null;
393-
394-
return (
395-
<SignInContext.Provider value={isSignedIn}>
396-
<Navigation />
397-
</SignInContext.Provider>
398-
);
399-
}
400-
```
401-
402-
</TabItem>
403-
<TabItem value="dynamic" label="Dynamic">
404-
405362
```js
406363
state.userToken == null ? (
407364
<>
@@ -417,15 +374,15 @@ state.userToken == null ? (
417374
);
418375
```
419376

377+
</TabItem>
378+
</Tabs>
379+
420380
:::tip
421381

422-
If you have both your login-related screens and rest of the screens in two different Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
382+
If you have both your login-related screens and rest of the screens in Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
423383

424384
:::
425385

426-
</TabItem>
427-
</Tabs>
428-
429386
## Implement the logic for restoring the token
430387

431388
:::note

0 commit comments

Comments
 (0)