You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
363
354
364
355
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
368
359
369
360
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:
370
361
371
-
<TabsgroupId="config"queryString="config">
372
-
<TabItemvalue="static"label="Static"default>
373
-
374
-
```js
375
-
constSignInContext=React.createContext();
376
-
377
-
functionuseIsSignedIn() {
378
-
constisSignedIn=React.useContext(SignInContext);
379
-
return isSignedIn;
380
-
}
381
-
382
-
functionuseIsSignedOut() {
383
-
constisSignedIn=React.useContext(SignInContext);
384
-
return!isSignedIn;
385
-
}
386
-
387
-
/* content */
388
-
389
-
exportdefaultfunctionApp() {
390
-
/* content */
391
-
392
-
constisSignedIn= userToken !=null;
393
-
394
-
return (
395
-
<SignInContext.Provider value={isSignedIn}>
396
-
<Navigation />
397
-
</SignInContext.Provider>
398
-
);
399
-
}
400
-
```
401
-
402
-
</TabItem>
403
-
<TabItemvalue="dynamic"label="Dynamic">
404
-
405
362
```js
406
363
state.userToken==null? (
407
364
<>
@@ -417,15 +374,15 @@ state.userToken == null ? (
417
374
);
418
375
```
419
376
377
+
</TabItem>
378
+
</Tabs>
379
+
420
380
:::tip
421
381
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.
0 commit comments