@@ -144,8 +144,12 @@ export default (View) => {
144
144
}
145
145
146
146
willReceiveProps ( nextProps : P ) : void {
147
- const { range : nextRange } = nextProps ;
148
- const { range : lastRange } = this . props ;
147
+ // @ts -ignore
148
+ const { range : nextRange , data : nextData } = nextProps ;
149
+ const { range : lastRange , data : lastData } = this . props ;
150
+ if ( nextData !== lastData ) {
151
+ this . _cancelAnimationFrame ( ) ;
152
+ }
149
153
if ( ! isEqual ( nextRange , lastRange ) ) {
150
154
const cacheRange = { } ;
151
155
each ( this . dims , ( dim ) => {
@@ -215,7 +219,21 @@ export default (View) => {
215
219
}
216
220
217
221
didUnmount ( ) : void {
218
- this . loop && cancelAnimationFrame ( this . loop ) ;
222
+ this . _cancelAnimationFrame ( ) ;
223
+ }
224
+
225
+ _requestAnimationFrame ( calllback : Function ) {
226
+ const { context } = this ;
227
+ const { requestAnimationFrame } = context . canvas ;
228
+ this . loop = requestAnimationFrame ( calllback ) ;
229
+ return this . loop ;
230
+ }
231
+
232
+ _cancelAnimationFrame ( ) {
233
+ const { loop, context } = this ;
234
+ if ( loop ) {
235
+ context . canvas . cancelAnimationFrame ( loop ) ;
236
+ }
219
237
}
220
238
221
239
_bindEvents ( ) {
@@ -273,7 +291,7 @@ export default (View) => {
273
291
const { state } = this ;
274
292
const { range } = state ;
275
293
this . startRange = range ;
276
- this . loop && cancelAnimationFrame ( this . loop ) ;
294
+ this . _cancelAnimationFrame ( ) ;
277
295
} ;
278
296
279
297
onPan = ( ev ) => {
@@ -317,16 +335,15 @@ export default (View) => {
317
335
318
336
this . startRange = range ;
319
337
320
- this . loop = requestAnimationFrame ( ( ) => this . update ( ) ) ;
338
+ this . _requestAnimationFrame ( ( ) => this . update ( ) ) ;
321
339
if ( Math . abs ( x - endX ) < 0.0005 && Math . abs ( y - endY ) < 0.0005 ) {
322
340
this . onEnd ( ) ;
323
- cancelAnimationFrame ( this . loop ) ;
341
+ this . _cancelAnimationFrame ( ) ;
324
342
}
325
343
}
326
344
327
345
animateSwipe ( dim : string , dimRange : ZoomRange , velocity : number ) {
328
- const { context, props } = this ;
329
- const { requestAnimationFrame } = context . canvas ;
346
+ const { props } = this ;
330
347
const { swipeDuration = 1000 } = props ;
331
348
332
349
const diff = ( dimRange [ 1 ] - dimRange [ 0 ] ) * velocity ;
@@ -357,7 +374,7 @@ export default (View) => {
357
374
const easedProgress = easeing ( progress ) ;
358
375
updateRange ( easedProgress ) ;
359
376
360
- requestAnimationFrame ( ( ) => {
377
+ this . _requestAnimationFrame ( ( ) => {
361
378
update ( ) ;
362
379
} ) ;
363
380
} ;
0 commit comments