2 Commits d4f863997f ... 5896c88d5e

Tác giả SHA1 Thông báo Ngày
  zbb 5896c88d5e chore: bump version to 1.0.2 build 8 1 tháng trước cách đây
  zbb 326c15b248 fix(safepay): use AppState to reliably trigger callback on iOS 1 tháng trước cách đây
2 tập tin đã thay đổi với 31 bổ sung12 xóa
  1. 2 2
      app.json
  2. 29 10
      app/safepay.tsx

+ 2 - 2
app.json

@@ -2,7 +2,7 @@
   "expo": {
     "name": "asios",
     "slug": "asios",
-    "version": "1.0.1",
+    "version": "1.0.2",
     "orientation": "portrait",
     "icon": "./assets/images/icon.png",
     "scheme": ["asios", "alipay2021005175632205"],
@@ -12,7 +12,7 @@
       "supportsTablet": false,
       "bundleIdentifier": "com.asios",
       "appleTeamId": "Y9ZVX3FRX6",
-      "buildNumber": "7",
+      "buildNumber": "8",
       "infoPlist": {
         "ITSAppUsesNonExemptEncryption": false,
         "NSPhotoLibraryUsageDescription": "App需要访问您的相册以便您可以上传头像或保存商品分享图片。",

+ 29 - 10
app/safepay.tsx

@@ -1,7 +1,13 @@
 import { Colors } from "@/constants/Colors";
 import { useLocalSearchParams, useRouter } from "expo-router";
 import { useEffect } from "react";
-import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
+import {
+    ActivityIndicator,
+    AppState,
+    StyleSheet,
+    Text,
+    View,
+} from "react-native";
 
 /**
  * Alipay Callback Handler
@@ -15,21 +21,34 @@ export default function AlipayResult() {
   useEffect(() => {
     console.log("Alipay callback params:", params);
 
-    // The native SDK (expo-native-alipay) listens for the app verify event
-    // and resolves the Promise in the calling component (Recharge/Checkout).
-    // This route mainly exists to prevent "Unmatched Route" errors.
-    // We simply dismiss it to reveal the underlying screen.
-    const timer = setTimeout(() => {
-      // Use router.dismiss() if available in stack, or back()
+    let hasNavigated = false;
+    let fallbackTimer: ReturnType<typeof setTimeout>;
+
+    const navigateBack = () => {
+      if (hasNavigated) return;
+      hasNavigated = true;
       if (router.canGoBack()) {
         router.back();
       } else {
-        // Fallback if launched directly (unlikely for payment callback)
         router.replace("/");
       }
-    }, 500); // Short delay to allow smooth transition
+    };
+
+    // Listen for AppState changes to know when user actually returns to the app
+    const subscription = AppState.addEventListener("change", (nextAppState) => {
+      if (nextAppState === "active") {
+        // App has returned to foreground. Give a tiny delay for React Native to settle.
+        setTimeout(navigateBack, 500);
+      }
+    });
+
+    // Fallback: if AppState doesn't trigger for some reason, navigate after a max delay (e.g., 2000ms)
+    fallbackTimer = setTimeout(navigateBack, 2000);
 
-    return () => clearTimeout(timer);
+    return () => {
+      subscription.remove();
+      clearTimeout(fallbackTimer);
+    };
   }, []);
 
   return (