KefuPopup.tsx 2.3 KB

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