Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swipe up gesture to homescreen #124

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { hasOnboardedKey, useAppStore } from "~/lib/state/appStore";
import { usePathname } from "expo-router";
import { UserInactivityProvider } from "~/context/UserInactivity";
import { PortalHost } from '@rn-primitives/portal';
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { isBiometricSupported } from "~/lib/isBiometricSupported";

const LIGHT_THEME: Theme = {
Expand Down Expand Up @@ -121,11 +122,13 @@ export default function RootLayout() {
<StatusBar style={isDarkColorScheme ? "light" : "dark"} />
<PolyfillCrypto />
<SafeAreaView className="w-full h-full bg-background">
<UserInactivityProvider>
<Stack />
</UserInactivityProvider>
<Toast config={toastConfig} position="bottom" bottomOffset={140} topOffset={140} />
<PortalHost />
<GestureHandlerRootView>
<UserInactivityProvider>
<Stack />
</UserInactivityProvider>
<Toast config={toastConfig} position="bottom" bottomOffset={140} topOffset={140} />
<PortalHost />
</GestureHandlerRootView>
</SafeAreaView>
</ThemeProvider>
</SWRConfig>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.5",
"react-native-gesture-handler": "~2.16.1",
"react-native-get-random-values": "^1.9.0",
"react-native-qrcode-svg": "^6.3.1",
"react-native-reanimated": "~3.10.1",
Expand Down
146 changes: 83 additions & 63 deletions pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { View, Pressable, StyleSheet, TouchableOpacity } from "react-native";
import React, { useState } from "react";
import React, { useState, useCallback, useEffect } from "react";
import { useBalance } from "hooks/useBalance";
import { useAppStore } from "lib/state/appStore";
import { WalletConnection } from "~/pages/settings/wallets/WalletConnection";
Expand All @@ -22,6 +22,7 @@ import { SvgProps } from "react-native-svg";
import { Button } from "~/components/ui/button";
import Screen from "~/components/Screen";
import { useOnboarding } from "~/hooks/useOnboarding";
import { GestureDetector, Gesture, Directions } from "react-native-gesture-handler";

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -68,77 +69,96 @@ export function Home() {
}
}

const [shouldNavigate, setShouldNavigate] = useState(false);

const handleSwipeUp = useCallback(() => {
setShouldNavigate(true);
}, []);

useEffect(() => {
if (shouldNavigate) {
router.push("/transactions");
setShouldNavigate(false);
}
}, [shouldNavigate]);

const swipeUpGesture = Gesture.Fling()
.direction(Directions.UP)
.onEnd(handleSwipeUp);

return (
<>
<Screen
title=""
right={() =>
<Link href="/settings" asChild>
<TouchableOpacity>
<Settings2 className="text-foreground" />
</TouchableOpacity>
</Link>
}
/>
<View className="h-full flex">
<View className="grow flex flex-col items-center justify-center gap-4">
<TouchableOpacity
onPress={switchBalanceState}
className="w-full flex flex-col items-center justify-center gap-4"
>
<View className="w-full flex flex-row justify-center items-center gap-2">
{balance ? (
<>
<Text className="text-foreground text-5xl font-bold2">
<GestureDetector gesture={swipeUpGesture}>
<View>
<Screen
title=""
right={() =>
<Link href="/settings" asChild>
<TouchableOpacity>
<Settings2 className="text-foreground" />
</TouchableOpacity>
</Link>
}
/>
<View className="h-full flex">
<View className="grow flex flex-col items-center justify-center gap-4">
<TouchableOpacity
onPress={switchBalanceState}
className="w-full flex flex-col items-center justify-center gap-4"
>
<View className="w-full flex flex-row justify-center items-center gap-2">
{balance ? (
<>
<Text className="text-foreground text-5xl font-bold2">
{balanceState == BalanceState.SATS &&
new Intl.NumberFormat().format(
Math.floor(balance.balance / 1000),
)}
{balanceState == BalanceState.FIAT &&
getFiatAmount &&
getFiatAmount(Math.floor(balance.balance / 1000))}
{balanceState == BalanceState.HIDDEN && "****"}
</Text>
<Text className="text-muted-foreground text-3xl font-semibold2">
{balanceState == BalanceState.SATS && "sats"}
</Text>
</>
) : (
<Skeleton className="w-48 h-12" />
)}
</View>
<View className="flex justify-center items-center">
{balance ? (
<Text className="text-center text-3xl text-muted-foreground font-semibold2">
{balanceState == BalanceState.SATS &&
new Intl.NumberFormat().format(
Math.floor(balance.balance / 1000),
)}
{balanceState == BalanceState.FIAT &&
getFiatAmount &&
getFiatAmount(Math.floor(balance.balance / 1000))}
{balanceState == BalanceState.HIDDEN && "****"}
</Text>
<Text className="text-muted-foreground text-3xl font-semibold2">
{balanceState == BalanceState.SATS && "sats"}
{balanceState == BalanceState.FIAT &&
new Intl.NumberFormat().format(
Math.floor(balance.balance / 1000),
) + " sats"}
</Text>
</>
) : (
<Skeleton className="w-48 h-12" />
)}
</View>
<View className="flex justify-center items-center">
{balance ? (
<Text className="text-center text-3xl text-muted-foreground font-semibold2">
{balanceState == BalanceState.SATS &&
getFiatAmount &&
getFiatAmount(Math.floor(balance.balance / 1000))}
{balanceState == BalanceState.FIAT &&
new Intl.NumberFormat().format(
Math.floor(balance.balance / 1000),
) + " sats"}
</Text>
) : (
<Skeleton className="w-32 h-10" />
)}
) : (
<Skeleton className="w-32 h-10" />
)}
</View>
</TouchableOpacity>
</View>
<View className="flex items-center justify-center">
<Link href="/transactions" asChild>
<Button variant="ghost" className="p-10 rounded-full aspect-square">
<ChevronUp className="text-muted-foreground" size={32} />
</Button>
</Link>
</View>
<View>
<View className="flex flex-row gap-6 p-6 pt-2">
<MainButton title="Receive" href="/receive" Icon={LargeArrowDown} />
<MainButton title="Send" href="/send" Icon={LargeArrowUp} />
</View>
</TouchableOpacity>
</View>
<View className="flex items-center justify-center">
<Link href="/transactions" asChild>
<Button variant="ghost" className="p-10 rounded-full aspect-square">
<ChevronUp className="text-muted-foreground" size={32} />
</Button>
</Link>
</View>
<View>
<View className="flex flex-row gap-6 p-6 pt-2">
<MainButton title="Receive" href="/receive" Icon={LargeArrowDown} />
<MainButton title="Send" href="/send" Icon={LargeArrowUp} />
</View>
</View>
</View>
</>
</GestureDetector>
);
}

Expand Down
36 changes: 33 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,13 @@
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@egjs/hammerjs@^2.0.17":
version "2.0.17"
resolved "https://registry.yarnpkg.com/@egjs/hammerjs/-/hammerjs-2.0.17.tgz#5dc02af75a6a06e4c2db0202cae38c9263895124"
integrity sha512-XQsZgjm2EcVUiZQf11UBJQfmZeEmOW8DpI1gsFeln6w0ae0ii4dMQEQ0kjl6DspdWX1aGY1/loyXnP0JS06e/A==
dependencies:
"@types/hammerjs" "^2.0.36"

"@expo/bunyan@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@expo/bunyan/-/bunyan-4.0.0.tgz#be0c1de943c7987a9fbd309ea0b1acd605890c7b"
Expand Down Expand Up @@ -2247,6 +2254,11 @@
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/hammerjs@^2.0.36":
version "2.0.45"
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.45.tgz#ffa764bb68a66c08db6efb9c816eb7be850577b1"
integrity sha512-qkcUlZmX6c4J8q45taBKTL3p+LbITgyx7qhlPYOdOHZB7B31K0mXbP5YA7i7SgDeEGuI9MnumiKPEMrxg8j3KQ==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
Expand Down Expand Up @@ -4463,6 +4475,13 @@ hermes-profile-transformer@^0.0.6:
dependencies:
source-map "^0.7.3"

hoist-non-react-statics@^3.3.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

hosted-git-info@^3.0.2:
version "3.0.8"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-3.0.8.tgz#6e35d4cc87af2c5f816e4cb9ce350ba87a3f370d"
Expand Down Expand Up @@ -5286,7 +5305,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.3.tgz#557ed7d2a9438cac5fd5a43043ca60cb455e01f7"
integrity sha512-H+sg4+uBLOBrw9833P6gCURJjV+puWPbxM8S3H4ORlhVCmQpF5yCE50bc4Exaqm9U5Nhjw83Okq1azyb1U7mxw==

lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.4:
lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.21, lodash@^4.17.4:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -6386,7 +6405,7 @@ prompts@^2.3.2, prompts@^2.4.2:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.8.0:
prop-types@^15.7.2, prop-types@^15.8.0:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -6496,7 +6515,7 @@ react-freeze@^1.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

react-is@^16.13.0, react-is@^16.13.1, react-is@^16.8.4:
react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.4:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand All @@ -6517,6 +6536,17 @@ [email protected]:
babel-plugin-tester "^11.0.4"
lightningcss "1.22.0"

react-native-gesture-handler@~2.16.1:
version "2.16.2"
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz#032bd2a07334292d7f6cff1dc9d1ec928f72e26d"
integrity sha512-vGFlrDKlmyI+BT+FemqVxmvO7nqxU33cgXVsn6IKAFishvlG3oV2Ds67D5nPkHMea8T+s1IcuMm0bF8ntZtAyg==
dependencies:
"@egjs/hammerjs" "^2.0.17"
hoist-non-react-statics "^3.3.0"
invariant "^2.2.4"
lodash "^4.17.21"
prop-types "^15.7.2"

react-native-get-random-values@^1.9.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/react-native-get-random-values/-/react-native-get-random-values-1.11.0.tgz#1ca70d1271f4b08af92958803b89dccbda78728d"
Expand Down
Loading