-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeScreen.js
More file actions
66 lines (60 loc) · 1.76 KB
/
HomeScreen.js
File metadata and controls
66 lines (60 loc) · 1.76 KB
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
import React, { Component } from "react"
import { Button, Text } from "react-native-elements"
import { View, StyleSheet } from "react-native"
import SmsRetriever from "react-native-sms-retriever"
export class HomeScreen extends Component {
state = {
message: null,
listening: false
}
_onSmsListenerPressed = async () => {
try {
const registered = await SmsRetriever.startSmsRetriever()
console.log(`Registered: ${registered}`)
if (registered) {
this.setState({ listening: registered, message: null })
SmsRetriever.addSmsListener(event => {
console.log(`Response: ${event.message}`)
this.setState({ message: event.message, listening: false }, () => {
SmsRetriever.removeSmsListener()
})
})
}
} catch (error) {
console.log(JSON.stringify(error))
}
}
render() {
const { message, listening } = this.state
return (
<View style={styles.container}>
<View style={{ alignItems: "center" }}>
<Text h3> SMS Listener Example </Text>
<Button
raised
buttonStyle={{ width: 300, backgroundColor: "green" }}
loading={listening}
title="Register SMS Listening"
onPress={() => {
this._onSmsListenerPressed()
}}
/>
{listening && <Text>Waiting for message...</Text>}
</View>
<View style={{ alignItems: "center" }}>
<Text h4>{`Message Received:`}</Text>
<Text>{`${message}`}</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "space-evenly",
alignItems: "center",
backgroundColor: "white"
}
})
export default HomeScreen