-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.js
More file actions
51 lines (45 loc) · 1.42 KB
/
Utils.js
File metadata and controls
51 lines (45 loc) · 1.42 KB
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
import { Animated, Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window')
const duration = 200
function getBoundaryOffset(scale) {
const offsetBoundaryX = (scale*width/2-width/2)/scale
const offsetBoundaryY = (scale*height/2-height/2)/scale
let offsetX = this.animatedOffsetX._value
let offsetY = this.animatedOffsetY._value
if (Math.abs(this.animatedOffsetX._value) > offsetBoundaryX) {
offsetX = offsetBoundaryX*Math.sign(this.animatedOffsetX._value)
}
if (Math.abs(this.animatedOffsetY._value) > offsetBoundaryY) {
offsetY = offsetBoundaryY*Math.sign(this.animatedOffsetY._value)
}
return {offsetX,offsetY}
}
function parallelWithoutScaleAnimated({offsetX,offsetY,done}) {
Animated.parallel([
Animated.timing(this.animatedOffsetX,{
toValue: offsetX,
duration: duration,
}),
Animated.timing(this.animatedOffsetY,{
toValue: offsetY,
duration: duration,
})
]).start(done)
}
function parallelAnimated({scale,offsetX,offsetY,done}) {
Animated.parallel([
Animated.timing(this.animatedScale,{
toValue: scale,
duration: duration,
}),
Animated.timing(this.animatedOffsetX,{
toValue: offsetX,
duration: duration,
}),
Animated.timing(this.animatedOffsetY,{
toValue: offsetY,
duration: duration,
})
]).start(done)
}
export { getBoundaryOffset, parallelWithoutScaleAnimated, parallelAnimated }