perf: perf transtion
parent
bd138a8711
commit
a095728a46
|
@ -0,0 +1,21 @@
|
||||||
|
// import animate from './css-animation';
|
||||||
|
const getTransitionGroupProps = (transitionName, opt = {}) => {
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
return { css: false, ...opt };
|
||||||
|
}
|
||||||
|
const transitionProps = {
|
||||||
|
appear: true,
|
||||||
|
appearFromClass: `${transitionName}-appear`,
|
||||||
|
appearActiveClass: `${transitionName}`,
|
||||||
|
appearToClass: `${transitionName}-appear-active`,
|
||||||
|
enterFromClass: `${transitionName}-appear ${transitionName}-enter`,
|
||||||
|
enterActiveClass: `${transitionName}`,
|
||||||
|
enterToClass: `${transitionName}-appear-active ${transitionName}-enter-active`,
|
||||||
|
leaveActiveClass: `${transitionName} ${transitionName}-leave`,
|
||||||
|
leaveToClass: `${transitionName}-leave-active`,
|
||||||
|
...opt,
|
||||||
|
};
|
||||||
|
return transitionProps;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getTransitionGroupProps;
|
|
@ -1,17 +1,18 @@
|
||||||
import animate from './css-animation';
|
|
||||||
const getTransitionProps = (transitionName, opt = {}) => {
|
const getTransitionProps = (transitionName, opt = {}) => {
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test') {
|
||||||
return { css: false, ...opt };
|
return { css: false, ...opt };
|
||||||
}
|
}
|
||||||
const transitionProps = {
|
const transitionProps = {
|
||||||
appear: true,
|
appear: true,
|
||||||
css: false,
|
appearFromClass: `${transitionName}-appear`,
|
||||||
onEnter: (el, done) => {
|
appearActiveClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
||||||
transitionName ? animate(el, `${transitionName}-enter`, done) : done();
|
appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
||||||
},
|
enterFromClass: `${transitionName}-enter`,
|
||||||
onLeave: (el, done) => {
|
enterActiveClass: `${transitionName}-enter ${transitionName}-enter-active`,
|
||||||
transitionName ? animate(el, `${transitionName}-leave`, done) : done();
|
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
|
||||||
},
|
leaveFormClass: ` ${transitionName}-leave`,
|
||||||
|
leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
||||||
|
leaveToClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
||||||
...opt,
|
...opt,
|
||||||
};
|
};
|
||||||
return transitionProps;
|
return transitionProps;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
import classNames from '../../_util/classNames';
|
import classNames from '../../_util/classNames';
|
||||||
import pickAttrs from '../../_util/pickAttrs';
|
import pickAttrs from '../../_util/pickAttrs';
|
||||||
import PropTypes from '../../_util/vue-types';
|
import PropTypes from '../../_util/vue-types';
|
||||||
import getTransitionProps from '../../_util/getTransitionProps';
|
import getTransitionGroupProps from '../../_util/getTransitionGroupProps';
|
||||||
|
|
||||||
const REST_TAG_KEY = '__RC_SELECT_MAX_REST_COUNT__';
|
const REST_TAG_KEY = '__RC_SELECT_MAX_REST_COUNT__';
|
||||||
|
|
||||||
|
@ -158,12 +158,12 @@ const SelectSelector = defineComponent<SelectorProps>({
|
||||||
: maxTagPlaceholder,
|
: maxTagPlaceholder,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const transitionProps = getTransitionProps(choiceTransitionName, {
|
const transitionProps = getTransitionGroupProps(choiceTransitionName, {
|
||||||
appear: motionAppear,
|
appear: motionAppear,
|
||||||
});
|
});
|
||||||
selectionNode.value = (
|
selectionNode.value = (
|
||||||
<TransitionGroup {...transitionProps}>
|
<TransitionGroup {...transitionProps}>
|
||||||
{displayValues.map(
|
{...displayValues.map(
|
||||||
({ key, label, value, disabled: itemDisabled, class: className, style }) => {
|
({ key, label, value, disabled: itemDisabled, class: className, style }) => {
|
||||||
const mergedKey = key || value;
|
const mergedKey = key || value;
|
||||||
const closable = key !== REST_TAG_KEY && !itemDisabled;
|
const closable = key !== REST_TAG_KEY && !itemDisabled;
|
||||||
|
@ -180,7 +180,7 @@ const SelectSelector = defineComponent<SelectorProps>({
|
||||||
<span
|
<span
|
||||||
key={mergedKey as string}
|
key={mergedKey as string}
|
||||||
onMousedown={onMousedown}
|
onMousedown={onMousedown}
|
||||||
class={className}
|
class={classNames(className)}
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
{tagRender({
|
{tagRender({
|
||||||
|
@ -214,7 +214,6 @@ const SelectSelector = defineComponent<SelectorProps>({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
{}
|
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -238,6 +237,7 @@ const SelectSelector = defineComponent<SelectorProps>({
|
||||||
onInputMouseDown,
|
onInputMouseDown,
|
||||||
onInputCompositionStart,
|
onInputCompositionStart,
|
||||||
onInputCompositionEnd,
|
onInputCompositionEnd,
|
||||||
|
choiceTransitionName,
|
||||||
} = props;
|
} = props;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -18,7 +18,7 @@ for (let i = 10; i < 36; i += 1) {
|
||||||
const Test = {
|
const Test = {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
state: {
|
state: {
|
||||||
useAnim: false,
|
useAnim: true,
|
||||||
showArrow: false,
|
showArrow: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
value: ['a10'],
|
value: ['a10'],
|
||||||
|
@ -64,7 +64,6 @@ const Test = {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { useAnim, showArrow, loading, value } = this.state;
|
const { useAnim, showArrow, loading, value } = this.state;
|
||||||
console.log(showArrow);
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>multiple select(scroll the menu)</h2>
|
<h2>multiple select(scroll the menu)</h2>
|
||||||
|
|
|
@ -3,10 +3,10 @@ import PropTypes from '../_util/vue-types';
|
||||||
import Align from '../vc-align';
|
import Align from '../vc-align';
|
||||||
import PopupInner from './PopupInner';
|
import PopupInner from './PopupInner';
|
||||||
import LazyRenderBox from './LazyRenderBox';
|
import LazyRenderBox from './LazyRenderBox';
|
||||||
import animate from '../_util/css-animation';
|
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { saveRef } from './utils';
|
import { saveRef } from './utils';
|
||||||
import { splitAttrs, findDOMNode } from '../_util/props-util';
|
import { splitAttrs, findDOMNode } from '../_util/props-util';
|
||||||
|
import getTransitionProps from '../_util/getTransitionProps';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'VCTriggerPopup',
|
name: 'VCTriggerPopup',
|
||||||
|
@ -37,6 +37,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
this.domEl = null;
|
this.domEl = null;
|
||||||
this.currentAlignClassName = undefined;
|
this.currentAlignClassName = undefined;
|
||||||
|
this.transitionProps = {};
|
||||||
this.savePopupRef = saveRef.bind(this, 'popupInstance');
|
this.savePopupRef = saveRef.bind(this, 'popupInstance');
|
||||||
this.saveAlignRef = saveRef.bind(this, 'alignInstance');
|
this.saveAlignRef = saveRef.bind(this, 'alignInstance');
|
||||||
return {
|
return {
|
||||||
|
@ -73,7 +74,7 @@ export default {
|
||||||
// FIX: https://github.com/react-component/tooltip/issues/79
|
// FIX: https://github.com/react-component/tooltip/issues/79
|
||||||
if (this.currentAlignClassName !== currentAlignClassName) {
|
if (this.currentAlignClassName !== currentAlignClassName) {
|
||||||
this.currentAlignClassName = currentAlignClassName;
|
this.currentAlignClassName = currentAlignClassName;
|
||||||
popupDomNode.className = this.getClassName(currentAlignClassName);
|
popupDomNode.className = this.getClassName(currentAlignClassName, popupDomNode.className);
|
||||||
}
|
}
|
||||||
const { onaAlign } = this.$attrs;
|
const { onaAlign } = this.$attrs;
|
||||||
onaAlign && onaAlign(popupDomNode, align);
|
onaAlign && onaAlign(popupDomNode, align);
|
||||||
|
@ -148,10 +149,19 @@ export default {
|
||||||
return transitionName;
|
return transitionName;
|
||||||
},
|
},
|
||||||
|
|
||||||
getClassName(currentAlignClassName) {
|
getClassName(currentAlignClassName, originClassName = '') {
|
||||||
|
// 保留动画 class
|
||||||
|
const enterActiveClass = [
|
||||||
|
...(this.transitionProps?.enterActiveClass?.split(' ') || []),
|
||||||
|
...(this.transitionProps?.appearActiveClass?.split(' ') || []),
|
||||||
|
];
|
||||||
|
const classNames = originClassName
|
||||||
|
.split(' ')
|
||||||
|
.filter(c => enterActiveClass.indexOf(c) !== -1)
|
||||||
|
.join(' ');
|
||||||
return `${this.$props.prefixCls} ${this.$attrs.class || ''} ${
|
return `${this.$props.prefixCls} ${this.$attrs.class || ''} ${
|
||||||
this.$props.popupClassName
|
this.$props.popupClassName
|
||||||
} ${currentAlignClassName}`;
|
} ${currentAlignClassName} ${classNames}`;
|
||||||
},
|
},
|
||||||
getPopupElement() {
|
getPopupElement() {
|
||||||
const { savePopupRef } = this;
|
const { savePopupRef } = this;
|
||||||
|
@ -209,38 +219,10 @@ export default {
|
||||||
ref: savePopupRef,
|
ref: savePopupRef,
|
||||||
style: { ...sizeStyle, ...popupStyle, ...style, ...this.getZIndexStyle() },
|
style: { ...sizeStyle, ...popupStyle, ...style, ...this.getZIndexStyle() },
|
||||||
};
|
};
|
||||||
let transitionProps = {
|
|
||||||
appear: true,
|
|
||||||
css: false,
|
|
||||||
};
|
|
||||||
const transitionName = getTransitionName();
|
const transitionName = getTransitionName();
|
||||||
let useTransition = !!transitionName;
|
let useTransition = !!transitionName;
|
||||||
const transitionEvent = {
|
let transitionProps = getTransitionProps(transitionName);
|
||||||
onBeforeEnter: () => {
|
|
||||||
// el.style.display = el.__vOriginalDisplay
|
|
||||||
// this.alignInstance.forceAlign();
|
|
||||||
},
|
|
||||||
onEnter: (el, done) => {
|
|
||||||
// render 后 vue 会移除通过animate动态添加的 class导致动画闪动,延迟两帧添加动画class,可以进一步定位或者重写 transition 组件
|
|
||||||
this.$nextTick(() => {
|
|
||||||
if (this.alignInstance) {
|
|
||||||
this.alignInstance.$nextTick(() => {
|
|
||||||
this.domEl = el;
|
|
||||||
animate(el, `${transitionName}-enter`, done);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onBeforeLeave: () => {
|
|
||||||
this.domEl = null;
|
|
||||||
},
|
|
||||||
onLeave: (el, done) => {
|
|
||||||
animate(el, `${transitionName}-leave`, done);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
transitionProps = { ...transitionProps, ...transitionEvent };
|
|
||||||
if (typeof animation === 'object') {
|
if (typeof animation === 'object') {
|
||||||
useTransition = true;
|
useTransition = true;
|
||||||
transitionProps = { ...transitionProps, ...animation };
|
transitionProps = { ...transitionProps, ...animation };
|
||||||
|
@ -248,6 +230,7 @@ export default {
|
||||||
if (!useTransition) {
|
if (!useTransition) {
|
||||||
transitionProps = {};
|
transitionProps = {};
|
||||||
}
|
}
|
||||||
|
this.transitionProps = transitionProps;
|
||||||
if (destroyPopupOnHide) {
|
if (destroyPopupOnHide) {
|
||||||
return (
|
return (
|
||||||
<Transition {...transitionProps}>
|
<Transition {...transitionProps}>
|
||||||
|
|
Loading…
Reference in New Issue