-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.js
145 lines (136 loc) · 3.46 KB
/
App.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator, TransitionSpecs, HeaderStyleInterpolators, CardStyleInterpolators } from "@react-navigation/stack";
import React from 'react';
import {
Easing,
StatusBar,
StyleSheet,
Text,
View,
} from 'react-native';
import Home from './src/screens/Home';
import ScreenA from './src/screens/ScreenA';
import ScreenB from './src/screens/ScreenB';
import ScreenC from './src/screens/ScreenC';
import ScreenD from './src/screens/ScreenD';
import ScreenE from './src/screens/ScreenE';
const Stack = createStackNavigator();
const config = {
animation: 'spring',
config: {
stiffness: 1000,
damping: 50,
mass: 3,
overshootClamping: false,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01,
}
}
const closeConfig = {
animation: 'timing',
config: {
duration: 200,
easing: Easing.linear,
}
}
const customTransition = {
gestureEnabled: true,
gestureDirection: 'horizontal',
transitionSpec: {
open: TransitionSpecs.TransitionIOSSpec,
close: TransitionSpecs.TransitionIOSSpec,
},
cardStyleInterpolator: ({ current, next, layouts }) => {
return {
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
})
},
{
rotate: current.progress.interpolate({
inputRange: [0, 1],
outputRange: ["180deg", "0deg"],
}),
},
{
scale: next ?
next.progress.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.7],
}) : 1,
}
]
},
opacity: current.opacity,
}
}
}
const AppStack = () => {
return (
<Stack.Navigator
// apply for all screen
screenOptions={{
gestureEnabled: true,
gestureDirection: 'horizontal',
}}
// headerMode="none"
>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="ScreenA" component={ScreenA}
options={{
gestureDirection: 'vertical',
transitionSpec: {
open: config,
close: closeConfig,
},
cardStyleInterpolator: CardStyleInterpolators.forModalPresentationIOS,
}}
/>
<Stack.Screen name="ScreenB" component={ScreenB}
options={{
transitionSpec: {
open: config,
close: closeConfig,
},
cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
}}
/>
<Stack.Screen name="ScreenC" component={ScreenC}
options={{
...customTransition,
}}
/>
<Stack.Screen name="ScreenD" component={ScreenD}
options={{
gestureDirection: 'vertical',
cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
}}
/>
<Stack.Screen name="ScreenE" component={ScreenE}
options={{
gestureDirection: 'vertical-inverted',
cardStyleInterpolator: CardStyleInterpolators.forRevealFromBottomAndroid,
}}
/>
</Stack.Navigator>
)
}
const App = () => {
return (
<NavigationContainer>
<AppStack />
</NavigationContainer>
);
};
export default App;