Modal.rn.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { View, Text, ScrollView } from '@tarojs/components'
  2. import './Modal.scss'
  3. import React, { useState } from 'react';
  4. import { ModalType } from '@/utils/types';
  5. import Box from './Box';
  6. import Taro from '@tarojs/taro';
  7. import {Modal as ModalRN} from 'react-native'
  8. import { vibrate } from '@/utils/tools';
  9. export default function Modal(props: {
  10. children: React.ReactNode,
  11. testInfo?: React.ReactNode,
  12. title?: string,
  13. dismiss: Function,
  14. confirm?: Function,
  15. themeColor?: string,
  16. modalType?: ModalType,
  17. cancelCatchMove?: boolean
  18. }) {
  19. const [isDismiss, setIsDismiss] = useState(false)
  20. //阻止中间内容点击事件穿透
  21. function click(e) {
  22. if (process.env.TARO_ENV == 'weapp') {
  23. e.stopPropagation()
  24. }
  25. vibrate()
  26. }
  27. function onClick() {
  28. }
  29. switch (props.modalType) {
  30. case ModalType.center:
  31. return <ModalRN transparent={true} >
  32. <View onClick={()=>{props.dismiss()}} style={{backgroundColor:'rgba(0,0,0,0.95)',width:'100%',height:'100%',alignItems:'center',justifyContent:'center'}}>
  33. <Box><View onClick={click}>
  34. {
  35. props.children
  36. }
  37. </View>
  38. </Box>
  39. </View>
  40. </ModalRN>
  41. }
  42. function longPress(e) {
  43. if (process.env.TARO_ENV == 'weapp') {
  44. e.stopPropagation()
  45. }
  46. }
  47. function dismiss() {
  48. if (props.modalType == ModalType.center) {
  49. props.dismiss()
  50. return
  51. }
  52. setIsDismiss(true)
  53. setTimeout(() => {
  54. props.dismiss()
  55. }, 250)
  56. }
  57. global.dismissModal = dismiss;
  58. return <ModalRN style={{backgroundColor:'red'}} >
  59. <View style={{ flex: 1, width: 375, flexShrink: 0 }} onClick={(e) => {
  60. dismiss()
  61. }}>
  62. {
  63. props.testInfo ? props.testInfo : null
  64. }
  65. </View>
  66. <View className={isDismiss ? 'modal_bottom_content modal_bottom_dismiss' : 'modal_bottom_content'} style={{ flexShrink: 0 }} onClick={onClick}>
  67. {/* <Text className='modal_title' style={{ color: color }}>{props.title ? props.title : '测试标题 '}</Text> */}
  68. {
  69. props.children
  70. }
  71. </View>
  72. </ModalRN>
  73. }