Skip to content

Commit 25b9186

Browse files
authored
Revert "fix: Motion state record (react-component#188)" (react-component#190)
This reverts commit 981acac.
1 parent 77a255f commit 25b9186

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

src/Popup.tsx

+6-18
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ interface PopupState {
7878
status: PopupStatus;
7979
prevVisible: boolean;
8080
alignClassName: string;
81-
82-
/** Record for CSSMotion is working or not */
83-
inMotion: boolean;
8481
}
8582

8683
interface AlignRefType {
@@ -99,8 +96,6 @@ class Popup extends Component<PopupProps, PopupState> {
9996
status: null,
10097
prevVisible: null, // eslint-disable-line react/no-unused-state
10198
alignClassName: null,
102-
103-
inMotion: false,
10499
};
105100

106101
public popupRef = React.createRef<HTMLDivElement>();
@@ -113,7 +108,7 @@ class Popup extends Component<PopupProps, PopupState> {
113108

114109
static getDerivedStateFromProps(
115110
{ visible, ...props }: PopupProps,
116-
{ prevVisible, status, inMotion }: PopupState,
111+
{ prevVisible, status }: PopupState,
117112
) {
118113
const newState: Partial<PopupState> = { prevVisible: visible, status };
119114

@@ -122,11 +117,12 @@ class Popup extends Component<PopupProps, PopupState> {
122117
if (prevVisible === null && visible === false) {
123118
// Init render should always be stable
124119
newState.status = 'stable';
125-
newState.inMotion = false;
126120
} else if (visible !== prevVisible) {
127-
newState.inMotion = false;
128-
129-
if (visible || (supportMotion(mergedMotion) && inMotion)) {
121+
if (
122+
visible ||
123+
(supportMotion(mergedMotion) &&
124+
['motion', 'AfterMotion', 'stable'].includes(status))
125+
) {
130126
newState.status = null;
131127
} else {
132128
newState.status = 'stable';
@@ -326,14 +322,6 @@ class Popup extends Component<PopupProps, PopupState> {
326322
mergedMotionVisible = false;
327323
}
328324

329-
// Update trigger to tell if is in motion
330-
['onEnterStart', 'onAppearStart', 'onLeaveStart'].forEach(event => {
331-
mergedMotion[event] = (...args) => {
332-
mergedMotion?.[event]?.(...args);
333-
this.setState({ inMotion: true });
334-
};
335-
});
336-
337325
// ================== Align ==================
338326
const mergedAlignDisabled =
339327
!visible ||

tests/popup.test.jsx

+5-13
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ describe('Popup', () => {
2020
const props = { visible: false };
2121
const state = { prevVisible: null, status: 'something' };
2222

23-
expect(Popup.getDerivedStateFromProps(props, state).status).toBe(
24-
'stable',
25-
);
23+
expect(Popup.getDerivedStateFromProps(props, state).status).toBe('stable');
2624
});
2725

2826
it('does not change when visible is unchanged', () => {
2927
const props = { visible: true };
3028
const state = { prevVisible: true, status: 'something' };
3129

32-
expect(Popup.getDerivedStateFromProps(props, state).status).toBe(
33-
'something',
34-
);
30+
expect(Popup.getDerivedStateFromProps(props, state).status).toBe('something');
3531
});
3632

3733
it('returns null when visible is changed to true', () => {
@@ -45,9 +41,7 @@ describe('Popup', () => {
4541
const props = { visible: false };
4642
const state = { prevVisible: true, status: 'something' };
4743

48-
expect(Popup.getDerivedStateFromProps(props, state).status).toBe(
49-
'stable',
50-
);
44+
expect(Popup.getDerivedStateFromProps(props, state).status).toBe('stable');
5145
});
5246

5347
it('returns null when visible is changed to false and motion is started', () => {
@@ -57,7 +51,7 @@ describe('Popup', () => {
5751
motionName: 'enter',
5852
},
5953
};
60-
const state = { prevVisible: true, status: 'motion', inMotion: true };
54+
const state = { prevVisible: true, status: 'motion' };
6155

6256
expect(Popup.getDerivedStateFromProps(props, state).status).toBe(null);
6357
});
@@ -71,9 +65,7 @@ describe('Popup', () => {
7165
};
7266
const state = { prevVisible: true, status: 'beforeMotion' };
7367

74-
expect(Popup.getDerivedStateFromProps(props, state).status).toBe(
75-
'stable',
76-
);
68+
expect(Popup.getDerivedStateFromProps(props, state).status).toBe('stable');
7769
});
7870
});
7971

0 commit comments

Comments
 (0)