PressSureModal.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { Images } from '@/constants/images';
  2. import { ImageBackground } from 'expo-image';
  3. import React, { forwardRef, useImperativeHandle, useState } from 'react';
  4. import { Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
  5. export interface PressSureModalRef {
  6. show: (type: number) => void;
  7. close: () => void;
  8. }
  9. interface Props {
  10. onPress: (type: number) => void;
  11. }
  12. export const PressSureModal = forwardRef<PressSureModalRef, Props>((props, ref) => {
  13. const [visible, setVisible] = useState(false);
  14. const [pressType, setPressType] = useState(1);
  15. useImperativeHandle(ref, () => ({
  16. show: (type) => {
  17. setPressType(type);
  18. setVisible(true);
  19. },
  20. close: () => setVisible(false),
  21. }));
  22. const handleSubmit = () => {
  23. setVisible(false);
  24. props.onPress(pressType);
  25. }
  26. if (!visible) return null;
  27. return (
  28. <Modal visible={visible} transparent animationType="fade" onRequestClose={() => setVisible(false)}>
  29. <View style={styles.overlay}>
  30. <View style={styles.contentContainer}>
  31. <View style={styles.content}>
  32. <ImageBackground source={{ uri: Images.welfare.welfareDialogBg }} style={styles.textBox} resizeMode="stretch">
  33. <Text style={styles.text}>是否扭{pressType === 1 ? '一' : '五'}次?</Text>
  34. </ImageBackground>
  35. <View style={styles.btns}>
  36. <TouchableOpacity onPress={() => setVisible(false)}>
  37. <ImageBackground source={{ uri: Images.welfare.welfareDialogSubmit }} style={styles.btn} resizeMode="stretch">
  38. <Text style={styles.btnText}>取消</Text>
  39. </ImageBackground>
  40. </TouchableOpacity>
  41. <TouchableOpacity onPress={handleSubmit}>
  42. <ImageBackground source={{ uri: Images.welfare.welfareDialogSubmit }} style={styles.btn} resizeMode="stretch">
  43. <Text style={styles.btnText}>确认</Text>
  44. </ImageBackground>
  45. </TouchableOpacity>
  46. </View>
  47. </View>
  48. </View>
  49. </View>
  50. </Modal>
  51. );
  52. });
  53. const styles = StyleSheet.create({
  54. overlay: {
  55. flex: 1,
  56. backgroundColor: 'rgba(0,0,0,0.6)',
  57. justifyContent: 'center',
  58. alignItems: 'center',
  59. },
  60. contentContainer: {
  61. width: '100%',
  62. paddingHorizontal: 0,
  63. alignItems: 'center',
  64. },
  65. content: {
  66. width: '100%',
  67. paddingHorizontal: 16,
  68. paddingBottom: 30,
  69. },
  70. textBox: {
  71. width: '100%',
  72. height: 136, // 272rpx
  73. justifyContent: 'center',
  74. alignItems: 'center',
  75. },
  76. text: {
  77. fontSize: 24,
  78. fontWeight: 'bold',
  79. color: '#000',
  80. },
  81. btns: {
  82. flexDirection: 'row',
  83. justifyContent: 'space-between',
  84. paddingHorizontal: 11,
  85. marginTop: 20,
  86. },
  87. btn: {
  88. width: 150, // 300rpx
  89. height: 59, // 118rpx
  90. justifyContent: 'center',
  91. alignItems: 'center',
  92. paddingTop: 10,
  93. },
  94. btnText: {
  95. fontSize: 14,
  96. color: '#fff',
  97. fontWeight: 'bold',
  98. textShadowColor: '#000',
  99. textShadowOffset: { width: 1, height: 1 },
  100. textShadowRadius: 1,
  101. }
  102. });