diff --git a/.changeset/giant-tables-hunt.md b/.changeset/giant-tables-hunt.md new file mode 100644 index 0000000000..097f6d7164 --- /dev/null +++ b/.changeset/giant-tables-hunt.md @@ -0,0 +1,5 @@ +--- +'@td-design/react-native': patch +--- + +feat: 为Modal增加show方法,实现指令式打开弹窗的功能 diff --git a/packages/react-native/src/modal/index.tsx b/packages/react-native/src/modal/index.tsx index 88f17fbf99..cbf8a6a7de 100644 --- a/packages/react-native/src/modal/index.tsx +++ b/packages/react-native/src/modal/index.tsx @@ -2,6 +2,7 @@ import alert from './alert'; import confirm from './confirm'; import Modal from './Modal'; import prompt from './prompt'; +import show from './show'; import tip from './tip'; -export default Object.assign(Modal, { alert, confirm, prompt, tip }); +export default Object.assign(Modal, { alert, confirm, prompt, tip, show }); diff --git a/packages/react-native/src/modal/show/index.tsx b/packages/react-native/src/modal/show/index.tsx new file mode 100644 index 0000000000..66c171f5f7 --- /dev/null +++ b/packages/react-native/src/modal/show/index.tsx @@ -0,0 +1,43 @@ +import React, { PropsWithChildren } from 'react'; + +import { useSafeState } from '@td-design/rn-hooks'; + +import Portal from '../../portal'; +import ModalView from '../Modal/ModalView'; +import { ModalProps } from '../type'; + +export default function show( + comp: React.ReactElement, + props?: Omit +) { + const key = Portal.add( + { + if (!visible) { + Portal.remove(key); + } + }} + > + {comp} + + ); +} + +const ModalContent = ({ children, ...props }: PropsWithChildren>) => { + const [visible, setVisible] = useSafeState(true); + + return ( + setVisible(false)} + > + {children} + + ); +};