-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncStorageText.js
More file actions
93 lines (91 loc) · 2.29 KB
/
AsyncStorageText.js
File metadata and controls
93 lines (91 loc) · 2.29 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Created by penn on 2016/12/14.
*/
import React, { Component } from "react";
import {
View,
StyleSheet,
Text,
AsyncStorage,
TextInput,
Button,
TouchableOpacity
} from "react-native";
import Girl from "./Girl";
import NavigationBar from "./js/common/NavigationBar";
import Toast, { DURATION } from "react-native-easy-toast";
const KEY = "test";
export default class AsyncStorageText extends Component {
constructor(props) {
super(props);
this.state = {
what: ""
};
}
onSave() {
AsyncStorage.setItem(KEY, this.text, error => {
if (!error) {
this.toast.show("保存成功", DURATION.LENGTH_LONG);
} else {
this.toast.show("保存失败", DURATION.LENGTH_LONG);
}
});
}
onRemove() {
AsyncStorage.removeItem(KEY,(error)=>{
if (!error) {
this.toast.show("移除成功", DURATION.LENGTH_LONG);
} else {
this.toast.show("移除失败", DURATION.LENGTH_LONG);
}
})
}
onFetch() {
AsyncStorage.getItem(KEY, (error, result) => {
if (!error) {
if (result !== ""&&result!==null) {
this.toast.show("取出的内容为" + result);
}else{
this.toast.show('key不存在');
}
} else {
this.toast.show("去除失败" + result);
}
});
}
render() {
return (
<View style={styles.container}>
<NavigationBar
title="AsyncStorageText"
style={{ backgroundColor: "#6495ED" }}
/>
<TextInput
style={{ borderWidth: 1, height: 40, margin: 6 }}
onChangeText={text => (this.text = text)}
/>
<View style={{ flexDirection: "row" }}>
<TouchableOpacity onPress={() => this.onSave()}>
<Text style={styles.tips}>保存</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.onRemove()}>
<Text style={styles.tips}>移除</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.onFetch()}>
<Text style={styles.tips}>取出</Text>
</TouchableOpacity>
</View>
<Toast ref={toast => (this.toast = toast)} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
tips: {
fontSize: 29,
margin: 5
}
});