-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
102 lines (80 loc) · 2.07 KB
/
App.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
/**
* DiHola Shaking API Example
* https://github.com/diholapp/react-native-dihola-shaking
*/
import React, {Component} from 'react';
import { StyleSheet, Text, View, Vibration } from 'react-native';
import { ShakingAPI } from 'react-native-dihola-shaking';
export default class App extends Component {
state = {
myID: Math.random().toString(36).substring(7),
result: [],
error: 0,
shaken: 0,
loading: 0
}
componentDidMount(){
ShakingAPI.configure({
API_KEY: "Get one at www.diholapp.com",
user: this.state.myID,
sensibility: 50,
timingFilter: 2000,
keepSearching: true,
onShaking: () => this.setState({ shaken: 1, loading: 1 }),
onSuccess: (result) => this.setState({ result, error: 0, loading: 0 }),
onError: (error) => this.setState({ error, loading: 0 })
}).start();
}
componentWillUnmount(){
ShakingAPI.stop();
}
render() {
const { myID, shaken } = this.state;
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to DiHola Shaking API!</Text>
<Text style={styles.instructions}>Shake your device</Text>
<Text style={styles.instructions}>My ID: {myID}</Text>
{ shaken === 1 && this.renderResult() }
</View>
);
}
renderResult(){
const { result, error, loading } = this.state;
var text = "No users found...";
if(loading){
text = "LOADING...";
}
else if (error) {
text = "Something went wrong: " + error;
}
else if (result.length){
text = "Last user(s) found: " + result;
}
return(
<Text style={[styles.instructions, error && styles.error]}>{text}</Text>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 22,
textAlign: 'center',
margin: 10,
},
instructions: {
fontSize: 18,
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
error: {
color: 'red'
}
});