safepay.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Colors } from "@/constants/Colors";
  2. import { useLocalSearchParams, useRouter } from "expo-router";
  3. import { useEffect } from "react";
  4. import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
  5. /**
  6. * Alipay Callback Handler
  7. * Handles the "asios://safepay" deep link from Alipay.
  8. * Automatically goes back to invoke the native SDK's callback handling.
  9. */
  10. export default function AlipayResult() {
  11. const router = useRouter();
  12. const params = useLocalSearchParams();
  13. useEffect(() => {
  14. console.log("Alipay callback params:", params);
  15. // In TestFlight/Release builds, performing a router.back() or router.dismiss() here
  16. // forces a React Navigation transition that often unmounts the underlying component
  17. // (CheckoutModal) BEFORE the native `Alipay.pay()` Promise has time to resolve and
  18. // trigger `handleSuccess`.
  19. // Instead of forcing a navigation here, we simply act as a passive sink for the deep link
  20. // to prevent the "Unmatched Route" warning. We trust the original `Alipay.pay()`
  21. // call in CheckoutModal to receive its native completion event and navigate the user
  22. // to the result screen (e.g., /happy-spin) which will naturally replace this route.
  23. // To ensure the user isn't stuck if the payment was cancelled or failed natively,
  24. // we provide a manual close button, or rely on them swiping back.
  25. }, []);
  26. return (
  27. <View style={styles.container}>
  28. <ActivityIndicator size="large" color={Colors.neonBlue || "#00F3FF"} />
  29. <Text style={styles.text}>正在确认支付结果...</Text>
  30. <Text
  31. style={styles.subtext}
  32. onPress={() => {
  33. if (router.canGoBack()) router.back();
  34. else router.replace("/");
  35. }}
  36. >
  37. 如长时间未响应,请点击此处返回
  38. </Text>
  39. </View>
  40. );
  41. }
  42. const styles = StyleSheet.create({
  43. container: {
  44. flex: 1,
  45. justifyContent: "center",
  46. alignItems: "center",
  47. backgroundColor: Colors.darkBg || "#121212",
  48. },
  49. text: {
  50. marginTop: 20,
  51. color: Colors.textSecondary || "#aaa",
  52. fontSize: 16,
  53. fontWeight: "bold",
  54. },
  55. subtext: {
  56. marginTop: 30,
  57. color: Colors.neonPink || "#FF007F",
  58. fontSize: 14,
  59. textDecorationLine: "underline",
  60. padding: 10,
  61. },
  62. });