Skip to content

Commit

Permalink
feat: handle header for home stack
Browse files Browse the repository at this point in the history
  • Loading branch information
halv1s committed Dec 1, 2023
1 parent 908cf3c commit 4107dd8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
35 changes: 2 additions & 33 deletions apps/mobile/src/screens/Dashboard/History/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { FC } from 'react';
import type { ViewStyle } from 'react-native';
import { StyleSheet, TouchableOpacity } from 'react-native';
import type { StackScreenProps } from '@react-navigation/stack';
import { FullHistoryFeature, useSafeAreaInsets } from '@walless/app';
import { Text, View } from '@walless/gui';
import { ChevronLeft } from '@walless/icons';
import { View } from '@walless/gui';
import { tabBarHeight } from 'stacks/Dashboard/TabBar';
import { type HomeParamList, navigate } from 'utils/navigation';
import { type HomeParamList } from 'utils/navigation';

type Props = StackScreenProps<HomeParamList, 'History'>;

Expand All @@ -17,40 +15,11 @@ export const HistoryScreen: FC<Props> = () => {
paddingHorizontal: 8,
};

const handleGoBack = () => {
navigate('Dashboard', {
screen: 'Home',
params: {
screen: 'Default',
},
});
};

return (
<View style={containerStyle}>
<View style={styles.header}>
<TouchableOpacity onPress={handleGoBack}>
<ChevronLeft />
</TouchableOpacity>
<Text style={styles.title}>Transaction History</Text>
</View>

<FullHistoryFeature />
</View>
);
};

export default HistoryScreen;

const styles = StyleSheet.create({
header: {
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 14,
gap: 14,
},
title: {
fontSize: 20,
color: '#ffffff',
},
});
2 changes: 1 addition & 1 deletion apps/mobile/src/stacks/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const DashboardStack = () => {
tabBar={(props) => <TabBar tabProps={props} />}
>
<Tab.Screen name="Explore" component={DrawerStack} options={noHeader} />
<Tab.Screen name="Home" component={HomeStack} />
<Tab.Screen name="Home" component={HomeStack} options={noHeader} />
<Tab.Screen name="Setting" component={SettingStack} />
</Tab.Navigator>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/stacks/Drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DrawerStack = () => {
<Header
title={widgetName ?? 'Explore'}
topInset={insets.top}
showMenu={true}
showIcon
toggleDrawer={navigation.toggleDrawer}
/>
);
Expand Down
42 changes: 35 additions & 7 deletions apps/mobile/src/stacks/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
import type { FC } from 'react';
import type { StackScreenProps } from '@react-navigation/stack';
import type {
StackNavigationOptions,
StackScreenProps,
} from '@react-navigation/stack';
import { createStackNavigator } from '@react-navigation/stack';
import HistoryScreen from 'screens/Dashboard/History';
import ProfileScreen from 'screens/Dashboard/Home';
import { useSafeAreaInsets } from 'utils/hooks';
import type { DashboardParamList, HomeParamList } from 'utils/navigation';

import Header from '../components/Header';

type Props = StackScreenProps<DashboardParamList, 'Home'>;

const Stack = createStackNavigator<HomeParamList>();

export const HomeStack: FC<Props> = () => {
const screenOptions = {
headerShown: false,
};
const insets = useSafeAreaInsets();

const getScreenOptions = (
screenName: string,
canGoBack: boolean = false,
): StackNavigationOptions => ({
header({ navigation }) {
return (
<Header
title={screenName}
topInset={insets.top}
showIcon={canGoBack}
goBack={navigation.goBack}
/>
);
},
});

return (
<Stack.Navigator screenOptions={screenOptions}>
<Stack.Screen name="Default" component={ProfileScreen} />
<Stack.Screen name="History" component={HistoryScreen} />
<Stack.Navigator>
<Stack.Screen
name="Default"
component={ProfileScreen}
options={getScreenOptions('Home')}
/>
<Stack.Screen
name="History"
component={HistoryScreen}
options={getScreenOptions('Transaction History', true)}
/>
</Stack.Navigator>
);
};
Expand Down
17 changes: 11 additions & 6 deletions apps/mobile/src/stacks/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import type { FC } from 'react';
import type { ViewStyle } from 'react-native';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Hamburger } from '@walless/icons';
import { ChevronLeft, Hamburger } from '@walless/icons';

interface HeaderProps {
topInset: number;
title: string;
showMenu?: boolean;
showIcon?: boolean;
toggleDrawer?: () => void;
goBack?: () => void;
}

const Header: FC<HeaderProps> = ({
topInset,
title,
showMenu,
showIcon,
toggleDrawer,
goBack,
}) => {
const offsetStyle: ViewStyle = {
paddingTop: topInset,
};

const handlePressIcon = toggleDrawer ? toggleDrawer : goBack;
const Icon = toggleDrawer ? Hamburger : ChevronLeft;

return (
<View style={[offsetStyle, styles.container]}>
<View style={styles.textContainer}>
{showMenu && (
<TouchableOpacity onPress={toggleDrawer}>
<Hamburger size={20} />
{showIcon && (
<TouchableOpacity onPress={handlePressIcon}>
<Icon size={20} />
</TouchableOpacity>
)}
<Text style={styles.text}>{title}</Text>
Expand Down

0 comments on commit 4107dd8

Please sign in to comment.