Skip to content

Commit 60a76a7

Browse files
Extend example for decorator usage
1 parent 4f00b4a commit 60a76a7

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

Example.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component } from 'react';
2+
import {
3+
StyleSheet,
4+
Text,
5+
View
6+
} from 'react-native';
7+
import ScrollableTabView, {DefaultTabBar, } from 'react-native-scrollable-tab-view';
8+
9+
import SensorExample from './SensorExample';
10+
import SensorAwareViewExample from './SensorAwareViewExample';
11+
12+
export default class Example extends Component {
13+
render() {
14+
return (
15+
<ScrollableTabView
16+
style={{marginTop: 20, }}
17+
renderTabBar={() => <DefaultTabBar />}
18+
>
19+
<SensorExample tabLabel="Sensors" />
20+
<SensorAwareViewExample tabLabel="SensorAwareView" />
21+
</ScrollableTabView>
22+
);
23+
}
24+
}

SensorAwareViewExample.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+
import RNSensors from 'react-native-sensors';
8+
9+
function SensorView(props) {
10+
const Component = RNSensors.decorator({
11+
...props,
12+
})(SensorsDisplay);
13+
14+
return (
15+
<Component />
16+
)
17+
}
18+
19+
const SensorDisplay = ({ value, name }) => (
20+
<Text style={styles.welcome}>{name}: {value}</Text>
21+
);
22+
23+
class SensorsDisplay extends Component {
24+
render() {
25+
const {
26+
Accelerometer,
27+
Gyroscope,
28+
Magnetometer,
29+
} = this.props;
30+
31+
debugger;
32+
33+
return (
34+
<View style={styles.container}>
35+
<SensorDisplay name="Accelerometer" value={Accelerometer} />
36+
<SensorDisplay name="Gyroscope" value={Gyroscope} />
37+
<SensorDisplay name="Magnetometer" value={Magnetometer} />
38+
</View>
39+
);
40+
}
41+
}
42+
43+
export default class SensorAwareViewExample extends Component {
44+
render() {
45+
return (
46+
<View style={styles.container}>
47+
<SensorView Accelerometer Gyroscope Magnetometer />
48+
</View>
49+
);
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
22
import { AppRegistry } from 'react-native';
3-
import SensorExample from './SensorExample';
3+
import Example from './Example';
44

5-
AppRegistry.registerComponent('SensorExample', () => SensorExample);
5+
AppRegistry.registerComponent('SensorExample', () => Example);

index.ios.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
22
import { AppRegistry } from 'react-native';
3-
import SensorExample from './SensorExample';
3+
import Example from './Example';
44

5-
AppRegistry.registerComponent('SensorExample', () => SensorExample);
5+
AppRegistry.registerComponent('SensorExample', () => Example);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"react": "15.4.1",
1111
"react-native": "0.39.2",
12+
"react-native-scrollable-tab-view": "^0.7.0",
1213
"react-native-sensors": "next"
1314
},
1415
"devDependencies": {

0 commit comments

Comments
 (0)