Skip to content
This repository was archived by the owner on Apr 15, 2020. It is now read-only.

Commit 5a0d6a7

Browse files
committed
Hello, Transitioner
0 parents  commit 5a0d6a7

71 files changed

Lines changed: 12469 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.DS_Store
2+
node_modules/**/*
3+
.expo/*
4+
npm-debug.*
5+
6+
ios/build

.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Animators.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Animated, { Easing } from 'react-native-reanimated';
2+
3+
export const createScreenSpringAnimator = toValue => progress =>
4+
new Promise(resolve => {
5+
if (Platform.OS === 'ios' && supportsImprovedSpringAnimation()) {
6+
Animated.spring(progress, {
7+
toValue,
8+
stiffness: 5000,
9+
damping: 600,
10+
mass: 3,
11+
useNativeDriver: true,
12+
}).start(resolve);
13+
} else {
14+
Animated.timing(progress, {
15+
toValue,
16+
duration,
17+
easing: EaseInOut,
18+
useNativeDriver: true,
19+
}).start(resolve);
20+
}
21+
});

App.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from "react";
2+
import { View, Button } from "react-native";
3+
import {
4+
createSwitchNavigator,
5+
createNavigationContainer
6+
} from "react-navigation";
7+
import ExampleA from "./ExampleA";
8+
import ExampleB from "./ExampleB";
9+
import ExampleC from "./ExampleC";
10+
import ExampleD from "./ExampleD";
11+
import ExampleE from "./ExampleE";
12+
import ExampleT from "./ExampleT";
13+
import ExampleS from "./ExampleS";
14+
import ExampleZ from "./ExampleZ";
15+
16+
import { Provider as LayoutProvider } from "./LayoutContext";
17+
18+
const Examples = ({ navigation }) => (
19+
<View style={{ flex: 1, justifyContent: "center" }}>
20+
{Object.keys(EXAMPLES).map(exampleName => (
21+
<Button
22+
key={exampleName}
23+
onPress={() => navigation.navigate(exampleName)}
24+
title={exampleName}
25+
/>
26+
))}
27+
</View>
28+
);
29+
30+
const EXAMPLES = {
31+
ExampleA,
32+
ExampleB,
33+
ExampleC,
34+
ExampleD,
35+
ExampleE,
36+
// ExampleT,
37+
ExampleS
38+
// ExampleZ
39+
};
40+
41+
const AppNavigator = createSwitchNavigator({
42+
Examples,
43+
...EXAMPLES
44+
});
45+
46+
// const StatefulAppNavigator = createNavigationContainer(AppNavigator);
47+
48+
const App = () => (
49+
<LayoutProvider style={{ flex: 1 }}>
50+
<AppNavigator />
51+
</LayoutProvider>
52+
);
53+
54+
// export default ExampleZ;
55+
export default App;

BasicModalTransition.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React from "react";
2+
import { StyleSheet, View, TouchableWithoutFeedback } from "react-native";
3+
import Animated, { Easing } from "react-native-reanimated";
4+
const { interpolate, timing, Value } = Animated;
5+
import { Consumer } from "./LayoutContext";
6+
7+
const BasicModalTransitionWithLayout = ({
8+
transition,
9+
navigation,
10+
children,
11+
layout
12+
}) => {
13+
const myKey = navigation.state.key;
14+
let opacity = 1;
15+
let transform = [];
16+
if (transition) {
17+
const { fromState, toState, progress } = transition;
18+
const fromKey = fromState.routes[fromState.index].key;
19+
const toKey = toState.routes[toState.index].key;
20+
const fromOpacity = myKey === fromKey ? 1 : 0;
21+
const toOpacity = myKey === toKey ? 1 : 0;
22+
console.log({ myKey, fromOpacity, toOpacity, toKey });
23+
opacity = interpolate(progress, {
24+
inputRange: [0, 1],
25+
outputRange: [fromOpacity, toOpacity]
26+
});
27+
const translateDist = layout.height;
28+
const fromTranslate = myKey === fromKey ? 0 : translateDist;
29+
const toTranslate = myKey === toKey ? 0 : translateDist;
30+
console.log("interpolating from ", { fromTranslate, toTranslate });
31+
transform = [
32+
{
33+
translateY: interpolate(progress, {
34+
inputRange: [0, 1],
35+
outputRange: [fromTranslate, toTranslate]
36+
})
37+
}
38+
];
39+
}
40+
41+
return (
42+
<View style={{ flex: 1 }}>
43+
<TouchableWithoutFeedback
44+
onPress={() => {
45+
navigation.goBack();
46+
}}
47+
>
48+
<Animated.View
49+
useNativeDriver={true}
50+
style={{
51+
...StyleSheet.absoluteFillObject,
52+
opacity,
53+
backgroundColor: "#0009"
54+
}}
55+
/>
56+
</TouchableWithoutFeedback>
57+
<Animated.View
58+
useNativeDriver={true}
59+
style={{
60+
flex: 1,
61+
transform,
62+
margin: 50
63+
}}
64+
>
65+
{children}
66+
</Animated.View>
67+
</View>
68+
);
69+
};
70+
71+
const BasicModalTransition = props => (
72+
<Consumer>
73+
{layout => <BasicModalTransitionWithLayout {...props} layout={layout} />}
74+
</Consumer>
75+
);
76+
77+
BasicModalTransition.navigationOptions = {
78+
createTransition: transition => {
79+
return { ...transition, progress: new Value(0) };
80+
},
81+
runTransition: transition =>
82+
new Promise(resolve => {
83+
timing(transition.progress, {
84+
toValue: 1,
85+
duration: 500,
86+
easing: Easing.inOut(Easing.cubic)
87+
}).start(resolve);
88+
})
89+
};
90+
91+
export default BasicModalTransition;

0 commit comments

Comments
 (0)