welfare.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { Image } from 'expo-image';
  2. import { useRouter } from 'expo-router';
  3. import React, { useCallback, useEffect, useState } from 'react';
  4. import {
  5. Dimensions,
  6. ImageBackground,
  7. ScrollView,
  8. StatusBar,
  9. StyleSheet,
  10. Text,
  11. TouchableOpacity,
  12. View,
  13. } from 'react-native';
  14. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  15. import { Images } from '@/constants/images';
  16. import { getUserInfo, UserInfo } from '@/services/user';
  17. export default function WelfareScreen() {
  18. const router = useRouter();
  19. const insets = useSafeAreaInsets();
  20. const [showSection, setShowSection] = useState(true);
  21. const [user, setUser] = useState<UserInfo | null>(null);
  22. const loadUserInfo = useCallback(async () => {
  23. try {
  24. const info = await getUserInfo();
  25. setUser(info);
  26. } catch (error) {
  27. console.error('获取用户信息失败:', error);
  28. }
  29. }, []);
  30. useEffect(() => {
  31. loadUserInfo();
  32. }, [loadUserInfo]);
  33. const handleRoomPress = (type: number) => {
  34. if (type === 0) {
  35. // 福利房间
  36. router.push('/weal/room' as any);
  37. } else if (type === 1) {
  38. // 扭蛋机
  39. router.push('/weal/catchDoll' as any);
  40. } else {
  41. // 祈愿
  42. router.push('/weal/wish' as any);
  43. }
  44. };
  45. return (
  46. <View style={styles.container}>
  47. <StatusBar barStyle="light-content" />
  48. <ImageBackground
  49. source={{ uri: Images.mine.kaixinMineBg }}
  50. style={styles.background}
  51. resizeMode="cover"
  52. >
  53. {/* 顶部导航 */}
  54. <View style={[styles.header, { paddingTop: insets.top + 50 }]}>
  55. <Text style={styles.title}>福利</Text>
  56. </View>
  57. {/* 标题区域 */}
  58. <ImageBackground
  59. source={{ uri: Images.welfare.wealTitle }}
  60. style={styles.headSection}
  61. resizeMode="cover"
  62. >
  63. <Text style={styles.headTitle}>限时福利活动</Text>
  64. <Text style={styles.headText}>限时活动,不定时开放</Text>
  65. </ImageBackground>
  66. {/* 房间列表 */}
  67. {showSection && (
  68. <ScrollView
  69. style={styles.scrollView}
  70. showsVerticalScrollIndicator={false}
  71. contentContainerStyle={styles.scrollContent}
  72. >
  73. <TouchableOpacity
  74. style={styles.roomItem}
  75. onPress={() => handleRoomPress(0)}
  76. activeOpacity={0.8}
  77. >
  78. <Image
  79. source={{ uri: Images.welfare.indexItem1 }}
  80. style={styles.roomImage}
  81. contentFit="fill"
  82. />
  83. </TouchableOpacity>
  84. <TouchableOpacity
  85. style={styles.roomItem}
  86. onPress={() => handleRoomPress(1)}
  87. activeOpacity={0.8}
  88. >
  89. <Image
  90. source={{ uri: Images.welfare.indexItem2 }}
  91. style={styles.roomImage}
  92. contentFit="fill"
  93. />
  94. </TouchableOpacity>
  95. <TouchableOpacity
  96. style={styles.roomItem}
  97. onPress={() => handleRoomPress(2)}
  98. activeOpacity={0.8}
  99. >
  100. <Image
  101. source={{ uri: Images.welfare.indexItem3 }}
  102. style={styles.roomImage}
  103. contentFit="fill"
  104. />
  105. </TouchableOpacity>
  106. </ScrollView>
  107. )}
  108. {/* 底部占位 */}
  109. <View style={{ height: 120 }} />
  110. </ImageBackground>
  111. </View>
  112. );
  113. }
  114. const { width: SCREEN_WIDTH } = Dimensions.get('window');
  115. const styles = StyleSheet.create({
  116. container: {
  117. flex: 1,
  118. backgroundColor: '#52504e',
  119. },
  120. background: {
  121. flex: 1,
  122. },
  123. header: {
  124. alignItems: 'center',
  125. position: 'absolute',
  126. top: 0,
  127. left: 0,
  128. right: 0,
  129. zIndex: 100,
  130. },
  131. title: {
  132. color: '#fff',
  133. fontSize: 16,
  134. fontWeight: 'bold',
  135. height: 40,
  136. lineHeight: 40,
  137. },
  138. headSection: {
  139. width: '100%',
  140. height: 192,
  141. alignItems: 'center',
  142. paddingTop: 90,
  143. },
  144. headTitle: {
  145. fontWeight: 'bold',
  146. fontSize: 40,
  147. color: '#FDF685',
  148. textShadowColor: '#E85801',
  149. textShadowOffset: { width: 1, height: 2 },
  150. textShadowRadius: 0,
  151. },
  152. headText: {
  153. fontSize: 15,
  154. color: '#E85801',
  155. marginTop: 5,
  156. textShadowColor: '#fff',
  157. textShadowOffset: { width: 1, height: 2 },
  158. textShadowRadius: 1,
  159. },
  160. scrollView: {
  161. flex: 1,
  162. marginTop: 15,
  163. },
  164. scrollContent: {
  165. paddingHorizontal: 0,
  166. alignItems: 'center',
  167. },
  168. roomItem: {
  169. marginBottom: 6,
  170. width: SCREEN_WIDTH - 12, // Minimal margins (6px each side)
  171. alignSelf: 'center',
  172. },
  173. roomImage: {
  174. width: '100%',
  175. height: undefined,
  176. aspectRatio: 3, // Taller (345/115) to reduce horizontal stretch
  177. },
  178. });