1- import React from "react" ;
2- import {
3- Button ,
4- Text as UnstyledText ,
5- View as UnstyledView
6- } from "react-native" ;
7- import { createNavigator , StackRouter } from "react-navigation" ;
8- import { Transitioner } from "./Transitioner" ;
9- import Animated , { Easing } from "react-native-reanimated" ;
10- const { Value, timing, interpolate } = Animated ;
11- import FadeTransition from "./FadeTransition" ;
12-
13- const View = props => (
14- < UnstyledView
15- style = { { flex : 1 , justifyContent : "center" , backgroundColor : "#eee" } }
16- { ...props }
17- />
18- ) ;
19- const Text = props => (
20- < UnstyledText style = { { textAlign : "center" } } { ...props } />
21- ) ;
22-
23- const HomeScreen = ( { navigation } ) => (
24- < View >
25- < Text > Home Screen</ Text >
26- < Button
27- onPress = { ( ) => {
28- navigation . navigate ( "ProfileScreen" , { name : "Jane" } ) ;
29- } }
30- title = "Go to Jane's profile"
31- />
32- < Button
33- onPress = { ( ) => {
34- navigation . navigate ( "Examples" ) ;
35- } }
36- title = "Exit"
37- />
38- </ View >
39- ) ;
40-
41- class ProfileScreen extends React . Component {
42- static navigationOptions = {
43- createTransition : transition => ( {
44- ...transition ,
45- progress : new Value ( 0 )
46- } ) ,
47- runTransition : transition =>
48- new Promise ( resolve => {
49- timing ( transition . progress , {
50- toValue : 1 ,
51- duration : 500 ,
52- easing : Easing . inOut ( Easing . cubic )
53- } ) . start ( resolve ) ;
54- } )
55- } ;
56- render ( ) {
57- const { transition, navigation } = this . props ;
58- const myKey = navigation . state . key ;
59- let opacity = 1 ;
60- if ( transition ) {
61- const { fromState, toState, progress } = transition ;
62- const fromOpacity = fromState . routes . find ( r => r . key === myKey ) ? 1 : 0 ;
63- const toOpacity = toState . routes . find ( r => r . key === myKey ) ? 1 : 0 ;
64- opacity = interpolate ( progress , {
65- inputRange : [ 0 , 1 ] ,
66- outputRange : [ fromOpacity , toOpacity ]
67- } ) ;
68- }
69- return (
70- < Animated . View style = { { flex : 1 , opacity } } >
71- < View >
72- < Text >
73- { navigation . getParam ( "name" ) }
74- 's Profile
75- </ Text >
76- < Button
77- onPress = { ( ) => navigation . push ( "HomeScreen" ) }
78- title = "Go Home"
79- />
80- < Button onPress = { ( ) => navigation . goBack ( ) } title = "Go Back" />
81- </ View >
82- </ Animated . View >
83- ) ;
84- }
85- }
86-
87- const App = createNavigator (
88- Transitioner ,
89- StackRouter ( {
90- HomeScreen,
91- ProfileScreen
92- } )
93- ) ;
94-
95- export default App ;
96-
971// import React from "react";
982// import {
993// Button,
@@ -102,6 +6,8 @@ export default App;
1026// } from "react-native";
1037// import { createNavigator, StackRouter } from "react-navigation";
1048// import { Transitioner } from "./Transitioner";
9+ // import Animated, { Easing } from "react-native-reanimated";
10+ // const { Value, timing, interpolate } = Animated;
10511// import FadeTransition from "./FadeTransition";
10612
10713// const View = props => (
@@ -114,38 +20,54 @@ export default App;
11420// <UnstyledText style={{ textAlign: "center" }} {...props} />
11521// );
11622
117- // class HomeScreen extends React.Component {
118- // static navigationOptions = FadeTransition.navigationOptions;
119- // render() {
120- // const { navigation } = this.props;
121- // return (
122- // <FadeTransition {...this.props}>
123- // <View>
124- // <Text>Home Screen</Text>
125- // <Button
126- // onPress={() => {
127- // navigation.navigate("ProfileScreen", { name: "Jane" });
128- // }}
129- // title="Go to Jane's profile"
130- // />
131- // <Button
132- // onPress={() => {
133- // navigation.navigate("Examples");
134- // }}
135- // title="Exit"
136- // />
137- // </View>
138- // </FadeTransition>
139- // );
140- // }
141- // }
23+ // const HomeScreen = ({ navigation }) => (
24+ // <View>
25+ // <Text>Home Screen</Text>
26+ // <Button
27+ // onPress={() => {
28+ // navigation.navigate("ProfileScreen", { name: "Jane" });
29+ // }}
30+ // title="Go to Jane's profile"
31+ // />
32+ // <Button
33+ // onPress={() => {
34+ // navigation.navigate("Examples");
35+ // }}
36+ // title="Exit"
37+ // />
38+ // </View>
39+ // );
14240
14341// class ProfileScreen extends React.Component {
144- // static navigationOptions = FadeTransition.navigationOptions;
42+ // static navigationOptions = {
43+ // createTransition: transition => ({
44+ // ...transition,
45+ // progress: new Value(0)
46+ // }),
47+ // runTransition: transition =>
48+ // new Promise(resolve => {
49+ // timing(transition.progress, {
50+ // toValue: 1,
51+ // duration: 500,
52+ // easing: Easing.inOut(Easing.cubic)
53+ // }).start(resolve);
54+ // })
55+ // };
14556// render() {
146- // const { navigation } = this.props;
57+ // const { transition, navigation } = this.props;
58+ // const myKey = navigation.state.key;
59+ // let opacity = 1;
60+ // if (transition) {
61+ // const { fromState, toState, progress } = transition;
62+ // const fromOpacity = fromState.routes.find(r => r.key === myKey) ? 1 : 0;
63+ // const toOpacity = toState.routes.find(r => r.key === myKey) ? 1 : 0;
64+ // opacity = interpolate(progress, {
65+ // inputRange: [0, 1],
66+ // outputRange: [fromOpacity, toOpacity]
67+ // });
68+ // }
14769// return (
148- // <FadeTransition {...this.props }>
70+ // <Animated.View style={{ flex: 1, opacity } }>
14971// <View>
15072// <Text>
15173// {navigation.getParam("name")}
@@ -157,7 +79,7 @@ export default App;
15779// />
15880// <Button onPress={() => navigation.goBack()} title="Go Back" />
15981// </View>
160- // </FadeTransition >
82+ // </Animated.View >
16183// );
16284// }
16385// }
@@ -171,3 +93,81 @@ export default App;
17193// );
17294
17395// export default App;
96+
97+ import React from "react" ;
98+ import {
99+ Button ,
100+ Text as UnstyledText ,
101+ View as UnstyledView
102+ } from "react-native" ;
103+ import { createNavigator , StackRouter } from "react-navigation" ;
104+ import { Transitioner } from "./Transitioner" ;
105+ import FadeTransition from "./FadeTransition" ;
106+
107+ const View = props => (
108+ < UnstyledView
109+ style = { { flex : 1 , justifyContent : "center" , backgroundColor : "#eee" } }
110+ { ...props }
111+ />
112+ ) ;
113+ const Text = props => (
114+ < UnstyledText style = { { textAlign : "center" } } { ...props } />
115+ ) ;
116+
117+ class HomeScreen extends React . Component {
118+ static navigationOptions = FadeTransition . navigationOptions ;
119+ render ( ) {
120+ const { navigation } = this . props ;
121+ return (
122+ < FadeTransition { ...this . props } >
123+ < View >
124+ < Text > Home Screen</ Text >
125+ < Button
126+ onPress = { ( ) => {
127+ navigation . navigate ( "ProfileScreen" , { name : "Jane" } ) ;
128+ } }
129+ title = "Go to Jane's profile"
130+ />
131+ < Button
132+ onPress = { ( ) => {
133+ navigation . navigate ( "Examples" ) ;
134+ } }
135+ title = "Exit"
136+ />
137+ </ View >
138+ </ FadeTransition >
139+ ) ;
140+ }
141+ }
142+
143+ class ProfileScreen extends React . Component {
144+ static navigationOptions = FadeTransition . navigationOptions ;
145+ render ( ) {
146+ const { navigation } = this . props ;
147+ return (
148+ < FadeTransition { ...this . props } >
149+ < View >
150+ < Text >
151+ { navigation . getParam ( "name" ) }
152+ 's Profile
153+ </ Text >
154+ < Button
155+ onPress = { ( ) => navigation . push ( "HomeScreen" ) }
156+ title = "Go Home"
157+ />
158+ < Button onPress = { ( ) => navigation . goBack ( ) } title = "Go Back" />
159+ </ View >
160+ </ FadeTransition >
161+ ) ;
162+ }
163+ }
164+
165+ const App = createNavigator (
166+ Transitioner ,
167+ StackRouter ( {
168+ HomeScreen,
169+ ProfileScreen
170+ } )
171+ ) ;
172+
173+ export default App ;
0 commit comments