|
@@ -3,6 +3,7 @@ import { Image } from 'expo-image';
|
|
|
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
|
import {
|
|
import {
|
|
|
ActivityIndicator,
|
|
ActivityIndicator,
|
|
|
|
|
+ Alert,
|
|
|
Animated,
|
|
Animated,
|
|
|
Dimensions,
|
|
Dimensions,
|
|
|
ImageBackground,
|
|
ImageBackground,
|
|
@@ -141,7 +142,19 @@ export const LotteryResultModal = forwardRef<LotteryResultModalRef, LotteryResul
|
|
|
const [videoVisible, setVideoVisible] = useState(false);
|
|
const [videoVisible, setVideoVisible] = useState(false);
|
|
|
const [videoUrl, setVideoUrl] = useState('');
|
|
const [videoUrl, setVideoUrl] = useState('');
|
|
|
|
|
|
|
|
|
|
+ const videoRef = useRef<Video>(null);
|
|
|
const flipAnims = useRef<Animated.Value[]>([]);
|
|
const flipAnims = useRef<Animated.Value[]>([]);
|
|
|
|
|
+
|
|
|
|
|
+ const startFlow = (data: LotteryItem[]) => {
|
|
|
|
|
+ setVideoVisible(false);
|
|
|
|
|
+ const levelAItem = data.find((item: LotteryItem) => ['A', 'a'].includes(item.level));
|
|
|
|
|
+ if (levelAItem) {
|
|
|
|
|
+ setKingData(levelAItem);
|
|
|
|
|
+ setKingVisible(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setTimeout(() => flipCards(data), 500);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
const dataLoadedRef = useRef(false);
|
|
const dataLoadedRef = useRef(false);
|
|
|
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
useImperativeHandle(ref, () => ({
|
|
@@ -228,40 +241,28 @@ export const LotteryResultModal = forwardRef<LotteryResultModalRef, LotteryResul
|
|
|
if (res.video) {
|
|
if (res.video) {
|
|
|
playVideoUrl = res.video;
|
|
playVideoUrl = res.video;
|
|
|
} else {
|
|
} else {
|
|
|
- // Check if any Level A item exists
|
|
|
|
|
- const hasLevelA = array.some((item: LotteryItem) => item.level === 'A');
|
|
|
|
|
|
|
+ // Check if any Level A item exists (Robust check)
|
|
|
|
|
+ const hasLevelA = array.some((item: LotteryItem) => ['A', 'a'].includes(item.level));
|
|
|
if (hasLevelA) {
|
|
if (hasLevelA) {
|
|
|
playVideoUrl = DEFAULT_JACKPOT_VIDEO;
|
|
playVideoUrl = DEFAULT_JACKPOT_VIDEO;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Check for Level A item for KingModal logic (which happens after video)
|
|
|
|
|
- const levelAItem = array.find((item: LotteryItem) => item.level === 'A');
|
|
|
|
|
-
|
|
|
|
|
- const startFlow = () => {
|
|
|
|
|
- setVideoVisible(false);
|
|
|
|
|
- if (levelAItem) {
|
|
|
|
|
- setKingData(levelAItem);
|
|
|
|
|
- setKingVisible(true);
|
|
|
|
|
- } else {
|
|
|
|
|
- setTimeout(() => flipCards(array), 500);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
if (playVideoUrl) {
|
|
if (playVideoUrl) {
|
|
|
setVideoUrl(playVideoUrl);
|
|
setVideoUrl(playVideoUrl);
|
|
|
setVideoVisible(true);
|
|
setVideoVisible(true);
|
|
|
} else {
|
|
} else {
|
|
|
- startFlow();
|
|
|
|
|
|
|
+ startFlow(array);
|
|
|
}
|
|
}
|
|
|
} else if (attempts < maxAttempts) {
|
|
} else if (attempts < maxAttempts) {
|
|
|
attempts++;
|
|
attempts++;
|
|
|
timeoutId = setTimeout(fetchData, 400);
|
|
timeoutId = setTimeout(fetchData, 400);
|
|
|
} else {
|
|
} else {
|
|
|
setLoading(false);
|
|
setLoading(false);
|
|
|
- window.alert('获取结果超时,请在仓库中查看');
|
|
|
|
|
|
|
+ Alert.alert('提示', '获取结果超时,请在仓库中查看');
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
|
+ console.error(error);
|
|
|
if (attempts < maxAttempts) {
|
|
if (attempts < maxAttempts) {
|
|
|
attempts++;
|
|
attempts++;
|
|
|
timeoutId = setTimeout(fetchData, 400);
|
|
timeoutId = setTimeout(fetchData, 400);
|
|
@@ -294,10 +295,11 @@ export const LotteryResultModal = forwardRef<LotteryResultModalRef, LotteryResul
|
|
|
if (res) {
|
|
if (res) {
|
|
|
setTableData((prev) => prev.map((item) => ({ ...item, magicAmount: 0 })));
|
|
setTableData((prev) => prev.map((item) => ({ ...item, magicAmount: 0 })));
|
|
|
setTotal(0);
|
|
setTotal(0);
|
|
|
- window.alert('兑换成功');
|
|
|
|
|
|
|
+ setTotal(0);
|
|
|
|
|
+ Alert.alert('提示', '兑换成功');
|
|
|
}
|
|
}
|
|
|
} catch {
|
|
} catch {
|
|
|
- window.alert('兑换失败,请重试');
|
|
|
|
|
|
|
+ Alert.alert('提示', '兑换失败,请重试');
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -468,23 +470,27 @@ export const LotteryResultModal = forwardRef<LotteryResultModalRef, LotteryResul
|
|
|
{videoVisible && videoUrl ? (
|
|
{videoVisible && videoUrl ? (
|
|
|
<View style={styles.videoContainer}>
|
|
<View style={styles.videoContainer}>
|
|
|
<Video
|
|
<Video
|
|
|
|
|
+ key={videoUrl}
|
|
|
|
|
+ ref={videoRef}
|
|
|
source={{ uri: videoUrl }}
|
|
source={{ uri: videoUrl }}
|
|
|
style={styles.video}
|
|
style={styles.video}
|
|
|
resizeMode={ResizeMode.COVER}
|
|
resizeMode={ResizeMode.COVER}
|
|
|
shouldPlay
|
|
shouldPlay
|
|
|
isLooping={false}
|
|
isLooping={false}
|
|
|
|
|
+ useNativeControls={false}
|
|
|
|
|
+ onLoad={() => {
|
|
|
|
|
+ videoRef.current?.playAsync();
|
|
|
|
|
+ }}
|
|
|
|
|
+ onError={(error) => {
|
|
|
|
|
+ console.error('Video playback error:', error);
|
|
|
|
|
+ setVideoVisible(false);
|
|
|
|
|
+ startFlow(tableData);
|
|
|
|
|
+ }}
|
|
|
onPlaybackStatusUpdate={(status: AVPlaybackStatus) => {
|
|
onPlaybackStatusUpdate={(status: AVPlaybackStatus) => {
|
|
|
- if (status.isLoaded && status.didJustFinish) {
|
|
|
|
|
- // Video finished
|
|
|
|
|
|
|
+ if (!status.isLoaded) return;
|
|
|
|
|
+ if (status.didJustFinish) {
|
|
|
setVideoVisible(false);
|
|
setVideoVisible(false);
|
|
|
- // Proceed to next step
|
|
|
|
|
- const levelAItem = tableData.find((item: LotteryItem) => item.level === 'A');
|
|
|
|
|
- if (levelAItem) {
|
|
|
|
|
- setKingData(levelAItem);
|
|
|
|
|
- setKingVisible(true);
|
|
|
|
|
- } else {
|
|
|
|
|
- setTimeout(() => flipCards(tableData), 300);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ startFlow(tableData);
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
@@ -492,14 +498,7 @@ export const LotteryResultModal = forwardRef<LotteryResultModalRef, LotteryResul
|
|
|
style={styles.skipVideoBtn}
|
|
style={styles.skipVideoBtn}
|
|
|
onPress={() => {
|
|
onPress={() => {
|
|
|
setVideoVisible(false);
|
|
setVideoVisible(false);
|
|
|
- // Proceed to next step
|
|
|
|
|
- const levelAItem = tableData.find((item: LotteryItem) => item.level === 'A');
|
|
|
|
|
- if (levelAItem) {
|
|
|
|
|
- setKingData(levelAItem);
|
|
|
|
|
- setKingVisible(true);
|
|
|
|
|
- } else {
|
|
|
|
|
- setTimeout(() => flipCards(tableData), 300);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ startFlow(tableData);
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
<Text style={styles.skipText}>跳过</Text>
|
|
<Text style={styles.skipText}>跳过</Text>
|