perf: trigger animation

pull/2992/head
tangjinzhou 2020-10-10 06:58:19 +08:00
parent dcb71b06b2
commit 22b72855e5
5 changed files with 48 additions and 9 deletions

View File

@ -5,12 +5,12 @@ const getTransitionProps = (transitionName, opt = {}) => {
const transitionProps = { const transitionProps = {
appear: true, appear: true,
appearFromClass: `${transitionName}-appear`, appearFromClass: `${transitionName}-appear`,
appearActiveClass: `${transitionName}-appear ${transitionName}-appear-active`, // appearActiveClass: `antdv-base-transtion`,
appearToClass: `${transitionName}-appear ${transitionName}-appear-active`, appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
enterFromClass: `${transitionName}-enter`, enterFromClass: `${transitionName}-enter`,
enterActiveClass: `${transitionName}-enter ${transitionName}-enter-active`, // enterActiveClass: `antdv-base-transtion`,
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`, enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
leaveFormClass: ` ${transitionName}-leave`, leaveFromClass: ` ${transitionName}-leave`,
leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`, leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`,
leaveToClass: `${transitionName}-leave ${transitionName}-leave-active`, leaveToClass: `${transitionName}-leave ${transitionName}-leave-active`,
...opt, ...opt,

View File

@ -80,7 +80,7 @@ export default {
reAlign = true; reAlign = true;
} }
} }
this.sourceRect = sourceRect; this.sourceRect = { width: sourceRect.width, height: sourceRect.height };
} }
if (reAlign) { if (reAlign) {
@ -99,6 +99,11 @@ export default {
this.stopMonitorWindowResize(); this.stopMonitorWindowResize();
}, },
methods: { methods: {
// TODO
startMonitorElementResize() {
const currentElement = getElement(this.$props.target);
const element = findDOMNode(this);
},
startMonitorWindowResize() { startMonitorWindowResize() {
if (!this.resizeHandler) { if (!this.resizeHandler) {
this.bufferMonitor = buffer(this.forceAlign, this.$props.monitorBufferTime); this.bufferMonitor = buffer(this.forceAlign, this.$props.monitorBufferTime);

View File

@ -50,3 +50,33 @@ export function restoreFocus(activeElement, container) {
activeElement.focus(); activeElement.focus();
} }
} }
export function monitorResize(element, callback) {
let prevWidth = null;
let prevHeight = null;
function onResize([{ target }]) {
if (!document.documentElement.contains(target)) return;
const { width, height } = target.getBoundingClientRect();
const fixedWidth = Math.floor(width);
const fixedHeight = Math.floor(height);
if (prevWidth !== fixedWidth || prevHeight !== fixedHeight) {
// https://webkit.org/blog/9997/resizeobserver-in-webkit/
Promise.resolve().then(() => {
callback({ width: fixedWidth, height: fixedHeight });
});
}
prevWidth = fixedWidth;
prevHeight = fixedHeight;
}
const resizeObserver = new ResizeObserver(onResize);
if (element) {
resizeObserver.observe(element);
}
return () => {
resizeObserver.disconnect();
};
}

View File

@ -65,7 +65,7 @@ const Test = {
render() { render() {
const { useAnim, showArrow, loading, value } = this.state; const { useAnim, showArrow, loading, value } = this.state;
return ( return (
<div> <div style="margin: 20px">
<h2>multiple selectscroll the menu</h2> <h2>multiple selectscroll the menu</h2>
<p> <p>

View File

@ -151,10 +151,14 @@ export default {
getClassName(currentAlignClassName, originClassName = '') { getClassName(currentAlignClassName, originClassName = '') {
// class // class
const enterActiveClass = [ const enterActiveClass = [];
...(this.transitionProps?.enterActiveClass?.split(' ') || []), if (this.transitionProps) {
...(this.transitionProps?.appearActiveClass?.split(' ') || []), Object.keys(this.transitionProps).forEach(k => {
]; if (typeof this.transitionProps[k] === 'string') {
enterActiveClass.push(...this.transitionProps[k].split(' '));
}
});
}
const classNames = originClassName const classNames = originClassName
.split(' ') .split(' ')
.filter(c => enterActiveClass.indexOf(c) !== -1) .filter(c => enterActiveClass.indexOf(c) !== -1)