Not a Plant Fehlermeldung
This commit is contained in:
107
app/_layout.tsx
107
app/_layout.tsx
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Animated, Easing, Image, StyleSheet, Text, View } from 'react-native';
|
||||
import { Animated, AppState, Easing, Image, StyleSheet, Text, View } from 'react-native';
|
||||
import { Redirect, Stack, usePathname } from 'expo-router';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
@@ -53,14 +53,14 @@ const ensureInstallConsistency = async (): Promise<boolean> => {
|
||||
|
||||
import { AnimatedSplashScreen } from '../components/AnimatedSplashScreen';
|
||||
|
||||
function RootLayoutInner() {
|
||||
const { isDarkMode, colorPalette, signOut, session, isInitializing, isLoadingPlants, syncRevenueCatState } = useApp();
|
||||
const colors = useColors(isDarkMode, colorPalette);
|
||||
const pathname = usePathname();
|
||||
const [installCheckDone, setInstallCheckDone] = useState(false);
|
||||
const [splashAnimationComplete, setSplashAnimationComplete] = useState(false);
|
||||
const [revenueCatReady, setRevenueCatReady] = useState(Constants.appOwnership === 'expo');
|
||||
const posthog = usePostHog();
|
||||
function RootLayoutInner() {
|
||||
const { isDarkMode, colorPalette, signOut, session, isInitializing, isLoadingPlants, syncRevenueCatState } = useApp();
|
||||
const colors = useColors(isDarkMode, colorPalette);
|
||||
const pathname = usePathname();
|
||||
const [installCheckDone, setInstallCheckDone] = useState(false);
|
||||
const [splashAnimationComplete, setSplashAnimationComplete] = useState(false);
|
||||
const [revenueCatReady, setRevenueCatReady] = useState(Constants.appOwnership === 'expo');
|
||||
const posthog = usePostHog();
|
||||
|
||||
useEffect(() => {
|
||||
// RevenueCat requires native store access — not available in Expo Go
|
||||
@@ -72,42 +72,42 @@ function RootLayoutInner() {
|
||||
|
||||
Purchases.setLogLevel(LOG_LEVEL.VERBOSE);
|
||||
const iosApiKey = process.env.EXPO_PUBLIC_REVENUECAT_IOS_API_KEY || 'appl_hrSpsuUuVstbHhYIDnOqYxPOnmR';
|
||||
const androidApiKey = process.env.EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY || 'goog_placeholder';
|
||||
if (Platform.OS === 'ios') {
|
||||
Purchases.configure({ apiKey: iosApiKey });
|
||||
} else if (Platform.OS === 'android') {
|
||||
Purchases.configure({ apiKey: androidApiKey });
|
||||
}
|
||||
setRevenueCatReady(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const isExpoGo = Constants.appOwnership === 'expo';
|
||||
if (isExpoGo || !revenueCatReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
if (session?.serverUserId) {
|
||||
await Purchases.logIn(session.serverUserId);
|
||||
const customerInfo = await Purchases.getCustomerInfo();
|
||||
if (!cancelled) {
|
||||
await syncRevenueCatState(customerInfo as any, 'app_init');
|
||||
}
|
||||
} else {
|
||||
await Purchases.logOut();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to align RevenueCat identity', error);
|
||||
}
|
||||
})();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [revenueCatReady, session?.serverUserId, syncRevenueCatState]);
|
||||
const androidApiKey = process.env.EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY || 'goog_placeholder';
|
||||
if (Platform.OS === 'ios') {
|
||||
Purchases.configure({ apiKey: iosApiKey });
|
||||
} else if (Platform.OS === 'android') {
|
||||
Purchases.configure({ apiKey: androidApiKey });
|
||||
}
|
||||
setRevenueCatReady(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const isExpoGo = Constants.appOwnership === 'expo';
|
||||
if (isExpoGo || !revenueCatReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
if (session?.serverUserId) {
|
||||
await Purchases.logIn(session.serverUserId);
|
||||
const customerInfo = await Purchases.getCustomerInfo();
|
||||
if (!cancelled) {
|
||||
await syncRevenueCatState(customerInfo as any, 'app_init');
|
||||
}
|
||||
} else {
|
||||
await Purchases.logOut();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to align RevenueCat identity', error);
|
||||
}
|
||||
})();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [revenueCatReady, session?.serverUserId, syncRevenueCatState]);
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.serverUserId) {
|
||||
@@ -120,6 +120,20 @@ function RootLayoutInner() {
|
||||
}
|
||||
}, [session, posthog]);
|
||||
|
||||
useEffect(() => {
|
||||
posthog.capture('screen_viewed', { screen: pathname });
|
||||
}, [pathname, posthog]);
|
||||
|
||||
useEffect(() => {
|
||||
posthog.capture('app_opened');
|
||||
const subscription = AppState.addEventListener('change', (nextState) => {
|
||||
if (nextState === 'active') {
|
||||
posthog.capture('app_opened');
|
||||
}
|
||||
});
|
||||
return () => subscription.remove();
|
||||
}, [posthog]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const didResetSessionForFreshInstall = await ensureInstallConsistency();
|
||||
@@ -226,7 +240,8 @@ export default function RootLayout() {
|
||||
return (
|
||||
<PostHogProvider apiKey={POSTHOG_API_KEY} options={{
|
||||
host: 'https://us.i.posthog.com',
|
||||
enableSessionReplay: true,
|
||||
enableSessionReplay: false,
|
||||
debug: __DEV__,
|
||||
}}>
|
||||
<AppProvider>
|
||||
<CoachMarksProvider>
|
||||
|
||||
Reference in New Issue
Block a user