Skip to content

Commit fbeba11

Browse files
authored
fix(ActionSheet): 页面跳转返回后再点击不显示问题 (#3796)
* fix: 页面跳转返回后再点击不显示问题 #3567 * test: 修复transition单测报错 * fix: fix(ActionSheet): 优化代码
1 parent 95e93bd commit fbeba11

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

src/mixins/transition.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function transition() {
5757
return [Number(durations), Number(durations)];
5858
},
5959
enter() {
60-
const { name } = this.data;
60+
const { name, transitionDurations } = this.data;
6161
const [duration] = this.durations;
6262
this.status = 'entering';
6363
this.setData({
@@ -71,6 +71,11 @@ export default function transition() {
7171
}, 30);
7272
if (typeof duration === 'number' && duration > 0) {
7373
this.transitionT = setTimeout(this.entered.bind(this), duration + 30);
74+
} else {
75+
this.transitionT = setTimeout(
76+
this.status === 'entering' ? this.entered.bind(this) : null,
77+
transitionDurations + 30,
78+
);
7479
}
7580
},
7681
entered() {
@@ -82,7 +87,7 @@ export default function transition() {
8287
});
8388
},
8489
leave() {
85-
const { name } = this.data;
90+
const { name, transitionDurations } = this.data;
8691
const [, duration] = this.durations;
8792
this.status = 'leaving';
8893
this.setData({
@@ -97,6 +102,11 @@ export default function transition() {
97102
if (typeof duration === 'number' && duration > 0) {
98103
this.customDuration = true;
99104
this.transitionT = setTimeout(this.leaved.bind(this), duration + 30);
105+
} else {
106+
this.transitionT = setTimeout(
107+
this.status === 'leaving' ? this.leaved.bind(this) : null,
108+
transitionDurations + 30,
109+
);
100110
}
101111
},
102112
leaved() {
@@ -106,6 +116,7 @@ export default function transition() {
106116
this.status = 'leaved';
107117
this.setData({
108118
transitionClass: '',
119+
realVisible: false,
109120
});
110121
},
111122
onTransitionEnd() {
@@ -118,9 +129,6 @@ export default function transition() {
118129
this.entered();
119130
} else if (this.status === 'leaving' && !this.data.visible) {
120131
this.leaved();
121-
this.setData({
122-
realVisible: false,
123-
});
124132
}
125133
},
126134
},

src/transition/__test__/index.test.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,46 @@ describe('transition', () => {
4141
const [transitionDom] = transitionComp.dom.children;
4242

4343
// enter
44-
transitionComp.setData({ visible: true });
45-
expect(transitionDom.style.display).toEqual('');
46-
expect(transitionDom.className.match(/fade-enter\s/)).toBeTruthy();
47-
expect(transitionDom.className.match(/fade-enter-active/)).toBeTruthy();
48-
49-
// enter to
50-
jest.runAllTimers();
51-
expect(transitionDom.className.match(/fade-enter-to/)).toBeTruthy();
52-
53-
// enter finished
54-
transitionComp.instance.onTransitionEnd();
55-
expect(transitionDom.className.match(/fade-(enter|enter-to|enter-active)/)).toBeFalsy();
56-
57-
// leave
58-
transitionComp.setData({ visible: false });
59-
expect(transitionDom.className.match(/leave\s/)).toBeTruthy();
60-
expect(transitionDom.className.match(/leave-active/)).toBeTruthy();
61-
62-
// leave to
63-
jest.runAllTimers();
64-
expect(transitionDom.className.match(/leave-to/)).toBeTruthy();
65-
66-
// leave finished
67-
transitionComp.instance.onTransitionEnd();
68-
expect(transitionDom.style.display).toEqual('none');
69-
expect(transitionDom.className.match(/(leave|leave-to|leave-active)/)).toBeFalsy();
44+
transitionComp.setData({ visible: true }, () => {
45+
expect(transitionDom.style.display).toEqual('');
46+
expect(transitionDom.className.match(/fade-enter\s/)).toBeTruthy();
47+
expect(transitionDom.className.match(/fade-enter-active/)).toBeTruthy();
48+
49+
// enter to
50+
jest.runAllTimers();
51+
expect(transitionDom.className.match(/fade-enter-to/)).toBeTruthy();
52+
53+
// enter finished
54+
transitionComp.instance.onTransitionEnd();
55+
expect(transitionDom.className.match(/fade-(enter|enter-to|enter-active)/)).toBeFalsy();
56+
57+
// leave
58+
transitionComp.setData({ visible: false });
59+
expect(transitionDom.className.match(/leave\s/)).toBeTruthy();
60+
expect(transitionDom.className.match(/leave-active/)).toBeTruthy();
61+
62+
// leave to
63+
jest.runAllTimers();
64+
expect(transitionDom.className.match(/leave-to/)).toBeTruthy();
65+
66+
// leave finished
67+
transitionComp.instance.onTransitionEnd();
68+
expect(transitionDom.style.display).toEqual('none');
69+
expect(transitionDom.className.match(/(leave|leave-to|leave-active)/)).toBeFalsy();
70+
});
7071
});
7172

7273
it(':name', () => {
7374
const transitionComp = simulate.render(transitionId, { name: 'foo' });
7475
transitionComp.attach(document.createElement('parent-wrapper'));
7576
const [transitionDom] = transitionComp.dom.children;
7677

77-
transitionComp.setData({ visible: true });
78-
jest.runAllTimers();
79-
expect(transitionDom.className.match(/foo-enter/)).toBeTruthy();
80-
expect(transitionDom.className.match(/foo-enter-active/)).toBeTruthy();
81-
expect(transitionDom.className.match(/foo-enter-to/)).toBeTruthy();
78+
transitionComp.setData({ visible: true }, () => {
79+
jest.runAllTimers();
80+
expect(transitionDom.className.match(/foo-enter/)).toBeTruthy();
81+
expect(transitionDom.className.match(/foo-enter-active/)).toBeTruthy();
82+
expect(transitionDom.className.match(/foo-enter-to/)).toBeTruthy();
83+
});
8284
});
8385

8486
// it(':destroyOnHide', () => {
@@ -93,13 +95,14 @@ describe('transition', () => {
9395
// });
9496

9597
it(':appear', () => {
96-
const transitionComp = simulate.render(transitionId, { visible: true, appear: true });
97-
transitionComp.attach(document.createElement('parent-wrapper'));
98-
const [transitionDom] = transitionComp.dom.children;
99-
expect(transitionDom.className.match(/enter\s/)).toBeTruthy();
100-
expect(transitionDom.className.match(/enter-active/)).toBeTruthy();
101-
jest.runAllTimers();
102-
expect(transitionDom.className.match(/enter-to/)).toBeTruthy();
98+
const transitionComp = simulate.render(transitionId, { visible: true, appear: true }, () => {
99+
transitionComp.attach(document.createElement('parent-wrapper'));
100+
const [transitionDom] = transitionComp.dom.children;
101+
expect(transitionDom.className.match(/enter\s/)).toBeTruthy();
102+
expect(transitionDom.className.match(/enter-active/)).toBeTruthy();
103+
jest.runAllTimers();
104+
expect(transitionDom.className.match(/enter-to/)).toBeTruthy();
105+
});
103106
});
104107

105108
it(':durations', () => {

0 commit comments

Comments
 (0)