Skip to content

Commit

Permalink
feat: add embedded stack example (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Nov 6, 2024
1 parent 13c307c commit 63fa844
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import LabeledTabs from './Examples/Labeled';
import NativeBottomTabs from './Examples/NativeBottomTabs';
import TintColorsExample from './Examples/TintColors';
import NativeBottomTabsVectorIcons from './Examples/NativeBottomTabsVectorIcons';
import NativeBottomTabsEmbeddedStacks from './Examples/NativeBottomTabsEmbeddedStacks';

const FourTabsIgnoreSafeArea = () => {
return <FourTabs ignoresTopSafeArea />;
Expand Down Expand Up @@ -69,6 +70,11 @@ const examples = [
{ component: FourTabs, name: 'Four Tabs' },
{ component: SFSymbols, name: 'SF Symbols' },
{ component: LabeledTabs, name: 'Labeled Tabs', platform: 'android' },
{
component: NativeBottomTabsEmbeddedStacks,
name: 'Embedded stacks',
screenOptions: { headerShown: false },
},
{
component: FourTabsIgnoreSafeArea,
name: 'Four Tabs - No header',
Expand Down
104 changes: 104 additions & 0 deletions example/src/Examples/NativeBottomTabsEmbeddedStacks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
import createNativeBottomTabNavigator from '../../../src/react-navigation/navigators/createNativeBottomTabNavigator';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

const headerOptions = {
headerShown: true,
headerLargeTitle: true,
};

const Tab = createNativeBottomTabNavigator();

const ArticleStack = createNativeStackNavigator();
const AlbumsStack = createNativeStackNavigator();
const ContactsStack = createNativeStackNavigator();
const ChatStack = createNativeStackNavigator();

function ArticleStackScreen() {
return (
<ArticleStack.Navigator>
<ArticleStack.Screen
options={{ ...headerOptions }}
name="ArticleScreen"
component={Article}
/>
</ArticleStack.Navigator>
);
}

function AlbumsStackScreen() {
return (
<AlbumsStack.Navigator>
<AlbumsStack.Screen
options={{ ...headerOptions }}
name="AlbumsScreen"
component={Albums}
/>
</AlbumsStack.Navigator>
);
}

function ContactsStackScreen() {
return (
<ContactsStack.Navigator>
<ContactsStack.Screen
options={{ ...headerOptions }}
name="ContactsScreen"
component={Contacts}
/>
</ContactsStack.Navigator>
);
}

function ChatStackScreen() {
return (
<ChatStack.Navigator>
<ChatStack.Screen
options={{ ...headerOptions }}
name="ChatScreen"
component={Chat}
/>
</ChatStack.Navigator>
);
}

function NativeBottomTabsEmbeddedStacks() {
return (
<Tab.Navigator ignoresTopSafeArea>
<Tab.Screen
name="Article"
component={ArticleStackScreen}
options={{
tabBarBadge: '10',
tabBarIcon: () => require('../../assets/icons/article_dark.png'),
}}
/>
<Tab.Screen
name="Albums"
component={AlbumsStackScreen}
options={{
tabBarIcon: () => require('../../assets/icons/grid_dark.png'),
}}
/>
<Tab.Screen
name="Contacts"
component={ContactsStackScreen}
options={{
tabBarIcon: () => require('../../assets/icons/person_dark.png'),
}}
/>
<Tab.Screen
name="Chat"
component={ChatStackScreen}
options={{
tabBarIcon: () => require('../../assets/icons/chat_dark.png'),
}}
/>
</Tab.Navigator>
);
}

export default NativeBottomTabsEmbeddedStacks;
7 changes: 7 additions & 0 deletions example/src/Screens/Albums.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useScrollToTop } from '@react-navigation/native';
import React from 'react';
import {
Image,
Platform,
Expand Down Expand Up @@ -41,8 +43,13 @@ export function Albums(props: Partial<ScrollViewProps>) {
console.log(Platform.OS, ' Rendering Albums');
const itemSize = dimensions.width / Math.floor(dimensions.width / 150);

const ref = React.useRef<ScrollView>(null);

useScrollToTop(ref);

return (
<ScrollView
ref={ref}
contentContainerStyle={styles.content}
contentInsetAdjustmentBehavior="automatic"
{...props}
Expand Down
3 changes: 3 additions & 0 deletions example/src/Screens/Article.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useScrollToTop } from '@react-navigation/native';
import * as React from 'react';
import {
Button,
Expand Down Expand Up @@ -47,6 +48,8 @@ export function Article({
}: Props) {
const ref = React.useRef<ScrollView>(null);

useScrollToTop(ref);

console.log(Platform.OS, ' Rendering Article');
return (
<ScrollView
Expand Down
5 changes: 5 additions & 0 deletions example/src/Screens/Contacts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useScrollToTop } from '@react-navigation/native';
import * as React from 'react';
import {
FlatList,
Expand Down Expand Up @@ -96,9 +97,13 @@ export function Contacts({ query, ...rest }: Props) {
console.log(Platform.OS, ' Rendering Contacts');
const renderItem = ({ item }: { item: Item }) => <ContactItem item={item} />;

const ref = React.useRef<FlatList>(null);
useScrollToTop(ref);

return (
<SafeAreaView>
<FlatList
ref={ref}
contentInsetAdjustmentBehavior="automatic"
{...rest}
data={
Expand Down

0 comments on commit 63fa844

Please sign in to comment.