Skip to content

Commit 7067461

Browse files
committed
Remove bottom tabs, use drawer navigator
1 parent 0abaee1 commit 7067461

File tree

38 files changed

+632
-428
lines changed

38 files changed

+632
-428
lines changed

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { GestureHandlerRootView } from "react-native-gesture-handler";
2+
import { Drawer } from "expo-router/drawer";
3+
4+
export default function Layout() {
5+
return (
6+
<GestureHandlerRootView style={{ flex: 1 }}>
7+
<Drawer>
8+
<Drawer.Screen
9+
name="account"
10+
options={{
11+
headerShown: false,
12+
drawerLabel: "Account",
13+
}}
14+
/>
15+
<Drawer.Screen
16+
name="settings"
17+
options={{
18+
headerShown: false,
19+
drawerLabel: "Settings",
20+
}}
21+
/>
22+
</Drawer>
23+
</GestureHandlerRootView>
24+
);
25+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Icon, useTheme, Text } from "@ui-kitten/components";
2+
import { useNavigation, useRouter } from "expo-router";
3+
import { Stack } from "expo-router/stack";
4+
import { TouchableOpacity, View } from "react-native";
5+
import { DrawerActions } from "@react-navigation/native";
6+
import { TouchableWithoutFeedback } from "react-native-gesture-handler";
7+
8+
function MenuIconButton({
9+
name,
10+
onPress,
11+
}: {
12+
name: string;
13+
onPress: () => void;
14+
}) {
15+
const theme = useTheme();
16+
return (
17+
<TouchableOpacity onPress={onPress}>
18+
<Icon
19+
name={name}
20+
fill={theme["color-primary-default"]}
21+
style={{
22+
height: 26,
23+
width: 26,
24+
}}
25+
/>
26+
</TouchableOpacity>
27+
);
28+
}
29+
30+
export default function Layout() {
31+
const navigation = useNavigation();
32+
const router = useRouter();
33+
const theme = useTheme();
34+
35+
return (
36+
<Stack>
37+
<Stack.Screen
38+
name="index"
39+
options={{
40+
headerTitle: () => (
41+
<TouchableWithoutFeedback
42+
onPress={() => {
43+
router.push("/(drawer)/account/account-select");
44+
}}
45+
>
46+
<View
47+
style={{ flexDirection: "row", alignItems: "center", gap: 4 }}
48+
>
49+
<Text category="h6">Testing</Text>
50+
<Icon
51+
name="chevron-down-outline"
52+
fill={theme["text-basic-color"]}
53+
style={{
54+
height: 20,
55+
width: 20,
56+
}}
57+
/>
58+
</View>
59+
</TouchableWithoutFeedback>
60+
),
61+
headerLeft: () => (
62+
<MenuIconButton
63+
name="menu-outline"
64+
onPress={() => {
65+
navigation.dispatch(DrawerActions.openDrawer());
66+
}}
67+
/>
68+
),
69+
headerRight: () => (
70+
<MenuIconButton
71+
name="settings-outline"
72+
onPress={() => {
73+
router.push("/(drawer)/account/account-settings");
74+
}}
75+
/>
76+
),
77+
}}
78+
/>
79+
</Stack>
80+
);
81+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { StatusBar } from "expo-status-bar";
2+
import { StyleSheet } from "react-native";
3+
import { Stack, useRouter } from "expo-router";
4+
import { useFacade } from "@/data/facades";
5+
import { CurrencyUtils } from "@ironfish/sdk";
6+
import {
7+
Layout,
8+
Text,
9+
Button,
10+
Card,
11+
Icon,
12+
IconProps,
13+
} from "@ui-kitten/components";
14+
import { SafeAreaView } from "react-native-safe-area-context";
15+
16+
const PlusIcon = (props: IconProps) => <Icon {...props} name="plus-outline" />;
17+
18+
export default function AccountSelect() {
19+
const router = useRouter();
20+
const facade = useFacade();
21+
22+
const getAccountsResult = facade.getAccounts.useQuery(undefined, {
23+
refetchInterval: 1000,
24+
});
25+
26+
const setActiveAccount = facade.setActiveAccount.useMutation();
27+
28+
return (
29+
<>
30+
<Stack.Screen
31+
options={{
32+
headerTitle: "Select Account",
33+
headerBackTitle: "Back",
34+
}}
35+
/>
36+
<Layout style={styles.container}>
37+
<Layout style={styles.content}>
38+
{getAccountsResult.data?.map((account) => (
39+
<Card
40+
key={account.name}
41+
style={styles.accountCard}
42+
onPress={async () => {
43+
const result = await setActiveAccount.mutateAsync({
44+
name: account.name,
45+
});
46+
console.log(`setActiveAccount: ${result}`);
47+
router.dismissAll();
48+
}}
49+
>
50+
<Layout style={styles.accountInfo}>
51+
<Layout>
52+
<Text category="s1">{account.name}</Text>
53+
<Text category="p2" appearance="hint">
54+
{`${CurrencyUtils.render(account.balances.iron.confirmed)} $IRON`}
55+
</Text>
56+
</Layout>
57+
{account.active && (
58+
<Text status="success" category="c1">
59+
Active
60+
</Text>
61+
)}
62+
</Layout>
63+
</Card>
64+
))}
65+
<Button
66+
style={styles.addButton}
67+
accessoryLeft={PlusIcon}
68+
onPress={() => router.push("/add-account/")}
69+
>
70+
Add Account
71+
</Button>
72+
</Layout>
73+
<StatusBar style="auto" />
74+
</Layout>
75+
</>
76+
);
77+
}
78+
79+
const styles = StyleSheet.create({
80+
container: {
81+
flex: 1,
82+
backgroundColor: "#fff",
83+
},
84+
content: {
85+
flex: 1,
86+
padding: 16,
87+
gap: 16,
88+
},
89+
accountCard: {
90+
marginVertical: 4,
91+
},
92+
accountInfo: {
93+
flexDirection: "row",
94+
justifyContent: "space-between",
95+
alignItems: "center",
96+
},
97+
addButton: {
98+
marginTop: 8,
99+
},
100+
});

packages/mobile-app/app/account-settings/index.tsx renamed to packages/mobile-app/app/(drawer)/account/account-settings/index.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {
88
Toggle,
99
} from "@ui-kitten/components";
1010
import { StyleSheet } from "react-native";
11-
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
12-
import { useFacade } from "../../data/facades";
11+
import { Stack, useRouter } from "expo-router";
12+
import { useFacade } from "@/data/facades";
1313
import { CurrencyUtils } from "@ironfish/sdk";
1414
import { SettingsKey } from "@/data/settings/db";
1515
import { useEffect, useState, useCallback } from "react";
16+
import { useAccount } from "@/providers/AccountProvider";
17+
import { SafeAreaView } from "react-native";
18+
import { Spinner } from "@ui-kitten/components";
1619

1720
const ForwardIcon = (props: any): IconElement => (
1821
<Icon {...props} name="arrow-ios-forward" />
@@ -41,15 +44,6 @@ const ACCOUNT_SETTINGS_ROUTES = {
4144
},
4245
} as const;
4346

44-
export const accountSettingsRoutes = Object.values(ACCOUNT_SETTINGS_ROUTES).map(
45-
(item) => {
46-
return {
47-
title: item.title,
48-
href: item.href,
49-
path: item.href.concat("/index"),
50-
};
51-
},
52-
);
5347
function getMenuItems({
5448
currentAccountName,
5549
currentAccountBalance,
@@ -74,14 +68,8 @@ function getMenuItems({
7468
});
7569
}
7670

77-
export default function AccountSettings() {
78-
const { accountName } = useLocalSearchParams<{ accountName: string }>();
71+
function AccountSettingsContent({ accountName }: { accountName: string }) {
7972
const router = useRouter();
80-
81-
if (accountName === undefined) {
82-
throw new Error("accountName is required");
83-
}
84-
8573
const facade = useFacade();
8674

8775
// I tried using isPending and variables on the mutation, but it was causing toggle
@@ -157,6 +145,26 @@ export default function AccountSettings() {
157145
);
158146
}
159147

148+
export default function AccountSettings() {
149+
const { accountName, isLoading } = useAccount();
150+
151+
if (isLoading) {
152+
return (
153+
<SafeAreaView>
154+
<Layout style={styles.container} level="1">
155+
<Spinner />
156+
</Layout>
157+
</SafeAreaView>
158+
);
159+
}
160+
161+
if (accountName === undefined) {
162+
throw new Error("accountName is required");
163+
}
164+
165+
return <AccountSettingsContent accountName={accountName} />;
166+
}
167+
160168
const styles = StyleSheet.create({
161169
container: {
162170
flex: 1,

packages/mobile-app/app/account-settings/remove-account/index.tsx renamed to packages/mobile-app/app/(drawer)/account/account-settings/remove-account/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StatusBar } from "expo-status-bar";
22
import { Button, Modal, StyleSheet, Text, View } from "react-native";
33
import { useLocalSearchParams, useRouter } from "expo-router";
44
import { useState } from "react";
5-
import { useFacade } from "../../../data/facades";
5+
import { useFacade } from "@/data/facades";
66

77
export default function RemoveAccount() {
88
const router = useRouter();

packages/mobile-app/app/add-account/create.tsx renamed to packages/mobile-app/app/(drawer)/account/add-account/create.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StatusBar } from "expo-status-bar";
22
import { Button, StyleSheet, TextInput, View } from "react-native";
33
import { useRouter } from "expo-router";
44
import { useState } from "react";
5-
import { useFacade } from "../../data/facades";
5+
import { useFacade } from "@/data/facades";
66

77
export default function CreateAccount() {
88
const router = useRouter();

packages/mobile-app/app/add-account/import-encoded.tsx renamed to packages/mobile-app/app/(drawer)/account/add-account/import-encoded.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StatusBar } from "expo-status-bar";
22
import { Button, Modal, StyleSheet, Text, TextInput, View } from "react-native";
33
import { useRouter } from "expo-router";
44
import { useState } from "react";
5-
import { useFacade } from "../../data/facades";
5+
import { useFacade } from "@/data/facades";
66

77
export default function ImportEncoded() {
88
const router = useRouter();

0 commit comments

Comments
 (0)