Skip to content

Commit 63fa844

Browse files
authored
feat: add embedded stack example (#126)
1 parent 13c307c commit 63fa844

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

example/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import LabeledTabs from './Examples/Labeled';
3131
import NativeBottomTabs from './Examples/NativeBottomTabs';
3232
import TintColorsExample from './Examples/TintColors';
3333
import NativeBottomTabsVectorIcons from './Examples/NativeBottomTabsVectorIcons';
34+
import NativeBottomTabsEmbeddedStacks from './Examples/NativeBottomTabsEmbeddedStacks';
3435

3536
const FourTabsIgnoreSafeArea = () => {
3637
return <FourTabs ignoresTopSafeArea />;
@@ -69,6 +70,11 @@ const examples = [
6970
{ component: FourTabs, name: 'Four Tabs' },
7071
{ component: SFSymbols, name: 'SF Symbols' },
7172
{ component: LabeledTabs, name: 'Labeled Tabs', platform: 'android' },
73+
{
74+
component: NativeBottomTabsEmbeddedStacks,
75+
name: 'Embedded stacks',
76+
screenOptions: { headerShown: false },
77+
},
7278
{
7379
component: FourTabsIgnoreSafeArea,
7480
name: 'Four Tabs - No header',
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { Article } from '../Screens/Article';
2+
import { Albums } from '../Screens/Albums';
3+
import { Contacts } from '../Screens/Contacts';
4+
import { Chat } from '../Screens/Chat';
5+
import createNativeBottomTabNavigator from '../../../src/react-navigation/navigators/createNativeBottomTabNavigator';
6+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
7+
8+
const headerOptions = {
9+
headerShown: true,
10+
headerLargeTitle: true,
11+
};
12+
13+
const Tab = createNativeBottomTabNavigator();
14+
15+
const ArticleStack = createNativeStackNavigator();
16+
const AlbumsStack = createNativeStackNavigator();
17+
const ContactsStack = createNativeStackNavigator();
18+
const ChatStack = createNativeStackNavigator();
19+
20+
function ArticleStackScreen() {
21+
return (
22+
<ArticleStack.Navigator>
23+
<ArticleStack.Screen
24+
options={{ ...headerOptions }}
25+
name="ArticleScreen"
26+
component={Article}
27+
/>
28+
</ArticleStack.Navigator>
29+
);
30+
}
31+
32+
function AlbumsStackScreen() {
33+
return (
34+
<AlbumsStack.Navigator>
35+
<AlbumsStack.Screen
36+
options={{ ...headerOptions }}
37+
name="AlbumsScreen"
38+
component={Albums}
39+
/>
40+
</AlbumsStack.Navigator>
41+
);
42+
}
43+
44+
function ContactsStackScreen() {
45+
return (
46+
<ContactsStack.Navigator>
47+
<ContactsStack.Screen
48+
options={{ ...headerOptions }}
49+
name="ContactsScreen"
50+
component={Contacts}
51+
/>
52+
</ContactsStack.Navigator>
53+
);
54+
}
55+
56+
function ChatStackScreen() {
57+
return (
58+
<ChatStack.Navigator>
59+
<ChatStack.Screen
60+
options={{ ...headerOptions }}
61+
name="ChatScreen"
62+
component={Chat}
63+
/>
64+
</ChatStack.Navigator>
65+
);
66+
}
67+
68+
function NativeBottomTabsEmbeddedStacks() {
69+
return (
70+
<Tab.Navigator ignoresTopSafeArea>
71+
<Tab.Screen
72+
name="Article"
73+
component={ArticleStackScreen}
74+
options={{
75+
tabBarBadge: '10',
76+
tabBarIcon: () => require('../../assets/icons/article_dark.png'),
77+
}}
78+
/>
79+
<Tab.Screen
80+
name="Albums"
81+
component={AlbumsStackScreen}
82+
options={{
83+
tabBarIcon: () => require('../../assets/icons/grid_dark.png'),
84+
}}
85+
/>
86+
<Tab.Screen
87+
name="Contacts"
88+
component={ContactsStackScreen}
89+
options={{
90+
tabBarIcon: () => require('../../assets/icons/person_dark.png'),
91+
}}
92+
/>
93+
<Tab.Screen
94+
name="Chat"
95+
component={ChatStackScreen}
96+
options={{
97+
tabBarIcon: () => require('../../assets/icons/chat_dark.png'),
98+
}}
99+
/>
100+
</Tab.Navigator>
101+
);
102+
}
103+
104+
export default NativeBottomTabsEmbeddedStacks;

example/src/Screens/Albums.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useScrollToTop } from '@react-navigation/native';
2+
import React from 'react';
13
import {
24
Image,
35
Platform,
@@ -41,8 +43,13 @@ export function Albums(props: Partial<ScrollViewProps>) {
4143
console.log(Platform.OS, ' Rendering Albums');
4244
const itemSize = dimensions.width / Math.floor(dimensions.width / 150);
4345

46+
const ref = React.useRef<ScrollView>(null);
47+
48+
useScrollToTop(ref);
49+
4450
return (
4551
<ScrollView
52+
ref={ref}
4653
contentContainerStyle={styles.content}
4754
contentInsetAdjustmentBehavior="automatic"
4855
{...props}

example/src/Screens/Article.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useScrollToTop } from '@react-navigation/native';
12
import * as React from 'react';
23
import {
34
Button,
@@ -47,6 +48,8 @@ export function Article({
4748
}: Props) {
4849
const ref = React.useRef<ScrollView>(null);
4950

51+
useScrollToTop(ref);
52+
5053
console.log(Platform.OS, ' Rendering Article');
5154
return (
5255
<ScrollView

example/src/Screens/Contacts.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useScrollToTop } from '@react-navigation/native';
12
import * as React from 'react';
23
import {
34
FlatList,
@@ -96,9 +97,13 @@ export function Contacts({ query, ...rest }: Props) {
9697
console.log(Platform.OS, ' Rendering Contacts');
9798
const renderItem = ({ item }: { item: Item }) => <ContactItem item={item} />;
9899

100+
const ref = React.useRef<FlatList>(null);
101+
useScrollToTop(ref);
102+
99103
return (
100104
<SafeAreaView>
101105
<FlatList
106+
ref={ref}
102107
contentInsetAdjustmentBehavior="automatic"
103108
{...rest}
104109
data={

0 commit comments

Comments
 (0)