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

fix: delay camera #76

Merged
merged 4 commits into from
Sep 3, 2024
Merged
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
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
Loading