forked from michalchudziak/react-native-geolocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
133 lines (121 loc) · 2.96 KB
/
index.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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
import React from 'react';
import {
AppRegistry,
Button,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import GeolocationExample from './GeolocationExample';
import {name as appName} from './app.json';
// Examples which show the user how to correctly use the library
const EXAMPLES = [
{
id: 'getCurrentPosition',
title: 'Geolocation.getCurrentPosition',
description: 'Asynchronously load and observe location',
render() {
return <GeolocationExample />;
},
},
];
// Test cases for the e2e tests. THESE ARE NOT EXAMPLES OF BEST PRACTICE
import TEST_CASES from './testCases';
type State = {
showExamples: boolean,
};
class ExampleApp extends React.Component<{}, State> {
constructor(props) {
super(props);
this.state = {
showExamples: true,
};
}
_toggleMode = () => {
this.setState(state => ({showExamples: !state.showExamples}));
};
render() {
const {showExamples} = this.state;
return (
<ScrollView style={styles.container}>
<SafeAreaView>
<Button
testID="modeToggle"
onPress={this._toggleMode}
title={showExamples ? 'Switch to Test Cases' : 'Switch to Examples'}
/>
{showExamples ? (
<>
<Text testID="examplesTitle" style={styles.sectionTitle}>
Examples
</Text>
{EXAMPLES.map(this._renderExample)}
</>
) : (
<>
<Text testID="testCasesTitle" style={styles.sectionTitle}>
Test Cases
</Text>
{TEST_CASES.map(this._renderExample)}
</>
)}
</SafeAreaView>
</ScrollView>
);
}
_renderExample = example => {
return (
<View
testID={`example-${example.id}`}
key={example.title}
style={styles.exampleContainer}>
<Text style={styles.exampleTitle}>{example.title}</Text>
<Text style={styles.exampleDescription}>{example.description}</Text>
<View style={styles.exampleInnerContainer}>{example.render()}</View>
</View>
);
};
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
sectionTitle: {
fontSize: 24,
marginHorizontal: 8,
marginTop: 24,
},
exampleContainer: {
padding: 16,
marginVertical: 4,
backgroundColor: '#FFF',
borderColor: '#EEE',
borderTopWidth: 1,
borderBottomWidth: 1,
},
exampleTitle: {
fontSize: 18,
},
exampleDescription: {
color: '#333333',
marginBottom: 16,
},
exampleInnerContainer: {
borderColor: '#EEE',
borderTopWidth: 1,
paddingTop: 16,
},
});
AppRegistry.registerComponent(appName, () => ExampleApp);