@@ -14,10 +14,6 @@ var React = require('react');
14
14
var createReactClass = require ( 'create-react-class' ) ;
15
15
var ReactNative = require ( 'react-native' ) ;
16
16
var { AlertIOS, Platform, ToastAndroid, Text, View} = ReactNative ;
17
- /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
18
- * found when Flow v0.54 was deployed. To see the error delete this comment and
19
- * run Flow. */
20
- var TimerMixin = require ( 'react-timer-mixin' ) ;
21
17
var RNTesterButton = require ( './RNTesterButton' ) ;
22
18
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
23
19
* found when Flow v0.54 was deployed. To see the error delete this comment and
@@ -123,13 +119,15 @@ class RequestIdleCallbackTester extends React.Component<{}, $FlowFixMeState> {
123
119
124
120
var TimerTester = createReactClass ( {
125
121
displayName : 'TimerTester' ,
126
- mixins : [ TimerMixin ] ,
127
122
128
123
_ii : 0 ,
129
124
_iters : 0 ,
130
125
_start : 0 ,
126
+ _timerId : ( null : ?TimeoutID ) ,
127
+ _rafId : ( null : ?AnimationFrameID ) ,
128
+ _intervalId : ( null : ?IntervalID ) ,
129
+ _immediateId : ( null : ?Object ) ,
131
130
_timerFn : ( null : ?( ) = > any ) ,
132
- _handle : ( null : any ) ,
133
131
134
132
render : function ( ) {
135
133
var args = 'fn' + ( this . props . dt !== undefined ? ', ' + this . props . dt : '' ) ;
@@ -140,6 +138,24 @@ var TimerTester = createReactClass({
140
138
) ;
141
139
} ,
142
140
141
+ componentWillUnmount ( ) {
142
+ if ( this . _timerId != null ) {
143
+ clearTimeout ( this . _timerId ) ;
144
+ }
145
+
146
+ if ( this . _rafId != null ) {
147
+ cancelAnimationFrame ( this . _rafId ) ;
148
+ }
149
+
150
+ if ( this . _immediateId != null ) {
151
+ clearImmediate ( this . _immediateId ) ;
152
+ }
153
+
154
+ if ( this . _intervalId != null ) {
155
+ clearInterval ( this . _intervalId ) ;
156
+ }
157
+ } ,
158
+
143
159
_run : function ( ) {
144
160
if ( ! this . _start ) {
145
161
var d = new Date ( ) ;
@@ -152,19 +168,25 @@ var TimerTester = createReactClass({
152
168
} else if ( this . props . dt > 20 ) {
153
169
this . _iters = 10 ;
154
170
}
155
- this . _timerFn = ( ) => this . setTimeout ( this . _run , this . props . dt ) ;
171
+ this . _timerFn = ( ) => {
172
+ this . _timerId = setTimeout ( this . _run , this . props . dt ) ;
173
+ } ;
156
174
} else if ( this . props . type === 'requestAnimationFrame' ) {
157
- this . _timerFn = ( ) => this . requestAnimationFrame ( this . _run ) ;
175
+ this . _timerFn = ( ) => {
176
+ this . _rafId = requestAnimationFrame ( this . _run ) ;
177
+ } ;
158
178
} else if ( this . props . type === 'setImmediate' ) {
159
179
this . _iters = 5000 ;
160
- this . _timerFn = ( ) => this . setImmediate ( this . _run ) ;
180
+ this . _timerFn = ( ) => {
181
+ this . _immediateId = setImmediate ( this . _run ) ;
182
+ } ;
161
183
} else if ( this . props . type === 'setInterval' ) {
162
184
this . _iters = 30 ; // Only used for forceUpdate periodicidy
163
185
this . _timerFn = null ;
164
- this . _handle = this . setInterval ( this . _run , this . props . dt ) ;
186
+ this . _intervalId = setInterval ( this . _run , this . props . dt ) ;
165
187
}
166
188
}
167
- if ( this . _ii >= this . _iters && ! this . _handle ) {
189
+ if ( this . _ii >= this . _iters && this . _intervalId == null ) {
168
190
var d = new Date ( ) ;
169
191
var e = d . getTime ( ) - this . _start ;
170
192
var msg =
@@ -195,14 +217,16 @@ var TimerTester = createReactClass({
195
217
if ( this . _ii % ( this . _iters / 5 ) === 0 ) {
196
218
this . forceUpdate ( ) ;
197
219
}
198
- this . _timerFn && this . _timerFn ( ) ;
220
+ if ( this . _timerFn ) {
221
+ this . _timerId = this . _timerFn ( ) ;
222
+ }
199
223
} ,
200
224
201
225
clear : function ( ) {
202
- this . clearInterval ( this . _handle ) ; // invalid handles are ignored
203
- if ( this . _handle ) {
226
+ if ( this . _intervalId != null ) {
227
+ clearInterval ( this . _intervalId ) ;
204
228
// Configure things so we can do a final run to update UI and reset state.
205
- this . _handle = null ;
229
+ this . _intervalId = null ;
206
230
this . _iters = this . _ii ;
207
231
this . _run ( ) ;
208
232
}
0 commit comments