Skip to content

Commit 4881b6d

Browse files
committed
fix: entering animation with mountOnEnter and unmountOnExit
1 parent 5aa3fd2 commit 4881b6d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Transition.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ReactDOM from 'react-dom';
55
import config from './config';
66
import { timeoutsShape } from './utils/PropTypes';
77
import TransitionGroupContext from './TransitionGroupContext';
8+
import { nextTick } from "./utils/nextTick"
89

910
export const UNMOUNTED = 'unmounted';
1011
export const EXITED = 'exited';
@@ -212,7 +213,15 @@ class Transition extends React.Component {
212213
this.cancelNextCallback();
213214

214215
if (nextStatus === ENTERING) {
215-
this.performEnter(mounting);
216+
// https://github.com/reactjs/react-transition-group/pull/749
217+
// With unmountOnExit or mountOnEnter, the enter animation should happen at the transition between `exited` and `entering`.
218+
// To make the animation happen, we have to separate each rendering and avoid being processed as batched.
219+
if (this.props.unmountOnExit || this.props.mountOnEnter) {
220+
// `exited` -> `entering`
221+
nextTick(() => this.performEnter(mounting));
222+
} else {
223+
this.performEnter(mounting);
224+
}
216225
} else {
217226
this.performExit();
218227
}

src/utils/nextTick.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// polyfill for requestAnimationFrame
2+
const rAF = typeof window !== "undefined" && typeof window.requestAnimationFrame === "function" ? window.requestAnimationFrame : cb => setTimeout(cb, 1)
3+
4+
// https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
5+
// Note: Your callback routine must itself call requestAnimationFrame() again
6+
// if you want to animate another frame at the next repaint. requestAnimationFrame() is 1 shot.
7+
export const nextTick = cb => rAF(() => rAF(cb))

0 commit comments

Comments
 (0)