This repository was archived by the owner on May 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathApp.js
More file actions
104 lines (98 loc) · 2.25 KB
/
App.js
File metadata and controls
104 lines (98 loc) · 2.25 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { Component } from "react";
import {
Animated,
Dimensions,
ScrollView,
StyleSheet,
Text,
View
} from "react-native";
const SCREEN_WIDTH = Dimensions.get("window").width;
const xOffset = new Animated.Value(0);
const Screen = props => {
return (
<View style={styles.scrollPage}>
<Animated.View style={[styles.screen, transitionAnimation(props.index)]}>
<Text style={styles.text}>{props.text}</Text>
</Animated.View>
</View>
);
};
const transitionAnimation = index => {
return {
transform: [
{ perspective: 800 },
{
scale: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH
],
outputRange: [0.25, 1, 0.25]
})
},
{
rotateX: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH
],
outputRange: ["45deg", "0deg", "45deg"]
})
},
{
rotateY: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH
],
outputRange: ["-45deg", "0deg", "45deg"]
})
}
]
};
};
export default class App extends Component {
render() {
return (
<Animated.ScrollView
scrollEventThrottle={16}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: xOffset } } }],
{ useNativeDriver: true }
)}
horizontal
pagingEnabled
style={styles.scrollView}
>
<Screen text="Screen 1" index={0} />
<Screen text="Screen 2" index={1} />
<Screen text="Screen 3" index={2} />
</Animated.ScrollView>
);
}
}
const styles = StyleSheet.create({
scrollView: {
flexDirection: "row",
backgroundColor: "#00d4ff"
},
scrollPage: {
width: SCREEN_WIDTH,
padding: 20
},
screen: {
height: 600,
justifyContent: "center",
alignItems: "center",
borderRadius: 25,
backgroundColor: "white"
},
text: {
fontSize: 45,
fontWeight: "bold"
}
});