-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
70 lines (56 loc) · 1.36 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
import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
import Gun from 'gun/gun.js'
const gun = new Gun('https://gun-test-rn.herokuapp.com/gun')
Component.prototype.$gun = gun
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
name: ''
}
this.$hello = this.$gun.get('hello')
let _this = this
this.$hello.on(function (data, key) {
let name = data.name
_this.setState({ name: name })
});
}
render() {
return (
<View style={styles.container}>
<View style={styles.messageArea}>
<Text>Common message :</Text>
<Text style={styles.messageText}> {this.state.name}</Text>
</View>
<TextInput style={styles.inputArea}
onChangeText={(text) => this.setState({ text })}
/>
<Button title='Update'
onPress={() => {
this.$hello.put({ name: this.state.text })
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
inputArea: {
borderWidth: 1,
paddingVertical: 10,
width: "80%"
},
messageArea: {
flexDirection: 'row'
},
messageText: {
color: 'red'
}
});