-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
60 lines (50 loc) · 1.32 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React from 'react';
import {
View,
Text,
TouchableOpacity,
StatusBar,
} from 'react-native';
import {connectChannel, leaveChannel} from './channels'
import styles from './styles'
export default class App extends React.Component {
state = {
currentEmoji: null
}
async componentDidMount() {
this.channel = await connectChannel('emojis')
this.channel.on('new_emoji', this.setNewEmoji)
}
componentWillUnmount() {
leaveChannel(this.channel)
}
setNewEmoji = ({value}) => this.setState({currentEmoji: value})
sendRandomEmoji = () => this.channel.push('random_emoji')
get headerText() {
return this.state.currentEmoji ? "A Wild Emoji Appears!" : "No emoji set ..."
}
render() {
return (
<View style={styles.container}>
<StatusBar barStyle="light-content" />
<View style={styles.header}>
<Text style={styles.headerText}>{this.headerText}</Text>
</View>
<Text style={styles.emoji}>{this.state.currentEmoji}</Text>
<TouchableOpacity
style={styles.button}
onPress={this.sendRandomEmoji}
>
<Text style={styles.buttonText}> Send Randemoji</Text>
</TouchableOpacity>
</View>
);
}
}