This repository has been archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnavigation.js
113 lines (101 loc) · 2.42 KB
/
navigation.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
import React from 'react';
import { StackNavigation, createRouter } from '@expo/ex-navigation';
import {
InteractionManager,
ScrollView,
StatusBar,
StyleSheet,
Text,
TouchableHighlight,
View,
} from 'react-native';
import Scenes from './Scenes';
class SceneScreen extends React.Component {
static route = {
navigationBar: {
title(params) {
return params.title || params.component.meta.description;
},
translucent: true,
tintColor: '#000',
},
};
state = {
transitionComplete: false,
};
componentWillMount() {
InteractionManager.runAfterInteractions(() => {
this.setState({ transitionComplete: true });
});
}
render() {
let { params } = this.props.route;
let SceneComponent;
if (this.state.transitionComplete) {
SceneComponent = params.component;
} else {
SceneComponent = View;
}
return (
<View
style={{
...this.props.route.getContentInsetsStyle(),
flex: 1,
backgroundColor: 'black',
}}>
<SceneComponent style={{ flex: 1 }} />
<StatusBar barStyle="default" />
</View>
);
}
}
class HomeScreen extends React.Component {
static route = {
navigationBar: {
title: 'EXGL Examples',
translucent: true,
},
};
render() {
return (
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={this.props.route.getContentContainerStyle()}>
{Object.values(Scenes).map(this._renderSceneOption)}
<StatusBar barStyle="default" />
</ScrollView>
);
}
_renderSceneOption = (SceneComponent, i) => {
return (
<TouchableHighlight
key={i}
style={styles.row}
underlayColor="#eee"
onPress={() => this._navigateToScene(SceneComponent)}>
<Text>{SceneComponent.meta.description || 'Scene missing description'}</Text>
</TouchableHighlight>
);
};
_navigateToScene = SceneComponent => {
this.props.navigator.push('scene', {
title: SceneComponent.meta.description,
component: SceneComponent,
});
};
}
export const Router = createRouter(
() => ({
home: () => HomeScreen,
scene: () => SceneScreen,
}),
{ ignoreSerializableWarnings: true }
);
const styles = StyleSheet.create({
row: {
paddingHorizontal: 20,
paddingVertical: 15,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#eee',
},
});