2019-01-12 03:33:27 +00:00
|
|
|
import cssAnimation from './css-animation';
|
2020-06-09 10:29:34 +00:00
|
|
|
import { nextTick } from 'vue';
|
2021-11-02 08:07:35 +00:00
|
|
|
import { requestAnimationTimeout, cancelAnimationTimeout } from './requestAnimationTimeout';
|
2017-12-07 10:33:33 +00:00
|
|
|
|
2020-10-02 07:44:10 +00:00
|
|
|
function animate(node, show, done) {
|
|
|
|
let height;
|
|
|
|
let requestAnimationFrameId;
|
|
|
|
let appearRequestAnimationFrameId;
|
2020-03-07 11:45:13 +00:00
|
|
|
return cssAnimation(node, 'ant-motion-collapse-legacy', {
|
2019-01-12 03:33:27 +00:00
|
|
|
start() {
|
2018-12-19 04:22:55 +00:00
|
|
|
if (appearRequestAnimationFrameId) {
|
2021-11-02 08:07:35 +00:00
|
|
|
cancelAnimationTimeout(appearRequestAnimationFrameId);
|
2018-12-19 04:22:55 +00:00
|
|
|
}
|
2017-12-07 10:33:33 +00:00
|
|
|
if (!show) {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = `${node.offsetHeight}px`;
|
|
|
|
node.style.opacity = '1';
|
2017-12-07 10:33:33 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
height = node.offsetHeight;
|
2018-12-19 04:22:55 +00:00
|
|
|
// not get offsetHeight when appear
|
|
|
|
// set it into raf get correct offsetHeight
|
2018-12-25 14:17:45 +00:00
|
|
|
if (height === 0) {
|
2021-11-02 08:07:35 +00:00
|
|
|
appearRequestAnimationFrameId = requestAnimationTimeout(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
height = node.offsetHeight;
|
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
|
|
|
});
|
2018-12-19 04:22:55 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
2018-12-19 04:22:55 +00:00
|
|
|
}
|
2017-12-07 10:33:33 +00:00
|
|
|
}
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
active() {
|
2017-12-07 10:33:33 +00:00
|
|
|
if (requestAnimationFrameId) {
|
2021-11-02 08:07:35 +00:00
|
|
|
cancelAnimationTimeout(requestAnimationFrameId);
|
2017-12-07 10:33:33 +00:00
|
|
|
}
|
2021-11-02 08:07:35 +00:00
|
|
|
requestAnimationFrameId = requestAnimationTimeout(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = `${show ? height : 0}px`;
|
|
|
|
node.style.opacity = show ? '1' : '0';
|
|
|
|
});
|
2017-12-07 10:33:33 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
end() {
|
2018-12-19 04:22:55 +00:00
|
|
|
if (appearRequestAnimationFrameId) {
|
2021-11-02 08:07:35 +00:00
|
|
|
cancelAnimationTimeout(appearRequestAnimationFrameId);
|
2018-12-19 04:22:55 +00:00
|
|
|
}
|
2017-12-07 10:33:33 +00:00
|
|
|
if (requestAnimationFrameId) {
|
2021-11-02 08:07:35 +00:00
|
|
|
cancelAnimationTimeout(requestAnimationFrameId);
|
2017-12-07 10:33:33 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = '';
|
|
|
|
node.style.opacity = '';
|
|
|
|
done && done();
|
2017-12-07 10:33:33 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2017-12-07 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const animation = {
|
2020-10-02 07:44:10 +00:00
|
|
|
onEnter(node, done) {
|
2020-06-09 10:29:34 +00:00
|
|
|
nextTick(() => {
|
2019-10-30 08:34:41 +00:00
|
|
|
animate(node, true, done);
|
|
|
|
});
|
2017-12-07 10:33:33 +00:00
|
|
|
},
|
2020-10-02 07:44:10 +00:00
|
|
|
onLeave(node, done) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return animate(node, false, done);
|
2017-12-07 10:33:33 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2017-12-07 10:33:33 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default animation;
|