forked from waleedAli2408/react-native-video-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.js
78 lines (78 loc) · 2.56 KB
/
animation.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
73
74
75
76
77
78
import { useEffect, useRef } from 'react';
import { Animated, useWindowDimensions } from 'react-native';
import { Device, getPlayerRotationDegree, getPlayerTranslate2D, } from './LayoutCalc';
export const useScaleSpring = (hidden) => {
const scaleAnim = useRef(new Animated.Value(hidden ? 0 : 1)).current;
useEffect(() => {
Animated.spring(scaleAnim, {
toValue: hidden ? 0 : 1,
friction: hidden ? 10 : 4,
useNativeDriver: true,
}).start();
}, [scaleAnim, hidden]);
return scaleAnim;
};
export const useOpacity = (hidden) => {
const opacityAnim = useRef(new Animated.Value(hidden ? 0 : 1)).current;
useEffect(() => {
Animated.timing(opacityAnim, {
toValue: hidden ? 0 : 1,
duration: 120,
useNativeDriver: true,
}).start();
}, [opacityAnim, hidden]);
return opacityAnim;
};
// todo: split to useFullscreenRotation & useFullscreenOpacity
export const useAnimatedFullscreen = (fullscreen, isLandscape) => {
const windowSize = useWindowDimensions();
const { width, height } = Device(windowSize);
const rotateAnim = useRef(new Animated.Value(0)).current;
const opacityAnim = useRef(new Animated.Value(1)).current;
const translate = getPlayerTranslate2D(windowSize, {
fullscreen: !!fullscreen,
isLandscape,
});
const rotate = getPlayerRotationDegree(windowSize, { isLandscape, fullscreen });
useEffect(() => {
Animated.timing(rotateAnim, {
toValue: rotate,
duration: 300,
useNativeDriver: true,
}).start();
}, [rotateAnim, rotate]);
useEffect(() => {
if (fullscreen && !isLandscape) {
opacityAnim.setValue(0);
Animated.timing(opacityAnim, {
toValue: 1,
duration: 300,
useNativeDriver: true,
}).start();
}
}, [opacityAnim, fullscreen, isLandscape]);
return {
staticTransform: [
...translate,
{
rotate: `${rotate}deg`,
},
],
animatedTransform: [
...translate,
{
rotate: rotateAnim.interpolate({
inputRange: [-90, 0, 90],
outputRange: ['-90deg', '0deg', '90deg'],
}),
},
],
fullscreenSize: {
width: isLandscape ? height : width,
height: isLandscape ? width : height,
},
animatedOpacity: {
opacity: opacityAnim,
},
};
};