forked from root-two/react-native-drawer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTweener.js
37 lines (28 loc) · 784 Bytes
/
Tweener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var easingTypes = require('tween-functions');
module.exports = function(config) {
return new Tween(config)
}
function Tween(config){
this._rafLoop = this._rafLoop.bind(this)
this.terminate = this.terminate.bind(this)
this._t0 = Date.now()
this._config = config
this._rafLoop()
}
Tween.prototype._rafLoop = function() {
if(this._break){ return }
var {duration, start, end, easingType} = this._config
var now = Date.now()
var elapsed = now - this._t0
if(elapsed >= duration){
this._config.onFrame(end)
this._config.onEnd()
return
}
var tweenVal = easingTypes[easingType](elapsed, start, end, duration)
this._config.onFrame(tweenVal)
requestAnimationFrame(this._rafLoop)
}
Tween.prototype.terminate = function(){
this._break = true
}