-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotificationScreen.js
73 lines (65 loc) · 1.51 KB
/
NotificationScreen.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
71
72
73
import React, { Component } from "react";
import { View, Text, Button, FlatList, StyleSheet } from "react-native";
import { SQLite } from 'expo-sqlite'
import { ScrollView } from "react-native-gesture-handler";
const db = SQLite.openDatabase('notifications');
class NotificationScreen extends Component {
static navigationOptions = {
title: 'Notifications',
headerStyle: {
backgroundColor: '#ff7800',
}
};
constructor(props) {
super(props);
this.state = {
notifications: []
}
}
componentDidMount() {
db.transaction(tx => {
tx.executeSql(
`select * from items`,
null,
(tx, results) => {
let notifications = results.rows._array;
notifications.reverse();
this.setState({
notifications: notifications
});
}
);
});
}
renderListNotification(item) {
return (
<View style={styles.container}>
<Text> Message Title:: {item.messageTitle}</Text>
<Text> Message Body :: {item.messageBody}</Text>
</View>
);
}
render() {
const {notifications} = this.state;
return (
<View >
{notifications.length === 0 ? <Text>You don't have any Notifications.</Text> : <FlatList
keyExtractor={item => item.id.toString()}
data={notifications}
renderItem={
({ item }) => <ScrollView>{this.renderListNotification(item)}</ScrollView>
}
/>}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
height: 50,
width: "100%",
backgroundColor: "grey",
margin: 5
}
});
export default NotificationScreen;