File tree 10 files changed +143
-5
lines changed
10 files changed +143
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import ReactDOM from 'react-dom';
5
5
import config from './config' ;
6
6
import { timeoutsShape } from './utils/PropTypes' ;
7
7
import TransitionGroupContext from './TransitionGroupContext' ;
8
+ import { nextTick } from './utils/nextTick' ;
8
9
9
10
export const UNMOUNTED = 'unmounted' ;
10
11
export const EXITED = 'exited' ;
@@ -212,7 +213,15 @@ class Transition extends React.Component {
212
213
this . cancelNextCallback ( ) ;
213
214
214
215
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
+ }
216
225
} else {
217
226
this . performExit ( ) ;
218
227
}
Original file line number Diff line number Diff line change
1
+ // polyfill for requestAnimationFrame
2
+ const rAF =
3
+ typeof window !== 'undefined' &&
4
+ typeof window . requestAnimationFrame === 'function'
5
+ ? window . requestAnimationFrame
6
+ : ( cb ) => setTimeout ( cb , 1 ) ;
7
+
8
+ // https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
9
+ // Note: Your callback routine must itself call requestAnimationFrame() again
10
+ // if you want to animate another frame at the next repaint. requestAnimationFrame() is 1 shot.
11
+ export const nextTick = ( cb ) => rAF ( ( ) => rAF ( cb ) ) ;
Original file line number Diff line number Diff line change
1
+ import React , { useState } from 'react' ;
2
+ import { storiesOf } from '@storybook/react' ;
3
+
4
+ import StoryFixture from './StoryFixture' ;
5
+ import Fade from './transitions/CSSFade' ;
6
+
7
+ function ToggleFixture ( { defaultIn, description, children } ) {
8
+ const [ show , setShow ] = useState ( defaultIn || false ) ;
9
+
10
+ return (
11
+ < StoryFixture description = { description } >
12
+ < div style = { { marginBottom : 10 } } >
13
+ < button
14
+ onClick = { ( ) => {
15
+ setShow ( ! show ) ;
16
+ } }
17
+ >
18
+ Toggle
19
+ </ button >
20
+ </ div >
21
+ { React . cloneElement ( children , { in : show } ) }
22
+ </ StoryFixture >
23
+ ) ;
24
+ }
25
+
26
+ storiesOf ( 'CSSTransition' , module )
27
+ . add ( 'Fade' , ( ) => (
28
+ < ToggleFixture >
29
+ < Fade > asaghasg asgasg</ Fade >
30
+ </ ToggleFixture >
31
+ ) )
32
+ . add ( 'Fade with appear' , ( ) => (
33
+ < ToggleFixture defaultIn >
34
+ < Fade appear > asaghasg asgasg</ Fade >
35
+ </ ToggleFixture >
36
+ ) )
37
+ . add ( 'Fade with mountOnEnter' , ( ) => {
38
+ return (
39
+ < ToggleFixture >
40
+ < Fade mountOnEnter > Fade with mountOnEnter</ Fade >
41
+ </ ToggleFixture >
42
+ ) ;
43
+ } )
44
+ . add ( 'Fade with unmountOnExit' , ( ) => {
45
+ return (
46
+ < ToggleFixture >
47
+ < Fade unmountOnExit > Fade with unmountOnExit</ Fade >
48
+ </ ToggleFixture >
49
+ ) ;
50
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import React , { useState } from 'react' ;
2
2
3
3
import StoryFixture from './StoryFixture' ;
4
- import Fade from './transitions/Fade ' ;
4
+ import Fade from './transitions/CSSFadeForTransitionGroup ' ;
5
5
import Scale from './transitions/Scale' ;
6
6
7
7
function FadeAndScale ( props ) {
Original file line number Diff line number Diff line change @@ -60,4 +60,18 @@ storiesOf('Transition', module)
60
60
< FadeInnerRef innerRef = { nodeRef } > Fade using innerRef</ FadeInnerRef >
61
61
</ ToggleFixture >
62
62
) ;
63
+ } )
64
+ . add ( 'Fade with mountOnEnter' , ( ) => {
65
+ return (
66
+ < ToggleFixture >
67
+ < Fade mountOnEnter > Fade with mountOnEnter</ Fade >
68
+ </ ToggleFixture >
69
+ ) ;
70
+ } )
71
+ . add ( 'Fade with unmountOnExit' , ( ) => {
72
+ return (
73
+ < ToggleFixture >
74
+ < Fade unmountOnExit > Fade with unmountOnExit</ Fade >
75
+ </ ToggleFixture >
76
+ ) ;
63
77
} ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import TransitionGroup from '../src/TransitionGroup';
6
6
import CSSTransitionGroupFixture from './CSSTransitionGroupFixture' ;
7
7
import NestedTransition from './NestedTransition' ;
8
8
import StoryFixture from './StoryFixture' ;
9
- import Fade , { FADE_TIMEOUT } from './transitions/Fade ' ;
9
+ import Fade , { FADE_TIMEOUT } from './transitions/CSSFadeForTransitionGroup ' ;
10
10
11
11
storiesOf ( 'Css Transition Group' , module )
12
12
. add ( 'Animates on all' , ( ) => (
Original file line number Diff line number Diff line change 1
1
import './Transition' ;
2
+ import './CSSTransition' ;
2
3
import './TransitionGroup' ;
3
4
import './ReplaceTransition' ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import Transition, {
12
12
const styles = css `
13
13
.fade {
14
14
opacity : 0 ;
15
- transition : opacity 0.15 s linear;
15
+ transition : opacity 0.5 s linear;
16
16
}
17
17
.fade .in {
18
18
opacity : 1 ;
@@ -47,7 +47,7 @@ export function Fade(props) {
47
47
{ ...props }
48
48
nodeRef = { nodeRef }
49
49
className = { styles . fade }
50
- timeout = { 150 }
50
+ timeout = { 500 }
51
51
>
52
52
{ ( status ) => (
53
53
< div
Original file line number Diff line number Diff line change
1
+ import { css } from 'astroturf' ;
2
+ import React , { useRef } from 'react' ;
3
+
4
+ import CSSTransition from '../../src/CSSTransition' ;
5
+
6
+ export const FADE_TIMEOUT = 1000 ;
7
+
8
+ const styles = css `
9
+ .default {
10
+ opacity : 0 ;
11
+ }
12
+ .enter-done {
13
+ opacity : 1 ;
14
+ }
15
+
16
+ .enter ,
17
+ .appear {
18
+ opacity : 0.01 ;
19
+ }
20
+
21
+ .enter .enter-active ,
22
+ .appear .appear-active {
23
+ opacity : 1 ;
24
+ transition : opacity ${ FADE_TIMEOUT } ms ease-in;
25
+ }
26
+
27
+ .exit {
28
+ opacity : 1 ;
29
+ }
30
+ .exit .exit-active {
31
+ opacity : 0.01 ;
32
+ transition : opacity ${ 0.8 * FADE_TIMEOUT } ms ease-in;
33
+ }
34
+ ` ;
35
+
36
+ const defaultProps = {
37
+ in : false ,
38
+ timeout : FADE_TIMEOUT ,
39
+ } ;
40
+ function Fade ( props ) {
41
+ const nodeRef = useRef ( ) ;
42
+ return (
43
+ < CSSTransition { ...props } classNames = { styles } nodeRef = { nodeRef } >
44
+ < div ref = { nodeRef } className = { styles . default } >
45
+ { props . children }
46
+ </ div >
47
+ </ CSSTransition >
48
+ ) ;
49
+ }
50
+
51
+ Fade . defaultProps = defaultProps ;
52
+
53
+ export default Fade ;
File renamed without changes.
You can’t perform that action at this time.
0 commit comments