Skip to content

Commit ddd480f

Browse files
tangjinzhouzhoudewei2526
authored andcommitted
perf: trigger animation
1 parent 036043c commit ddd480f

File tree

5 files changed

+35
-26
lines changed

5 files changed

+35
-26
lines changed

components/_util/ContainerRender.jsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,22 @@ export default {
4242
renderComponent(props = {}, ready) {
4343
const { visible, forceRender, getContainer, parent } = this;
4444
const self = this;
45-
if (visible || parent.$refs._component || forceRender) {
45+
if (visible || parent._component || parent.$refs._component || forceRender) {
4646
let el = this.componentEl;
4747
if (!this.container) {
4848
this.container = getContainer();
4949
el = document.createElement('div');
5050
this.componentEl = el;
5151
this.container.appendChild(el);
5252
}
53+
// self.getComponent 不要放在 render 中,会因为响应式数据问题导致,多次触发 render
54+
const com = { component: self.getComponent(props) };
5355
if (!this._component) {
5456
this._component = new this.$root.constructor({
5557
el,
5658
parent: self,
5759
data: {
58-
comProps: props,
60+
_com: com,
5961
},
6062
mounted() {
6163
this.$nextTick(() => {
@@ -72,17 +74,16 @@ export default {
7274
});
7375
},
7476
methods: {
75-
forceRender(p) {
76-
this.comProps = p;
77-
this.$forceUpdate();
77+
setComponent(_com) {
78+
this.$data._com = _com;
7879
},
7980
},
8081
render() {
81-
return self.getComponent(this.comProps);
82+
return this.$data._com.component;
8283
},
8384
});
8485
} else {
85-
this._component.forceRender(props);
86+
this._component.setComponent(com);
8687
}
8788
}
8889
},

components/vc-select/DropdownMenu.jsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export default {
3232
visible(val) {
3333
if (!val) {
3434
this.lastVisible = val;
35+
} else {
36+
this.$nextTick(() => {
37+
this.scrollActiveItemToView();
38+
});
3539
}
3640
},
3741
},
@@ -50,11 +54,11 @@ export default {
5054
},
5155
updated() {
5256
const props = this.$props;
53-
if (!this.prevVisible && props.visible) {
54-
this.$nextTick(() => {
55-
this.scrollActiveItemToView();
56-
});
57-
}
57+
// if (!this.prevVisible && props.visible) {
58+
// this.$nextTick(() => {
59+
// this.scrollActiveItemToView();
60+
// });
61+
// }
5862
this.lastVisible = props.visible;
5963
this.lastInputValue = props.inputValue;
6064
this.prevVisible = this.visible;

components/vc-tree-select/src/Select.jsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,10 @@ const Select = {
828828
// When set open success and single mode,
829829
// we will reset the input content.
830830
if (open && !multiple && !treeCheckable && _searchValue) {
831-
// 动画会有闪动,该特性先注释
832-
// this.setUncontrolledState({
833-
// _searchValue: '',
834-
// _filteredTreeNodes: null,
835-
// });
831+
this.setUncontrolledState({
832+
_searchValue: '',
833+
_filteredTreeNodes: null,
834+
});
836835
}
837836
this.setOpenState(open, true);
838837
},

components/vc-trigger/Popup.jsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ export default {
4646
this.setStretchSize();
4747
});
4848
},
49-
beforeUpdate() {
50-
if (this.domEl && this.domEl.rcEndListener) {
51-
this.domEl.rcEndListener();
52-
this.domEl = null;
53-
}
54-
},
49+
// 如添加会导致动画失效,如放开会导致快速输入时闪动 https://github.com/vueComponent/ant-design-vue/issues/1327,
50+
// 目前方案是保留动画,闪动问题(动画多次执行)进一步定位
51+
// beforeUpdate() {
52+
// if (this.domEl && this.domEl.rcEndListener) {
53+
// this.domEl.rcEndListener();
54+
// this.domEl = null;
55+
// }
56+
// },
5557
updated() {
5658
this.$nextTick(() => {
5759
this.setStretchSize();
@@ -207,10 +209,10 @@ export default {
207209
style: { ...sizeStyle, ...popupStyle, ...this.getZIndexStyle() },
208210
};
209211
let transitionProps = {
210-
props: Object.assign({
212+
props: {
211213
appear: true,
212214
css: false,
213-
}),
215+
},
214216
};
215217
const transitionName = getTransitionName();
216218
let useTransition = !!transitionName;
@@ -227,6 +229,8 @@ export default {
227229
this.domEl = el;
228230
animate(el, `${transitionName}-enter`, done);
229231
});
232+
} else {
233+
done();
230234
}
231235
});
232236
},

components/vc-trigger/Trigger.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ export default {
128128
if (this.sPopupVisible !== this.prevPopupVisible) {
129129
this.afterPopupVisibleChange(this.sPopupVisible);
130130
}
131+
this.prevPopupVisible = this.sPopupVisible;
131132
};
133+
this.renderComponent(null, triggerAfterPopupVisibleChange);
132134
this.$nextTick(() => {
133-
this.renderComponent(null, triggerAfterPopupVisibleChange);
134135
this.updatedCal();
135136
});
136137
},

0 commit comments

Comments
 (0)