@@ -41,7 +41,7 @@ class TransitionGroup extends React.Component {
41
41
let initialChildMapping = this . state . children ;
42
42
for ( let key in initialChildMapping ) {
43
43
if ( initialChildMapping [ key ] ) {
44
- this . performAppear ( key ) ;
44
+ this . performAppear ( key , this . childRefs [ key ] ) ;
45
45
}
46
46
}
47
47
}
@@ -60,15 +60,15 @@ class TransitionGroup extends React.Component {
60
60
for ( let key in nextChildMapping ) {
61
61
let hasPrev = prevChildMapping && prevChildMapping . hasOwnProperty ( key ) ;
62
62
if ( nextChildMapping [ key ] && ! hasPrev &&
63
- ! this . currentlyTransitioningKeys [ key ] ) {
63
+ ! this . currentlyTransitioningKeys [ key ] ) {
64
64
this . keysToEnter . push ( key ) ;
65
65
}
66
66
}
67
67
68
68
for ( let key in prevChildMapping ) {
69
69
let hasNext = nextChildMapping && nextChildMapping . hasOwnProperty ( key ) ;
70
70
if ( prevChildMapping [ key ] && ! hasNext &&
71
- ! this . currentlyTransitioningKeys [ key ] ) {
71
+ ! this . currentlyTransitioningKeys [ key ] ) {
72
72
this . keysToLeave . push ( key ) ;
73
73
}
74
74
}
@@ -79,30 +79,27 @@ class TransitionGroup extends React.Component {
79
79
componentDidUpdate ( ) {
80
80
let keysToEnter = this . keysToEnter ;
81
81
this . keysToEnter = [ ] ;
82
- keysToEnter . forEach ( this . performEnter ) ;
82
+ keysToEnter . forEach ( key => this . performEnter ( key , this . childRefs [ key ] ) ) ;
83
83
84
84
let keysToLeave = this . keysToLeave ;
85
85
this . keysToLeave = [ ] ;
86
- keysToLeave . forEach ( this . performLeave ) ;
86
+ keysToLeave . forEach ( key => this . performLeave ( key , this . childRefs [ key ] ) ) ;
87
87
}
88
88
89
- performAppear = ( key ) => {
89
+ performAppear = ( key , component ) => {
90
90
this . currentlyTransitioningKeys [ key ] = true ;
91
91
92
- let component = this . childRefs [ key ] ;
93
-
94
92
if ( component . componentWillAppear ) {
95
93
component . componentWillAppear (
96
- this . _handleDoneAppearing . bind ( this , key ) ,
94
+ this . _handleDoneAppearing . bind ( this , key , component ) ,
97
95
) ;
98
96
} else {
99
- this . _handleDoneAppearing ( key ) ;
97
+ this . _handleDoneAppearing ( key , component ) ;
100
98
}
101
99
} ;
102
100
103
- _handleDoneAppearing = ( key ) => {
104
- let component = this . childRefs [ key ] ;
105
- if ( component && component . componentDidAppear ) {
101
+ _handleDoneAppearing = ( key , component ) => {
102
+ if ( component . componentDidAppear ) {
106
103
component . componentDidAppear ( ) ;
107
104
}
108
105
@@ -112,27 +109,24 @@ class TransitionGroup extends React.Component {
112
109
113
110
if ( ! currentChildMapping || ! currentChildMapping . hasOwnProperty ( key ) ) {
114
111
// This was removed before it had fully appeared. Remove it.
115
- this . performLeave ( key ) ;
112
+ this . performLeave ( key , component ) ;
116
113
}
117
114
} ;
118
115
119
- performEnter = ( key ) => {
116
+ performEnter = ( key , component ) => {
120
117
this . currentlyTransitioningKeys [ key ] = true ;
121
118
122
- let component = this . childRefs [ key ] ;
123
-
124
119
if ( component . componentWillEnter ) {
125
120
component . componentWillEnter (
126
- this . _handleDoneEntering . bind ( this , key ) ,
121
+ this . _handleDoneEntering . bind ( this , key , component ) ,
127
122
) ;
128
123
} else {
129
- this . _handleDoneEntering ( key ) ;
124
+ this . _handleDoneEntering ( key , component ) ;
130
125
}
131
126
} ;
132
127
133
- _handleDoneEntering = ( key ) => {
134
- let component = this . childRefs [ key ] ;
135
- if ( component && component . componentDidEnter ) {
128
+ _handleDoneEntering = ( key , component ) => {
129
+ if ( component . componentDidEnter ) {
136
130
component . componentDidEnter ( ) ;
137
131
}
138
132
@@ -142,28 +136,25 @@ class TransitionGroup extends React.Component {
142
136
143
137
if ( ! currentChildMapping || ! currentChildMapping . hasOwnProperty ( key ) ) {
144
138
// This was removed before it had fully entered. Remove it.
145
- this . performLeave ( key ) ;
139
+ this . performLeave ( key , component ) ;
146
140
}
147
141
} ;
148
142
149
- performLeave = ( key ) => {
143
+ performLeave = ( key , component ) => {
150
144
this . currentlyTransitioningKeys [ key ] = true ;
151
145
152
- let component = this . childRefs [ key ] ;
153
146
if ( component . componentWillLeave ) {
154
- component . componentWillLeave ( this . _handleDoneLeaving . bind ( this , key ) ) ;
147
+ component . componentWillLeave ( this . _handleDoneLeaving . bind ( this , key , component ) ) ;
155
148
} else {
156
149
// Note that this is somewhat dangerous b/c it calls setState()
157
150
// again, effectively mutating the component before all the work
158
151
// is done.
159
- this . _handleDoneLeaving ( key ) ;
152
+ this . _handleDoneLeaving ( key , component ) ;
160
153
}
161
154
} ;
162
155
163
- _handleDoneLeaving = ( key ) => {
164
- let component = this . childRefs [ key ] ;
165
-
166
- if ( component && component . componentDidLeave ) {
156
+ _handleDoneLeaving = ( key , component ) => {
157
+ if ( component . componentDidLeave ) {
167
158
component . componentDidLeave ( ) ;
168
159
}
169
160
@@ -173,7 +164,7 @@ class TransitionGroup extends React.Component {
173
164
174
165
if ( currentChildMapping && currentChildMapping . hasOwnProperty ( key ) ) {
175
166
// This entered again before it fully left. Add it again.
176
- this . performEnter ( key ) ;
167
+ this . keysToEnter . push ( key ) ;
177
168
} else {
178
169
this . setState ( ( state ) => {
179
170
let newChildren = Object . assign ( { } , state . children ) ;
0 commit comments