KefuPopup.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { Image } from 'expo-image';
  2. import React, { forwardRef, useImperativeHandle, useState } from 'react';
  3. import {
  4. Modal,
  5. StyleSheet,
  6. Text,
  7. TouchableOpacity,
  8. View,
  9. } from 'react-native';
  10. export interface KefuPopupRef {
  11. open: () => void;
  12. close: () => void;
  13. }
  14. interface KefuPopupProps {
  15. onClose?: () => void;
  16. }
  17. export const KefuPopup = forwardRef<KefuPopupRef, KefuPopupProps>(
  18. ({ onClose }, ref) => {
  19. const [visible, setVisible] = useState(false);
  20. useImperativeHandle(ref, () => ({
  21. open: () => setVisible(true),
  22. close: () => {
  23. setVisible(false);
  24. onClose?.();
  25. },
  26. }));
  27. const handleClose = () => {
  28. setVisible(false);
  29. onClose?.();
  30. };
  31. return (
  32. <Modal
  33. visible={visible}
  34. transparent
  35. animationType="fade"
  36. onRequestClose={handleClose}
  37. >
  38. <View style={styles.overlay}>
  39. <TouchableOpacity
  40. style={styles.backdrop}
  41. activeOpacity={1}
  42. onPress={handleClose}
  43. />
  44. <View style={styles.content}>
  45. <Image
  46. source={{ uri: 'https://cdn.acetoys.cn/kefu/qr.jpg' }}
  47. style={styles.qrImage}
  48. contentFit="contain"
  49. />
  50. <Text style={styles.tipText}>长按识别二维码添加客服</Text>
  51. <TouchableOpacity style={styles.closeBtn} onPress={handleClose}>
  52. <Text style={styles.closeBtnText}>关闭</Text>
  53. </TouchableOpacity>
  54. </View>
  55. </View>
  56. </Modal>
  57. );
  58. }
  59. );
  60. const styles = StyleSheet.create({
  61. overlay: {
  62. flex: 1,
  63. justifyContent: 'center',
  64. alignItems: 'center',
  65. },
  66. backdrop: {
  67. position: 'absolute',
  68. top: 0,
  69. left: 0,
  70. right: 0,
  71. bottom: 0,
  72. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  73. },
  74. content: {
  75. backgroundColor: '#fff',
  76. borderRadius: 15,
  77. padding: 20,
  78. alignItems: 'center',
  79. zIndex: 10,
  80. },
  81. qrImage: {
  82. width: 250,
  83. height: 250,
  84. },
  85. tipText: {
  86. fontSize: 14,
  87. color: '#666',
  88. marginTop: 15,
  89. marginBottom: 20,
  90. },
  91. closeBtn: {
  92. backgroundColor: '#FC7D2E',
  93. paddingHorizontal: 40,
  94. paddingVertical: 12,
  95. borderRadius: 25,
  96. },
  97. closeBtnText: {
  98. color: '#fff',
  99. fontSize: 16,
  100. fontWeight: 'bold',
  101. },
  102. });