-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNavigatorExample01.tsx
140 lines (128 loc) · 3.75 KB
/
NavigatorExample01.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
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
import * as React from 'react';
import { StyleSheet, Text, SafeAreaView, TouchableOpacity } from 'react-native';
import { NavigatorView, RouteViewPortal, useNavigation, useNavRouteEvents } from 'react-native-ios-navigator';
import * as Colors from '../constants/Colors';
import * as Helpers from '../functions/Helpers';
const colors = [
Colors.PINK.A700,
Colors.RED.A700,
Colors.ORANGE.A700,
Colors.YELLOW.A700,
Colors.AMBER.A700,
Colors.GREEN.A700,
Colors.LIGHT_GREEN.A700,
Colors.BLUE.A700,
Colors.PURPLE.A700,
Colors.VIOLET.A700,
Colors.INDIGO.A700,
];
function randomBGColor(){
return Helpers.randomElement<string>(colors);
};
function ExampleRoute(){
const navigation = useNavigation();
const [bgColor] = React.useState(randomBGColor());
const routeContainerStyle = { backgroundColor: bgColor };
useNavRouteEvents('onRouteWillPush' , () => console.log('onRouteWillPush' ));
useNavRouteEvents('onRouteDidPush' , () => console.log('onRouteDidPush' ));
useNavRouteEvents('onRouteWillPop' , () => console.log('onRouteWillPop' ));
useNavRouteEvents('onRouteDidPop' , () => console.log('onRouteDidPop' ));
useNavRouteEvents('onRouteWillFocus', () => console.log('onRouteWillFocus'));
useNavRouteEvents('onRouteDidFocus' , () => console.log('onRouteDidFocus' ));
useNavRouteEvents('onRouteWillBlur' , () => console.log('onRouteWillBlur' ));
useNavRouteEvents('onRouteDidBlur' , () => console.log('onRouteDidBlur' ));
return (
<SafeAreaView style={[styles.routeContainer, routeContainerStyle]}>
<Text style={styles.textRoute}>
{`Debug: ${navigation.routeKey} - ${navigation.routeIndex}`}
</Text>
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => {
navigation.push({routeKey: 'routeA'}, {
transitionConfig: { type: 'SlideLeft', duration: 0.3 }
});
}}
>
<Text style={styles.buttonText}>
{'Push: RouteA'}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => {
navigation.push({routeKey: 'routeB', routeOptions: {
routeTitle: `Route B${navigation.routeIndex + 1}`
}});
}}
>
<Text style={styles.buttonText}>
{'Push: RouteB'}
</Text>
</TouchableOpacity>
</SafeAreaView>
);
};
export function NavigatorExample01() {
return(
<SafeAreaView style={styles.rootContainer}>
<RouteViewPortal
routeOptions={{
//largeTitleDisplayMode: 'never',
}}
/>
<NavigatorView
ref={r => { this.navRef = r }}
initialRoutes={[{routeKey: 'routeA'}]}
navBarPrefersLargeTitles={false}
routes={{
routeA: {
routeOptionsDefault: {
routeTitle: "Route A",
navBarButtonBackItemConfig: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'trash',
},
}
},
renderRoute: () => (
<ExampleRoute/>
),
},
routeB: {
routeOptionsDefault: {
routeTitle: "Route B",
},
renderRoute: () => (
<ExampleRoute/>
),
}
}}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
rootContainer: {
flex: 1,
},
routeContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
textRoute: {
fontSize: 32,
},
buttonContainer: {
backgroundColor: 'rgba(255,255,255,0.75)',
paddingHorizontal: 12,
paddingVertical: 7,
marginTop: 12,
borderRadius: 10,
},
buttonText: {
fontSize: 20,
}
});