|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import React, { useEffect, useState, useRef } from 'react'; |
|
|
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; |
|
|
|
|
import { Platform, Modal, View, StyleSheet, Text, TouchableOpacity, Animated, Keyboard } from 'react-native'; |
|
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage'; |
|
|
|
|
import Ionicons from '@expo/vector-icons/Ionicons'; |
|
|
|
|
import { useNavigation, useRoute } from '@react-navigation/native'; |
|
|
|
|
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'; |
|
|
|
@ -38,6 +39,7 @@ export const TabNavigator = () => {
|
|
|
|
|
const { isLoggedIn } = useAuth(); |
|
|
|
|
const [showLoginPrompt, setShowLoginPrompt] = useState(false); |
|
|
|
|
const [keyboardVisible, setKeyboardVisible] = useState(false); |
|
|
|
|
const [promptShownBefore, setPromptShownBefore] = useState(false); |
|
|
|
|
|
|
|
|
|
// 动画值
|
|
|
|
|
const fadeAnim = useRef(new Animated.Value(0)).current; |
|
|
|
@ -64,6 +66,20 @@ export const TabNavigator = () => {
|
|
|
|
|
}; |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
// 检查是否已经显示过弹窗
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const checkPromptShown = async () => { |
|
|
|
|
try { |
|
|
|
|
const value = await AsyncStorage.getItem('loginPromptShown'); |
|
|
|
|
setPromptShownBefore(value === 'true'); |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error('Error checking prompt status:', error); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
checkPromptShown(); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
useEffect(() => { |
|
|
|
|
// 如果是从 CountrySelect 页面来的,不显示登录提示
|
|
|
|
@ -71,8 +87,15 @@ export const TabNavigator = () => {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!isLoggedIn) { |
|
|
|
|
// 如果已登录或已经显示过弹窗,不再显示
|
|
|
|
|
if (isLoggedIn || promptShownBefore) { |
|
|
|
|
handleCloseModal(); |
|
|
|
|
} else { |
|
|
|
|
setShowLoginPrompt(true); |
|
|
|
|
// 标记弹窗已显示
|
|
|
|
|
AsyncStorage.setItem('loginPromptShown', 'true'); |
|
|
|
|
setPromptShownBefore(true); |
|
|
|
|
|
|
|
|
|
Animated.parallel([ |
|
|
|
|
Animated.timing(fadeAnim, { |
|
|
|
|
toValue: 1, |
|
|
|
@ -86,11 +109,8 @@ export const TabNavigator = () => {
|
|
|
|
|
useNativeDriver: true, |
|
|
|
|
}) |
|
|
|
|
]).start(); |
|
|
|
|
} else { |
|
|
|
|
// 如果已登录,关闭弹窗
|
|
|
|
|
handleCloseModal(); |
|
|
|
|
} |
|
|
|
|
}, [isLoggedIn, route.name]); |
|
|
|
|
}, [isLoggedIn, route.name, promptShownBefore]); |
|
|
|
|
|
|
|
|
|
const handleCloseModal = () => { |
|
|
|
|
Animated.parallel([ |
|
|
|
|