forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextScreen.js
46 lines (41 loc) · 1.04 KB
/
ContextScreen.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
const React = require('react');
const { Text, Button } = require('react-native');
const Root = require('../components/Root');
const { GlobalContext, Context } = require('../context');
class ContextScreen extends React.Component {
static contextType = Context;
static options() {
return {
topBar: {
title: {
text: 'React Context API'
}
}
};
}
render() {
return (
<Root style={styles.root}>
<Text style={styles.text}>Default value: {this.context}</Text>
<GlobalContext.Consumer>
{ctx => <Text style={styles.text}>Provider value: {ctx.title}</Text>}
</GlobalContext.Consumer>
<GlobalContext.Consumer>
{ctx => <Button title={`clicked ${ctx.count}`} onPress={() => ctx.incrementCount()} />}
</GlobalContext.Consumer>
</Root>
);
}
}
module.exports = ContextScreen;
const styles = {
root: {
justifyContent: 'center',
alignItems: 'center'
},
text: {
fontSize: 14,
textAlign: 'center',
marginBottom: 8
}
};