Skip to content

Commit

Permalink
improvements to headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ameer2468 committed Apr 27, 2024
1 parent 6f5f537 commit 9e831e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript/src/types';
import { RouteProp, useNavigation } from '@react-navigation/native';
import { NativeStackHeaderProps } from '@react-navigation/native-stack';
import { ArrowLeft, DotsThreeOutline, MagnifyingGlass } from 'phosphor-react-native';
import { Platform, Pressable, Text, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
Expand All @@ -9,13 +10,15 @@ import { Icon } from '../icons/Icon';


type Props = {
route: RouteProp<any, any>;
kind: 'tag' | 'location';
explorerMenu?: boolean;
headerRoute?: NativeStackHeaderProps; //supporting title from the options object of navigation
optionsRoute?: RouteProp<any, any>; //supporting params passed
kind: 'tag' | 'location'; //the kind of icon to display
explorerMenu?: boolean; //whether to show the explorer menu
};

export default function ParamsHeader({
route,
export default function DynamicHeader({
headerRoute,
optionsRoute,
kind,
explorerMenu = true
}: Props) {
Expand All @@ -40,12 +43,12 @@ export default function ParamsHeader({
<ArrowLeft size={23} color={tw.color('ink')} />
</Pressable>
<View style={tw`flex-row items-center gap-1.5`}>
<HeaderIconKind routeParams={route.params} kind={kind} />
<HeaderIconKind routeParams={optionsRoute?.params} kind={kind} />
<Text
numberOfLines={1}
style={tw`max-w-[200px] text-xl font-bold text-white`}
>
{route.params?.name}
{headerRoute?.options.title}
</Text>
</View>
</View>
Expand Down
1 change: 0 additions & 1 deletion apps/mobile/src/components/header/SearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Props = {
title?: string; // in some cases - we want to override the route title
};

// Default header with search bar and button to open drawer
export default function SearchHeader({
route,
kind,
Expand Down
10 changes: 5 additions & 5 deletions apps/mobile/src/navigation/tabs/BrowseStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LocationsScreen from '~/screens/browse/Locations';
import TagScreen from '~/screens/browse/Tag';
import TagsScreen from '~/screens/browse/Tags';

import ParamsHeader from '~/components/header/ParamsHeader';
import DynamicHeader from '~/components/header/DynamicHeader';
import SearchHeader from '~/components/header/SearchHeader';
import { TabScreenProps } from '../TabNavigator';

Expand All @@ -27,8 +27,8 @@ export default function BrowseStack() {
<Stack.Screen
name="Location"
component={LocationScreen}
options={({route}) => ({
header: () => <ParamsHeader route={route} kind="location" />
options={({route: optionsRoute}) => ({
header: (route) => <DynamicHeader optionsRoute={optionsRoute} headerRoute={route} kind="location" />
})}
/>
<Stack.Screen
Expand All @@ -48,8 +48,8 @@ export default function BrowseStack() {
<Stack.Screen
name="Tag"
component={TagScreen}
options={({route}) => ({
header: () => <ParamsHeader route={route} kind="tag" />
options={({route: optionsRoute}) => ({
header: (route) => <DynamicHeader optionsRoute={optionsRoute} headerRoute={route} kind="tag" />
})}
/>
<Stack.Screen
Expand Down

0 comments on commit 9e831e1

Please sign in to comment.