Skip to content

Commit 9f4e1b9

Browse files
added android example
1 parent ff57634 commit 9f4e1b9

File tree

4 files changed

+77
-129
lines changed

4 files changed

+77
-129
lines changed

SensorExample.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, { Component } from 'react';
2+
import {
3+
StyleSheet,
4+
Text,
5+
View
6+
} from 'react-native';
7+
8+
import RNSensors from 'react-native-sensors';
9+
const { Accelerometer, Gyroscope } = RNSensors;
10+
const accelerationObservable = new Gyroscope({
11+
updateInterval: 100, // defaults to 100ms
12+
});
13+
14+
export default class SensorExample extends Component {
15+
constructor(props) {
16+
super(props);
17+
this.state = {
18+
acceleration: {
19+
x: 'unknown',
20+
y: 'unknown',
21+
z: 'unknown',
22+
},
23+
};
24+
}
25+
componentWillMount() {
26+
accelerationObservable
27+
.subscribe(acceleration => this.setState({
28+
acceleration,
29+
}));
30+
}
31+
render() {
32+
const {
33+
acceleration,
34+
} = this.state;
35+
36+
return (
37+
<View style={styles.container}>
38+
<Text style={styles.welcome}>
39+
Acceleration
40+
</Text>
41+
<Text style={styles.instructions}>
42+
{acceleration.x + '/' + acceleration.y + '/' + acceleration.z}
43+
</Text>
44+
</View>
45+
);
46+
}
47+
48+
componentWillUnmount() {
49+
accelerationObservable.stop();
50+
}
51+
}
52+
53+
const styles = StyleSheet.create({
54+
container: {
55+
flex: 1,
56+
justifyContent: 'center',
57+
alignItems: 'center',
58+
backgroundColor: '#F5FCFF',
59+
},
60+
welcome: {
61+
fontSize: 20,
62+
textAlign: 'center',
63+
margin: 10,
64+
},
65+
instructions: {
66+
textAlign: 'center',
67+
color: '#333333',
68+
marginBottom: 5,
69+
},
70+
});

index.android.js

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
7-
import React, { Component } from 'react';
8-
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
14-
15-
export default class SensorExample extends Component {
16-
render() {
17-
return (
18-
<View style={styles.container}>
19-
<Text style={styles.welcome}>
20-
Welcome to React Native!
21-
</Text>
22-
<Text style={styles.instructions}>
23-
To get started, edit index.android.js
24-
</Text>
25-
<Text style={styles.instructions}>
26-
Double tap R on your keyboard to reload,{'\n'}
27-
Shake or press menu button for dev menu
28-
</Text>
29-
</View>
30-
);
31-
}
32-
}
33-
34-
const styles = StyleSheet.create({
35-
container: {
36-
flex: 1,
37-
justifyContent: 'center',
38-
alignItems: 'center',
39-
backgroundColor: '#F5FCFF',
40-
},
41-
welcome: {
42-
fontSize: 20,
43-
textAlign: 'center',
44-
margin: 10,
45-
},
46-
instructions: {
47-
textAlign: 'center',
48-
color: '#333333',
49-
marginBottom: 5,
50-
},
51-
});
1+
import React from 'react';
2+
import { AppRegistry } from 'react-native';
3+
import SensorExample from './SensorExample';
524

535
AppRegistry.registerComponent('SensorExample', () => SensorExample);

index.ios.js

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,5 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
7-
import React, { Component } from 'react';
8-
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
14-
15-
import RNSensors from 'react-native-sensors';
16-
const { Accelerometer, Gyroscope } = RNSensors;
17-
const accelerationObservable = new Gyroscope({
18-
updateInterval: 100, // defaults to 100ms
19-
});
20-
21-
export default class SensorExample extends Component {
22-
constructor(props) {
23-
super(props);
24-
this.state = {
25-
acceleration: {
26-
x: 'unknown',
27-
y: 'unknown',
28-
z: 'unknown',
29-
},
30-
};
31-
}
32-
componentWillMount() {
33-
accelerationObservable
34-
.subscribe(acceleration => this.setState({
35-
acceleration,
36-
}));
37-
}
38-
render() {
39-
const {
40-
acceleration,
41-
} = this.state;
42-
43-
return (
44-
<View style={styles.container}>
45-
<Text style={styles.welcome}>
46-
Acceleration
47-
</Text>
48-
<Text style={styles.instructions}>
49-
{acceleration.x + '/' + acceleration.y + '/' + acceleration.z}
50-
</Text>
51-
</View>
52-
);
53-
}
54-
55-
componentWillUnmount() {
56-
accelerationObservable.stop();
57-
}
58-
}
59-
60-
const styles = StyleSheet.create({
61-
container: {
62-
flex: 1,
63-
justifyContent: 'center',
64-
alignItems: 'center',
65-
backgroundColor: '#F5FCFF',
66-
},
67-
welcome: {
68-
fontSize: 20,
69-
textAlign: 'center',
70-
margin: 10,
71-
},
72-
instructions: {
73-
textAlign: 'center',
74-
color: '#333333',
75-
marginBottom: 5,
76-
},
77-
});
1+
import React from 'react';
2+
import { AppRegistry } from 'react-native';
3+
import SensorExample from './SensorExample';
784

795
AppRegistry.registerComponent('SensorExample', () => SensorExample);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "15.4.1",
1111
"react-native": "0.39.2",
12-
"react-native-sensors": "0.0.1-alpha.3"
12+
"react-native-sensors": "next"
1313
},
1414
"devDependencies": {
1515
"babel-jest": "18.0.0",

0 commit comments

Comments
 (0)