DollResultModal.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { Images } from '@/constants/images';
  2. import { ImageBackground } from 'expo-image';
  3. import React, { forwardRef, useImperativeHandle, useState } from 'react';
  4. import { Image, Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
  5. export interface DollResultModalRef {
  6. show: (data: any[]) => void;
  7. close: () => void;
  8. }
  9. export const DollResultModal = forwardRef<DollResultModalRef>((_, ref) => {
  10. const [visible, setVisible] = useState(false);
  11. const [prizeResult, setPrizeResult] = useState<any[]>([]);
  12. useImperativeHandle(ref, () => ({
  13. show: (data) => {
  14. setPrizeResult(data);
  15. setVisible(true);
  16. },
  17. close: () => setVisible(false),
  18. }));
  19. if (!visible) return null;
  20. return (
  21. <Modal visible={visible} transparent animationType="fade" onRequestClose={() => setVisible(false)}>
  22. <View style={styles.overlay}>
  23. <View style={styles.contentContainer}>
  24. <TouchableOpacity onPress={() => setVisible(false)} style={styles.closeBtn}>
  25. <Image source={{ uri: Images.common.closeBut }} style={styles.closeIcon} />
  26. </TouchableOpacity>
  27. <View style={styles.wrapper}>
  28. {prizeResult.length === 1 ? (
  29. <ImageBackground source={{ uri: Images.welfare.resultBg }} style={styles.prizeOneBg} resizeMode="stretch">
  30. <View style={styles.box}>
  31. <Text style={styles.textOne} numberOfLines={1}>{prizeResult[0].name}</Text>
  32. <View style={styles.imgOneBox}>
  33. <Image source={{ uri: prizeResult[0].cover }} style={styles.imgOne} resizeMode="contain" />
  34. </View>
  35. </View>
  36. </ImageBackground>
  37. ) : (
  38. <View style={styles.prizeFiveContainer}>
  39. {prizeResult.map((item, index) => (
  40. <ImageBackground key={item.spuId || index} source={{ uri: Images.welfare.resultBg }} style={[styles.prizeItemBg, (index + 1) % 3 === 0 && styles.noRightMargin]} resizeMode="stretch">
  41. <View style={styles.box}>
  42. <Text style={styles.textFive} numberOfLines={1}>{item.name}</Text>
  43. <View style={styles.imgFiveBox}>
  44. <Image source={{ uri: item.cover }} style={styles.imgFive} resizeMode="contain" />
  45. </View>
  46. </View>
  47. </ImageBackground>
  48. ))}
  49. </View>
  50. )}
  51. </View>
  52. </View>
  53. </View>
  54. </Modal>
  55. );
  56. });
  57. const styles = StyleSheet.create({
  58. overlay: {
  59. flex: 1,
  60. backgroundColor: 'rgba(0,0,0,0.6)',
  61. justifyContent: 'center',
  62. alignItems: 'center',
  63. },
  64. contentContainer: {
  65. width: '100%',
  66. },
  67. closeBtn: {
  68. alignSelf: 'flex-end',
  69. marginRight: 30, // Adjust as needed
  70. marginBottom: 10,
  71. },
  72. closeIcon: {
  73. width: 30,
  74. height: 30,
  75. },
  76. wrapper: {
  77. alignItems: 'center',
  78. width: '100%',
  79. },
  80. prizeOneBg: {
  81. width: 293, // 586rpx
  82. height: 290, // Approx based on padding
  83. paddingTop: 75, // 150rpx
  84. paddingBottom: 94, // 188rpx
  85. alignItems: 'center',
  86. justifyContent: 'center',
  87. },
  88. box: {
  89. height: '100%',
  90. alignItems: 'center',
  91. width: '100%',
  92. },
  93. textOne: {
  94. color: '#444',
  95. fontSize: 15,
  96. fontWeight: 'bold',
  97. textAlign: 'center',
  98. width: '80%',
  99. },
  100. imgOneBox: {
  101. marginTop: 27, // 54rpx
  102. width: 150, // 300rpx
  103. height: 150,
  104. justifyContent: 'center',
  105. alignItems: 'center',
  106. },
  107. imgOne: {
  108. width: '100%',
  109. height: '100%',
  110. },
  111. prizeFiveContainer: {
  112. flexDirection: 'row',
  113. flexWrap: 'wrap',
  114. justifyContent: 'center',
  115. width: '100%',
  116. paddingHorizontal: 20,
  117. },
  118. prizeItemBg: {
  119. width: 102, // 204rpx
  120. height: 130, // 260rpx
  121. marginRight: 9, // 18rpx
  122. marginBottom: 10, // 20rpx
  123. paddingTop: 27, // 54rpx
  124. alignItems: 'center',
  125. },
  126. noRightMargin: {
  127. marginRight: 0,
  128. },
  129. textFive: {
  130. color: '#444',
  131. fontWeight: 'bold',
  132. fontSize: 10,
  133. textAlign: 'center',
  134. width: '90%',
  135. },
  136. imgFiveBox: {
  137. marginTop: -15, // -30rpx
  138. width: 80, // 160rpx
  139. height: 80,
  140. justifyContent: 'center',
  141. alignItems: 'center',
  142. },
  143. imgFive: {
  144. width: '100%',
  145. height: '100%',
  146. }
  147. });