WishRuleModal.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Images } from '@/constants/images';
  2. import { Image } from 'expo-image';
  3. import React, { forwardRef, useImperativeHandle, useState } from 'react';
  4. import { ImageBackground, Modal, StyleSheet, TouchableOpacity, View } from 'react-native';
  5. export interface WishRuleModalRef {
  6. show: () => void;
  7. close: () => void;
  8. }
  9. export const WishRuleModal = forwardRef<WishRuleModalRef, {}>((props, ref) => {
  10. const [visible, setVisible] = useState(false);
  11. useImperativeHandle(ref, () => ({
  12. show: () => setVisible(true),
  13. close: () => setVisible(false),
  14. }));
  15. if (!visible) return null;
  16. return (
  17. <Modal visible={visible} transparent animationType="fade" onRequestClose={() => setVisible(false)}>
  18. <View style={styles.overlay}>
  19. <View style={styles.contentContainer}>
  20. <ImageBackground style={styles.content} source={{ uri: Images.welfare.welfareDialogBg }} resizeMode="contain">
  21. <View style={styles.titleBox}>
  22. <Image style={styles.title} source={{ uri: Images.welfare.qijiWelfareDollRule }} resizeMode="contain" />
  23. </View>
  24. <View style={styles.closeBox}>
  25. <TouchableOpacity onPress={() => setVisible(false)}>
  26. <Image style={styles.close} source={{ uri: Images.common.closeBut }} />
  27. </TouchableOpacity>
  28. </View>
  29. <Image source={{ uri: Images.welfare.catchDollRule }} style={styles.ruleImage} contentFit="contain" />
  30. </ImageBackground>
  31. </View>
  32. </View>
  33. </Modal>
  34. );
  35. });
  36. export default WishRuleModal;
  37. const styles = StyleSheet.create({
  38. overlay: {
  39. flex: 1,
  40. backgroundColor: 'rgba(0,0,0,0.7)',
  41. justifyContent: 'center',
  42. alignItems: 'center',
  43. },
  44. contentContainer: {
  45. width: 300,
  46. height: 400,
  47. alignItems: 'center',
  48. justifyContent: 'center',
  49. },
  50. content: {
  51. width: '100%',
  52. height: '100%',
  53. alignItems: 'center',
  54. justifyContent: 'center',
  55. },
  56. titleBox: {
  57. position: 'absolute',
  58. top: -20,
  59. zIndex: 1,
  60. },
  61. title: {
  62. width: 200,
  63. height: 50,
  64. },
  65. closeBox: {
  66. position: 'absolute',
  67. top: 0,
  68. right: -10,
  69. zIndex: 2,
  70. },
  71. close: {
  72. width: 30,
  73. height: 30,
  74. },
  75. ruleImage: {
  76. width: 260,
  77. height: 300,
  78. marginTop: 20,
  79. },
  80. });