-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStorageDemo.js
More file actions
68 lines (59 loc) · 1.8 KB
/
StorageDemo.js
File metadata and controls
68 lines (59 loc) · 1.8 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
'use strict';
import React, {Component} from 'react';
import {
View,
Text,
TextInput,
TouchableHighlight,
Dimensions,
Alert
} from 'react-native';
var winWidth = Dimensions.get('window').width;
var winHeight = Dimensions.get('window').height;
var myDB = require('./DAAsyncStorage');
var myDBInstance = new myDB();
var textField;
class StorageDemo extends Component {
constructor(props) {
super(props);
this.state = {
searchString:''
}
}
savePressed() {
myDBInstance.setTheItem('myKey',this.state.searchString,function(){
Alert.alert('Save',this.state.searchString+' was saved!');
}.bind(this));
}
fetchPressed() {
myDBInstance.getTheItem('myKey',function(value){
Alert.alert('Fetch','Your Value is - '+value);
});
}
valueChanged(event) {
this.setState({
searchString:event.nativeEvent.text
})
}
render() {
textField = <TextInput placeholder='Enter text to save' style={{position:'absolute',width:winWidth - 20,top:20,height:44,margin:10,backgroundColor:'#EEEEEE'}} onChange={this.valueChanged.bind(this)}></TextInput>;
return(
<View>
{textField}
<TouchableHighlight
underlayColor='#dddddd' onPress={this.savePressed.bind(this)} style={{position:'absolute',top:80}}>
<View>
<Text style={{fontSize:22,marginLeft:10,height:22,marginBottom:10,color:'blue'}}>Save</Text>
</View>
</TouchableHighlight>
<TouchableHighlight
underlayColor='#dddddd' onPress={this.fetchPressed} style={{position:'absolute',top:110}}>
<View>
<Text style={{fontSize:22,marginLeft:10,height:22,marginBottom:10,color:'blue'}}>Fetch</Text>
</View>
</TouchableHighlight>
</View>
);
}
}
module.exports = StorageDemo;