-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomScreen.js
57 lines (51 loc) · 1.61 KB
/
CustomScreen.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
import React, { Component } from 'react';
import NavigationBar from 'react-native-navbar';
import styles from './style';
import {
Text,
View,
AsyncStorage,
Button
} from 'react-native';
export default class CustomScreen extends Component {
constructor(props) {
super(props);
console.log("CustomScreen contructor ", this.props.feedId);
this.state = {
favouriteList: []
}
}
_saveDataLocal = async (feed) => {
console.log('Function add to my favourite list ...');
var myFavourite = await AsyncStorage.getItem("favouriteList");
if(myFavourite === null) {
await AsyncStorage.setItem("favouriteList", JSON.stringify(feed));
var afterAdded = await AsyncStorage.getItem("favouriteList");
console.log("Add first feed to my favourite: ", afterAdded);
} else {
await AsyncStorage.mergeItem("favouriteList", JSON.stringify(feed));
var afterAdded = await AsyncStorage.getItem("favouriteList");
console.log("Add one more feed to my favourite: ", afterAdded);
}
}
render() {
const leftButtonConfig = {
title: 'Back',
handler: () => this.props.navigator.pop(),
};
return (
<View style={{ flex: 1, backgroundColor: '#9999CC', }}>
<NavigationBar
title={{ title: 'Custom screen', }}
leftButton={leftButtonConfig} />
<Text>{this.props.name.title}</Text>
<View style={styles.initview.button}>
<Button
onPress={() => {this._saveDataLocal(this.props.name)}}
title="Add to Favourite"
/>
</View>
</View>
);
}
}