diff --git a/app/screens/ImageSearchResultScreen.tsx b/app/screens/ImageSearchResultScreen.tsx index 4b29892..7b7d20b 100644 --- a/app/screens/ImageSearchResultScreen.tsx +++ b/app/screens/ImageSearchResultScreen.tsx @@ -36,6 +36,8 @@ import widthUtils from "../utils/widthUtils"; import fontSize from "../utils/fontsizeUtils"; import useUserStore from "../store/user"; import { getSubjectTransLanguage } from "../utils/languageUtils"; +import Toast from "react-native-toast-message"; + // 图标组件 - 使用React.memo优化渲染 const IconComponent = React.memo( @@ -475,6 +477,14 @@ export const ImageSearchResultScreen = ({ // 处理点击产品 const handleProductPress = useCallback( (product: Product) => { + + if(product.original_min_price === 0 || product.original_min_price === null){ + Toast.show({ + type: "error", + text1: t("productDiscontinued"), + }); + return; + } navigation.navigate("ProductDetail", { offer_id: product.offer_id, price: product.min_price, diff --git a/app/screens/ProductDetailScreen.tsx b/app/screens/ProductDetailScreen.tsx index 284cff6..214c28f 100644 --- a/app/screens/ProductDetailScreen.tsx +++ b/app/screens/ProductDetailScreen.tsx @@ -279,16 +279,6 @@ export const ProductDetailScreen = () => { route.params.offer_id, userStore.user?.user_id ); - - if (res.original_min_price === 0 || res.original_min_price === null) { - navigation.goBack(); - Toast.show({ - type: "error", - text1: t("productDiscontinued"), - }); - setIsLoading(false); - return; - } if (res.skus != null) { const priceSelectedSku = res.skus.find( (item) => item.offer_price === route.params.price diff --git a/app/screens/SearchResultScreen.tsx b/app/screens/SearchResultScreen.tsx index 893dc88..99c46d5 100644 --- a/app/screens/SearchResultScreen.tsx +++ b/app/screens/SearchResultScreen.tsx @@ -33,6 +33,7 @@ import widthUtils from "../utils/widthUtils"; import fontSize from "../utils/fontsizeUtils"; import useUserStore from "../store/user"; import { getSubjectTransLanguage } from "../utils/languageUtils"; +import Toast from "react-native-toast-message"; // 图标组件 - 使用React.memo优化渲染 const IconComponent = React.memo( ({ name, size, color }: { name: string; size: number; color: string }) => { @@ -450,6 +451,13 @@ export const SearchResultScreen = ({ route, navigation }: SearchResultScreenProp // 处理点击产品 const handleProductPress = useCallback( (product: Product) => { + if (product.original_min_price === 0 || product.original_min_price === null) { + Toast.show({ + type: "error", + text1: t("productDiscontinued"), + }); + return; + } // 导航到产品详情页,并传递产品信息 navigation.navigate("ProductDetail", { offer_id: product.offer_id, diff --git a/app/screens/pay/PayError.tsx b/app/screens/pay/PayError.tsx index 3f4a36e..b894ac4 100644 --- a/app/screens/pay/PayError.tsx +++ b/app/screens/pay/PayError.tsx @@ -6,15 +6,63 @@ import { StyleSheet, ScrollView, Alert, + BackHandler, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; -import { useNavigation } from "@react-navigation/native"; +import { useNavigation, useFocusEffect } from "@react-navigation/native"; import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { RootStackParamList } from "../../navigation/types"; import fontSize from "../../utils/fontsizeUtils"; +type PayErrorStackParamList = { + MainTabs: { screen: string } | undefined; + PayError: undefined; + ConfirmOrder: undefined; + OrderDetails: undefined; +}; + export const PayError = () => { - const navigation = useNavigation>(); + const navigation = useNavigation>(); + + // 处理系统返回,返回到首页 + useFocusEffect( + React.useCallback(() => { + const onBackPress = () => { + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); + return true; // 阻止默认返回行为 + }; + + // 监听硬件返回按钮(Android) + const backHandler = BackHandler; + const subscription = backHandler.addEventListener('hardwareBackPress', onBackPress); + + // 监听导航事件(iOS手势返回和导航栏返回按钮) + const unsubscribe = navigation.addListener('beforeRemove', (e) => { + // 阻止默认行为 + e.preventDefault(); + + // 执行自定义返回逻辑 + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); + }); + + return () => { + subscription?.remove(); + unsubscribe(); + }; + }, [navigation]) + ); const handleRetryPayment = () => { // 导航回支付页面或确认订单页面 diff --git a/app/screens/pay/PaySuccess.tsx b/app/screens/pay/PaySuccess.tsx index fc73032..2014c56 100644 --- a/app/screens/pay/PaySuccess.tsx +++ b/app/screens/pay/PaySuccess.tsx @@ -6,14 +6,24 @@ import { TouchableOpacity, StyleSheet, ScrollView, + BackHandler, } from "react-native"; +import { useNavigation, useFocusEffect } from "@react-navigation/native"; +import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import fontSize from "../../utils/fontsizeUtils"; // import { useRoute, RouteProp } from "@react-navigation/native"; // import { RootStackParamList } from "../../navigation/types"; // import { payApi } from "../../services/api/payApi"; +type RootStackParamList = { + MainTabs: { screen: string } | undefined; + PaymentSuccessScreen: undefined; +}; + export const PaymentSuccessScreen = () => { + const navigation = useNavigation>(); + // const route = useRoute>(); // const { paymentId, PayerID } = route.params; // console.log("paymentId", paymentId); @@ -27,6 +37,46 @@ export const PaymentSuccessScreen = () => { // } // }, [paymentId, PayerID]); + // 处理系统返回,返回到首页 + useFocusEffect( + React.useCallback(() => { + const onBackPress = () => { + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); + return true; // 阻止默认返回行为 + }; + + // 监听硬件返回按钮(Android) + const backHandler = BackHandler; + const subscription = backHandler.addEventListener('hardwareBackPress', onBackPress); + + // 监听导航事件(iOS手势返回和导航栏返回按钮) + const unsubscribe = navigation.addListener('beforeRemove', (e) => { + // 阻止默认行为 + e.preventDefault(); + + // 执行自定义返回逻辑 + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); + }); + + return () => { + subscription?.remove(); + unsubscribe(); + }; + }, [navigation]) + ); + return ( @@ -35,32 +85,32 @@ export const PaymentSuccessScreen = () => { 支付成功 - + {/* 73800FCFA - + */} - + {/* 现代电话 17088752341 - - + */} + {/* 地址 河南省 - + */} 货到仓库后,打电话联系您 - + {/* 查看订单 订单详情 - + */} diff --git a/app/screens/previewOrder/perviewOrder.tsx b/app/screens/previewOrder/perviewOrder.tsx index 99b7fa2..a5745e1 100644 --- a/app/screens/previewOrder/perviewOrder.tsx +++ b/app/screens/previewOrder/perviewOrder.tsx @@ -58,7 +58,7 @@ type RootStackParamList = { Pay: { payUrl: string; method: string; order_id: string }; OrderDetails: { orderId?: number }; PaymentSuccessScreen: any; - MainTabs: undefined; + MainTabs: { screen: string } | undefined; }; export const PreviewOrder = () => { @@ -174,16 +174,23 @@ export const PreviewOrder = () => { useFocusEffect( React.useCallback(() => { const onBackPress = () => { - // 拦截系统返回键事件,导航到OrderDetails页面 - navigation.navigate("OrderDetails", { orderId: 1 }); + // 重置导航栈并返回到首页 + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); return true; // 返回true表示已处理返回事件 }; // 添加返回键监听(Android) BackHandler.addEventListener("hardwareBackPress", onBackPress); - return () => + return () => { BackHandler.removeEventListener("hardwareBackPress", onBackPress); + }; }, [navigation]) ); @@ -329,7 +336,15 @@ export const PreviewOrder = () => { - navigation.goBack()}> + { + navigation.reset({ + index: 0, + routes: [{ + name: 'MainTabs', + params: { screen: 'Home' } + }], + }); + }}>