Skip to content

Commit

Permalink
fix: delay camera (#76)
Browse files Browse the repository at this point in the history
* fix: new index route

* fix: use hook

* fix: remove debugging statements

* fix: remove console log
  • Loading branch information
reneaaron authored Sep 3, 2024
1 parent d342335 commit 9effdb2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
42 changes: 29 additions & 13 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ SplashScreen.preventAutoHideAsync();
export default function RootLayout() {
const { isDarkColorScheme } = useColorScheme();
const [fontsLoaded, setFontsLoaded] = React.useState(false);
const [checkedOnboarding, setCheckedOnboarding] = React.useState(false);
useConnectionChecker();

const rootNavigationState = useRootNavigationState();
const hasNavigationState = !!rootNavigationState?.key;

React.useEffect(() => {
const checkOnboardingStatus = async () => {
const hasOnboarded = await secureStorage.getItem(hasOnboardedKey);
if (!hasOnboarded && hasNavigationState) {
router.replace("/onboarding");
}
};
async function checkOnboardingStatus() {
const hasOnboarded = await secureStorage.getItem(hasOnboardedKey);
if (!hasOnboarded && hasNavigationState) {
router.replace("/onboarding");
}

checkOnboardingStatus();
setCheckedOnboarding(true);
};

async function loadFonts() {

(async () => {
await Font.loadAsync({
OpenRunde: require("./../assets/fonts/OpenRunde-Regular.otf"),
"OpenRunde-Medium": require("./../assets/fonts/OpenRunde-Medium.otf"),
Expand All @@ -71,12 +72,27 @@ export default function RootLayout() {
});

setFontsLoaded(true);
})().finally(() => {
SplashScreen.hideAsync();
});
}

React.useEffect(() => {
const init = async () => {
try {
await Promise.all([
checkOnboardingStatus(),
loadFonts(),
]);
}
finally {

SplashScreen.hideAsync();
}
};

init();

}, [hasNavigationState]);

if (!fontsLoaded) {
if (!fontsLoaded || !checkedOnboarding) {
return null;
}

Expand Down
18 changes: 18 additions & 0 deletions hooks/useOnboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { hasOnboardedKey } from "lib/state/appStore";
import React from "react";
import { useEffect } from "react";
import { secureStorage } from "~/lib/secureStorage";

export function useOnboarding() {
const [onboarded, setOnboarded] = React.useState(false);
useEffect(() => {
async function checkOnboardingStatus() {
const hasOnboarded = await secureStorage.getItem(hasOnboardedKey);
setOnboarded(!!hasOnboarded);
};

checkOnboardingStatus();
});

return onboarded;
}
7 changes: 5 additions & 2 deletions pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import LargeArrowDown from "~/components/icons/LargeArrowDown";
import { SvgProps } from "react-native-svg";
import { Button } from "~/components/ui/button";
import Screen from "~/components/Screen";
import { useOnboarding } from "~/hooks/useOnboarding";

dayjs.extend(relativeTime);

Expand All @@ -40,6 +41,7 @@ export function Home() {
);
const [pressed, setPressed] = React.useState(false);
const rootNavigationState = useRootNavigationState();
const isOnboarded = useOnboarding();

useFocusEffect(() => {
reloadBalance();
Expand All @@ -48,10 +50,11 @@ export function Home() {
let hasNavigationState = !!rootNavigationState?.key;
const hasNwcClient = !!nwcClient;
React.useEffect(() => {
if (hasNavigationState && !hasNwcClient) {
if (hasNavigationState && !hasNwcClient && isOnboarded) {
router.replace(`/settings/wallets/${selectedWalletId}/wallet-connection`);
}
}, [hasNwcClient, hasNavigationState]);
}, [hasNwcClient, hasNavigationState, isOnboarded]);

if (!nwcClient) {
return <WalletConnection />;
}
Expand Down
2 changes: 1 addition & 1 deletion pages/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hasOnboardedKey } from "~/lib/state/appStore";

export function Onboarding() {
async function finish() {
secureStorage.setItem(hasOnboardedKey, "true");
secureStorage.setItem(hasOnboardedKey, "true");
router.replace("/");
}

Expand Down
1 change: 1 addition & 0 deletions pages/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function Settings() {
onPress: () => {
router.dismissAll();
useAppStore.getState().reset();
router.replace("/");
},
},
],
Expand Down

0 comments on commit 9effdb2

Please sign in to comment.