fix: trigger animate #5008

close #5008
pull/5026/head
tangjinzhou 2021-12-11 14:59:52 +08:00
parent 7d7f0f326c
commit 7bc9c78d51
4 changed files with 28 additions and 11 deletions

View File

@ -26,7 +26,7 @@ export const getTransitionProps = (transitionName: string, opt: TransitionProps
// appearActiveClass: `antdv-base-transtion`, // appearActiveClass: `antdv-base-transtion`,
// appearToClass: `${transitionName}-appear ${transitionName}-appear-active`, // appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare`, enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
// enterActiveClass: `${transitionName}-enter ${transitionName}-enter-active`, enterActiveClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`, enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
leaveFromClass: ` ${transitionName}-leave`, leaveFromClass: ` ${transitionName}-leave`,
leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`, leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`,

View File

@ -39,9 +39,25 @@ export default defineComponent({
measureStretchStyle(props.getRootDomNode()); measureStretchStyle(props.getRootDomNode());
} }
}; };
const visible = ref(false);
let timeoutId: any;
watch(
() => props.visible,
val => {
clearTimeout(timeoutId);
if (val) {
timeoutId = setTimeout(() => {
visible.value = props.visible;
});
} else {
visible.value = false;
}
},
{ immediate: true },
);
// ======================== Status ======================== // ======================== Status ========================
const [status, goNextStatus] = useVisibleStatus(toRef(props, 'visible'), doMeasure); const [status, goNextStatus] = useVisibleStatus(visible, doMeasure);
// ======================== Aligns ======================== // ======================== Aligns ========================
const prepareResolveRef = ref<(value?: unknown) => void>(); const prepareResolveRef = ref<(value?: unknown) => void>();
@ -117,7 +133,6 @@ export default defineComponent({
return () => { return () => {
const { const {
zIndex, zIndex,
visible,
align, align,
prefixCls, prefixCls,
destroyPopupOnHide, destroyPopupOnHide,
@ -131,7 +146,8 @@ export default defineComponent({
const mergedStyle: CSSProperties = { const mergedStyle: CSSProperties = {
...stretchStyle.value, ...stretchStyle.value,
zIndex, zIndex,
opacity: statusValue === 'motion' || statusValue === 'stable' || !visible ? undefined : 0, opacity:
statusValue === 'motion' || statusValue === 'stable' || !visible.value ? undefined : 0,
pointerEvents: statusValue === 'stable' ? undefined : 'none', pointerEvents: statusValue === 'stable' ? undefined : 'none',
...(attrs.style as object), ...(attrs.style as object),
}; };
@ -149,7 +165,8 @@ export default defineComponent({
childNode = <div class={`${prefixCls}-content`}>{childNode}</div>; childNode = <div class={`${prefixCls}-content`}>{childNode}</div>;
} }
const mergedClassName = classNames(prefixCls, attrs.class, alignedClassName.value); const mergedClassName = classNames(prefixCls, attrs.class, alignedClassName.value);
const transitionProps = getTransitionProps(motion.value.name, motion.value); const hasAnimate = visible.value || !props.visible;
const transitionProps = hasAnimate ? getTransitionProps(motion.value.name, motion.value) : {};
return ( return (
<Transition <Transition
ref={elementRef} ref={elementRef}
@ -157,9 +174,9 @@ export default defineComponent({
onBeforeEnter={onShowPrepare} onBeforeEnter={onShowPrepare}
v-slots={{ v-slots={{
default: () => { default: () => {
return !destroyPopupOnHide || visible ? ( return !destroyPopupOnHide || props.visible ? (
<Align <Align
v-show={visible} v-show={visible.value}
target={getAlignTarget()} target={getAlignTarget()}
key="popup" key="popup"
ref={alignRef} ref={alignRef}

View File

@ -1,5 +1,5 @@
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { nextTick, onBeforeUnmount, ref, watch, onMounted } from 'vue'; import { onBeforeUnmount, ref, watch, onMounted } from 'vue';
import type { RafFrame } from '../../_util/raf'; import type { RafFrame } from '../../_util/raf';
import raf from '../../_util/raf'; import raf from '../../_util/raf';
@ -76,7 +76,7 @@ export default (
} }
if (status.value) { if (status.value) {
nextTick(() => { rafRef.value = raf(async () => {
const index = StatusQueue.indexOf(status.value); const index = StatusQueue.indexOf(status.value);
const nextStatus = StatusQueue[index + 1]; const nextStatus = StatusQueue[index + 1];
if (nextStatus && index !== -1) { if (nextStatus && index !== -1) {

View File

@ -62,12 +62,12 @@ export default defineComponent({
}, },
mounted() { mounted() {
this.scrollbarRef.current.addEventListener( this.scrollbarRef.current?.addEventListener(
'touchstart', 'touchstart',
this.onScrollbarTouchStart, this.onScrollbarTouchStart,
supportsPassive ? ({ passive: false } as EventListenerOptions) : false, supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
); );
this.thumbRef.current.addEventListener( this.thumbRef.current?.addEventListener(
'touchstart', 'touchstart',
this.onMouseDown, this.onMouseDown,
supportsPassive ? ({ passive: false } as EventListenerOptions) : false, supportsPassive ? ({ passive: false } as EventListenerOptions) : false,