From b43822562fe8099954f75888fd106a39fcecfe8f Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 1 May 2021 16:40:50 +0800 Subject: [PATCH] feat: add onPopupReopen (#8641) --- src/composables/on-popup-reopen.ts | 19 +++++++++++++++++++ src/popup/Popup.tsx | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 src/composables/on-popup-reopen.ts diff --git a/src/composables/on-popup-reopen.ts b/src/composables/on-popup-reopen.ts new file mode 100644 index 000000000..78e39e883 --- /dev/null +++ b/src/composables/on-popup-reopen.ts @@ -0,0 +1,19 @@ +import { inject, watch } from 'vue'; + +// eslint-disable-next-line +export const POPUP_TOGGLE_KEY = Symbol(); + +export function onPopupReopen(callback: () => void) { + const popupToggleStatus = inject<(() => boolean) | null>( + POPUP_TOGGLE_KEY, + null + ); + + if (popupToggleStatus) { + watch(popupToggleStatus, (show) => { + if (show) { + callback(); + } + }); + } +} diff --git a/src/popup/Popup.tsx b/src/popup/Popup.tsx index 5d2ae6410..71f04928a 100644 --- a/src/popup/Popup.tsx +++ b/src/popup/Popup.tsx @@ -1,6 +1,7 @@ import { ref, watch, + provide, Teleport, computed, PropType, @@ -21,6 +22,7 @@ import { useEventListener } from '@vant/use'; import { useExpose } from '../composables/use-expose'; import { useLockScroll } from '../composables/use-lock-scroll'; import { useLazyRender } from '../composables/use-lazy-render'; +import { POPUP_TOGGLE_KEY } from '../composables/on-popup-reopen'; // Components import { Icon } from '../icon'; @@ -245,6 +247,8 @@ export default defineComponent({ } }); + provide(POPUP_TOGGLE_KEY, () => props.show); + return () => { if (props.teleport) { return (