LackMolibModal.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { Images } from '@/constants/images';
  2. import { ImageBackground } from 'expo-image';
  3. import { useRouter } from 'expo-router';
  4. import React, { forwardRef, useImperativeHandle, useState } from 'react';
  5. import { Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
  6. export interface LackMolibModalRef {
  7. show: () => void;
  8. close: () => void;
  9. }
  10. export const LackMolibModal = forwardRef<LackMolibModalRef>((_, ref) => {
  11. const [visible, setVisible] = useState(false);
  12. const router = useRouter();
  13. useImperativeHandle(ref, () => ({
  14. show: () => setVisible(true),
  15. close: () => setVisible(false),
  16. }));
  17. const handleSubmit = () => {
  18. setVisible(false);
  19. // Navigate to box homepage
  20. router.push('/box');
  21. }
  22. if (!visible) return null;
  23. return (
  24. <Modal visible={visible} transparent animationType="fade" onRequestClose={() => setVisible(false)}>
  25. <View style={styles.overlay}>
  26. <TouchableOpacity style={styles.mask} activeOpacity={1} onPress={() => setVisible(false)} />
  27. <View style={styles.contentContainer}>
  28. <View style={styles.wrapper}>
  29. <ImageBackground source={{ uri: Images.welfare.welfareDialogMain }} style={styles.main} resizeMode="stretch">
  30. <Text style={styles.imgText}>尊主大人的源力币不够啦, 快去收集源力币吧。</Text>
  31. </ImageBackground>
  32. <TouchableOpacity onPress={handleSubmit}>
  33. <ImageBackground source={{ uri: Images.welfare.welfareDialogSubmit }} style={styles.submitBtn} resizeMode="stretch">
  34. <Text style={styles.btnText}>收集源力币</Text>
  35. </ImageBackground>
  36. </TouchableOpacity>
  37. </View>
  38. </View>
  39. </View>
  40. </Modal>
  41. );
  42. });
  43. const styles = StyleSheet.create({
  44. overlay: {
  45. flex: 1,
  46. backgroundColor: 'rgba(0,0,0,0.6)',
  47. justifyContent: 'center',
  48. alignItems: 'center',
  49. },
  50. mask: {
  51. position: 'absolute',
  52. top: 0,
  53. left: 0,
  54. right: 0,
  55. bottom: 0,
  56. },
  57. contentContainer: {
  58. width: '100%',
  59. alignItems: 'center',
  60. },
  61. wrapper: {
  62. marginTop: 33,
  63. alignItems: 'center',
  64. },
  65. main: {
  66. width: 357, // 714rpx
  67. height: 142, // 284rpx
  68. justifyContent: 'center',
  69. alignItems: 'center',
  70. marginBottom: 17,
  71. paddingHorizontal: 25,
  72. },
  73. imgText: {
  74. fontWeight: 'bold',
  75. fontSize: 20,
  76. color: '#000',
  77. textAlign: 'center',
  78. },
  79. submitBtn: {
  80. width: 179, // 358rpx
  81. height: 57, // 114rpx
  82. justifyContent: 'center',
  83. alignItems: 'center',
  84. paddingTop: 5,
  85. },
  86. btnText: {
  87. fontSize: 17.5, // 35rpx
  88. color: '#fff',
  89. textShadowColor: '#000',
  90. textShadowOffset: { width: 1, height: 1 },
  91. textShadowRadius: 1,
  92. }
  93. });