-
Notifications
You must be signed in to change notification settings - Fork 49
/
Utils.tsx
63 lines (53 loc) · 1.67 KB
/
Utils.tsx
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
import Animated from "react-native-reanimated";
const { interpolate, Extrapolate } = Animated;
import { Dimensions, Platform } from "react-native";
const { width, height } = Dimensions.get("window");
const innerHeight = width < height ? height : width;
const innerWidth = width < height ? width : height;
const IsAndroid = Platform.OS === "android";
export const VideoSize = {
inline: {
width: innerWidth,
height: (innerWidth * 9) / 16
},
fullScreen: {
height: innerWidth,
width: innerHeight
}
};
export const fullScreenInterpolate = (
width: Animated.Value<number>,
layout: { top: number; left: number }
) => {
const inputRange = [VideoSize.inline.width, VideoSize.fullScreen.width];
const topRange = [IsAndroid ? layout.top : 0, IsAndroid ? 0 : -layout.top];
const leftRange = [IsAndroid ? layout.left : 0, IsAndroid ? 0 : -layout.left];
const top = interpolate(width, {
inputRange,
outputRange: topRange,
extrapolate: Extrapolate.CLAMP
});
const left = interpolate(width, {
inputRange,
outputRange: leftRange,
extrapolate: Extrapolate.CLAMP
});
const height = interpolate(width, {
inputRange,
outputRange: [VideoSize.inline.height, VideoSize.fullScreen.height + 2],
extrapolate: Extrapolate.CLAMP
});
return { top, height, left };
};
export const sec2time = (time: number) => {
var pad = function(num: number, size: number) {
return ("000" + num).slice(size * -1);
},
hours = Math.floor(time / 60 / 60),
minutes = Math.floor(time / 60) % 60,
seconds = Math.floor(time - minutes * 60);
return `${hours > 0 ? pad(hours, 2) + ":" : ""} ${pad(minutes, 2)} :${pad(
seconds,
2
)}`;
};