Skip to content

Commit 4a6cd86

Browse files
authored
feat(example): Add example for MaterialTopTabs auth flow (#943)
1 parent ba7777c commit 4a6cd86

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

example/bun.lockb

1.06 KB
Binary file not shown.

example/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@callstack/react-native-visionos": "^0.76.0",
2020
"@react-native-community/masked-view": "^0.1.10",
21+
"@react-navigation/material-top-tabs": "^6.6.14",
2122
"@react-navigation/native": "^6.0.13",
2223
"@react-navigation/native-stack": "^6.9.1",
2324
"@react-navigation/stack": "^6.3.2",

example/src/App.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Button,
1212
Alert,
1313
I18nManager,
14-
DevSettings
14+
DevSettings,
1515
} from 'react-native';
1616
import { NavigationContainer, useNavigation } from '@react-navigation/native';
1717
import { createStackNavigator } from '@react-navigation/stack';
@@ -31,6 +31,7 @@ import CustomIndicatorExample from './tabView/CustomIndicatorExample';
3131
import CustomTabBarExample from './tabView/CustomTabBarExample';
3232
import CoverflowExample from './tabView/CoverflowExample';
3333
import ReanimatedOnPageScrollExample from './ReanimatedOnPageScrollExample';
34+
import { MaterialTopBarExample } from './MaterialTopTabExample';
3435
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3536
import { SafeAreaProvider } from 'react-native-safe-area-context';
3637
import { PagerHookExample } from './PagerHookExample';
@@ -43,6 +44,7 @@ const examples = [
4344
{ component: OnPageSelectedExample, name: 'OnPageSelected Example' },
4445
{ component: HeadphonesCarouselExample, name: 'Headphones Carousel Example' },
4546
{ component: PaginationDotsExample, name: 'Pagination Dots Example' },
47+
{ component: MaterialTopBarExample, name: 'MaterialTopBarExample' },
4648
{
4749
component: ScrollablePagerViewExample,
4850
name: 'Scrollable PagerView Example',

example/src/MaterialTopTabExample.tsx

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, { useState } from 'react';
2+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
4+
5+
import { View, Text, Button } from 'react-native';
6+
7+
function Tab1() {
8+
return (
9+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
10+
<Text>Tab 1</Text>
11+
</View>
12+
);
13+
}
14+
15+
function Tab2(props: any) {
16+
return (
17+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
18+
<Button title="Logout" onPress={props.onLogout} />
19+
</View>
20+
);
21+
}
22+
23+
const PreAuthScreen = (props: any) => {
24+
return (
25+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
26+
<Button title="Login" onPress={() => props.setIsSignedIn(true)} />
27+
</View>
28+
);
29+
};
30+
31+
const PostAuthScreen = (props: any) => {
32+
const { Navigator, Screen } = createMaterialTopTabNavigator();
33+
const onLogout = () => {
34+
setTimeout(() => {
35+
props.setIsSignedIn(false);
36+
}, 0);
37+
};
38+
39+
return (
40+
<View style={{ flex: 1 }}>
41+
<Navigator>
42+
<Screen name="Tab1" component={Tab1} />
43+
<Screen name="Tab2">
44+
{(props: any) => <Tab2 {...props} onLogout={onLogout} />}
45+
</Screen>
46+
</Navigator>
47+
</View>
48+
);
49+
};
50+
51+
export function MaterialTopBarExample() {
52+
const { Screen, Navigator } = createNativeStackNavigator();
53+
const [isSignedIn, setIsSignedIn] = useState(false);
54+
55+
return (
56+
<Navigator>
57+
{!isSignedIn ? (
58+
<Screen name="Pre Auth Screen">
59+
{(props: any) => (
60+
<PreAuthScreen {...props} setIsSignedIn={setIsSignedIn} />
61+
)}
62+
</Screen>
63+
) : (
64+
<Screen name="Post Auth Screen">
65+
{(props: any) => (
66+
<PostAuthScreen {...props} setIsSignedIn={setIsSignedIn} />
67+
)}
68+
</Screen>
69+
)}
70+
</Navigator>
71+
);
72+
}

0 commit comments

Comments
 (0)