result.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { Image } from 'expo-image';
  2. import { Stack, useLocalSearchParams, useRouter } from 'expo-router';
  3. import React, { useEffect, useState } from 'react';
  4. import { Dimensions, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
  5. import { Images } from '@/constants/images';
  6. const { width: SCREEN_WIDTH } = Dimensions.get('window');
  7. export default function LotteryResultScreen() {
  8. const router = useRouter();
  9. const params = useLocalSearchParams();
  10. const [results, setResults] = useState<any[]>([]);
  11. useEffect(() => {
  12. if (params.results) {
  13. try {
  14. setResults(JSON.parse(params.results as string));
  15. } catch (e) {
  16. console.error('Failed to parse results', e);
  17. }
  18. }
  19. }, [params.results]);
  20. const handleClose = () => {
  21. // Navigate back to the previous screen (likely detail page)
  22. // Or if we came from award_detail, we might want to go back there
  23. if (router.canGoBack()) {
  24. router.back();
  25. } else {
  26. router.replace('/(tabs)/box');
  27. }
  28. };
  29. const handleAgain = () => {
  30. // Navigation logic to play again if needed, or just close to let user click again
  31. handleClose();
  32. };
  33. return (
  34. <View style={styles.container}>
  35. <Stack.Screen options={{ headerShown: false }} />
  36. <View style={styles.overlay} />
  37. <View style={styles.content}>
  38. <Image
  39. source={{ uri: Images.box.resultBgA }} // Using A as default, logic should depend on rarity
  40. style={styles.resultBg}
  41. contentFit="contain"
  42. />
  43. <View style={styles.resultContainer}>
  44. <Text style={styles.title}>恭喜获得</Text>
  45. <ScrollView contentContainerStyle={styles.scrollContent}>
  46. <View style={styles.grid}>
  47. {results.map((item, index) => (
  48. <View key={index} style={styles.item}>
  49. <Image source={{ uri: item.cover }} style={styles.itemImage} contentFit="contain" />
  50. <Text style={styles.itemName} numberOfLines={1}>{item.name}</Text>
  51. </View>
  52. ))}
  53. </View>
  54. </ScrollView>
  55. <TouchableOpacity style={styles.button} onPress={handleClose}>
  56. <Text style={styles.buttonText}>收下奖品</Text>
  57. </TouchableOpacity>
  58. </View>
  59. </View>
  60. </View>
  61. );
  62. }
  63. const styles = StyleSheet.create({
  64. container: {
  65. flex: 1,
  66. justifyContent: 'center',
  67. alignItems: 'center',
  68. backgroundColor: 'transparent',
  69. },
  70. overlay: {
  71. ...StyleSheet.absoluteFillObject,
  72. backgroundColor: 'rgba(0,0,0,0.7)',
  73. },
  74. content: {
  75. width: SCREEN_WIDTH * 0.9,
  76. height: 500,
  77. alignItems: 'center',
  78. justifyContent: 'center',
  79. },
  80. resultBg: {
  81. position: 'absolute',
  82. width: '100%',
  83. height: '100%',
  84. },
  85. resultContainer: {
  86. width: '100%',
  87. height: '100%',
  88. paddingTop: 100,
  89. paddingHorizontal: 40,
  90. alignItems: 'center',
  91. },
  92. title: {
  93. fontSize: 24,
  94. fontWeight: 'bold',
  95. color: '#fff',
  96. marginBottom: 20,
  97. textShadowColor: 'rgba(0,0,0,0.5)',
  98. textShadowOffset: { width: 1, height: 1 },
  99. textShadowRadius: 2,
  100. },
  101. scrollContent: {
  102. alignItems: 'center',
  103. },
  104. grid: {
  105. flexDirection: 'row',
  106. flexWrap: 'wrap',
  107. justifyContent: 'center',
  108. },
  109. item: {
  110. width: 80,
  111. margin: 5,
  112. alignItems: 'center',
  113. backgroundColor: 'rgba(255,255,255,0.1)',
  114. borderRadius: 8,
  115. padding: 5,
  116. },
  117. itemImage: {
  118. width: 60,
  119. height: 60,
  120. marginBottom: 5,
  121. },
  122. itemName: {
  123. color: '#fff',
  124. fontSize: 10,
  125. textAlign: 'center',
  126. },
  127. button: {
  128. position: 'absolute',
  129. bottom: 30,
  130. backgroundColor: '#F62C71',
  131. paddingHorizontal: 40,
  132. paddingVertical: 10,
  133. borderRadius: 20,
  134. },
  135. buttonText: {
  136. color: '#fff',
  137. fontWeight: 'bold',
  138. },
  139. });