forked from donaldmorton/react-native-bottom-drawer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
72 lines (54 loc) · 1.91 KB
/
helper.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
var React = require('react-native');
var {
Animated,
Easing
} = React;
module.exports = function (screen_height ) {
var module = {};
var initialUsedSpace;
var tension;
var friction;
var initialPosition;
var callbackPositionUpdated;
module.calculateInitialPosition = function ( initial_used_space ){
initialUsedSpace = Math.abs(initial_used_space);
initialPosition = (screen_height * ( 1 - initialUsedSpace ));
return initialPosition;
};
module.getInitialUsedSpace = function(){
return initialUsedSpace;
};
module.getInitialPosition = function(){
return initialPosition;
};
module.setupAnimation = function ( higher_tension, friction, callbackPositionUpdated ){
this.tension = higher_tension;
this.friction = friction;
this.callbackPositionUpdated = callbackPositionUpdated;
};
module.isAValidMovement = function(distanceX, distanceY){
var moveTravelledFarEnough = Math.abs(distanceY) > Math.abs(distanceX) && Math.abs(distanceY) > 2;
return moveTravelledFarEnough;
};
module.startAnimation = function (velocityY, positionY,initialPositon,id ){
console.log('creating animation ');
var isGoingToUp = ( velocityY < 0 )? true : false;
var speed = Math.abs(velocityY);
var currentPosition = Math.abs(positionY / screen_height);
var endPosition = isGoingToUp? 0 : initialPositon;
var position = new Animated.Value(positionY);
position.removeAllListeners();
console.log('configuration : '+endPosition)
Animated.timing(position, {
toValue: endPosition,
tension: 30,
friction: 1,
//easing:Easing.elastic,
velocity: velocityY
}).start();
position.addListener((position)=>{console.log('position by',position,endPosition);});
position.addListener(this.callbackPositionUpdated);
};
return module;
};