-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
82 lines (72 loc) · 2.34 KB
/
App.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
74
75
76
77
78
79
80
81
82
import React, { Component } from 'react';
import {
Text,
View,
StatusBar,
TextInput,
TouchableOpacity,
AsyncStorage,
ToastAndroid
} from 'react-native';
import styles from './css/styles';
export default class App extends Component {
constructor() {
super();
this.state = {
textInputData: '',
getData: ''
}
}
setValueStorage = () => {
if (this.state.textInputData.trim() === "") {
ToastAndroid.show('Enter some text input', ToastAndroid.SHORT);
return;
}
AsyncStorage.setItem('storeValue', this.state.textInputData);
ToastAndroid.show('Data Stored Successfully', ToastAndroid.SHORT);
}
getValueStorage = () => {
AsyncStorage.getItem('storeValue').then((value) => this.setState({ getData: value }))
}
clearStorage = () => {
AsyncStorage.clear()
this.setState({getData: ''})
ToastAndroid.show('Data cleared successfully..!!', ToastAndroid.SHORT);
}
render() {
return (
<View style={styles.mainContainer}>
<Text style={styles.textHeader}>
React Native Codility
</Text>
<View style={{ backgroundColor: '#2471A3', width: '100%', height: 1 }} />
<View style={styles.container}>
<StatusBar
backgroundColor="#2471A3"
barStyle="light-content"
/>
<Text style={styles.welcome}>
Welcome to AsyncStorage APIs!
</Text>
<TextInput
placeholder='Enter text input'
style={styles.TextInputStyle}
underlineColorAndroid='transparent'
onChangeText={data => this.setState({ textInputData: data })}
>
</TextInput>
<TouchableOpacity style={styles.button} onPress={this.setValueStorage} activeOpacity={0.7}>
<Text style={styles.buttonText}>Store Data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this.getValueStorage} activeOpacity={0.7}>
<Text style={styles.buttonText}>Retrieve Data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this.clearStorage} activeOpacity={0.7}>
<Text style={styles.buttonText}>Clear Data</Text>
</TouchableOpacity>
<Text style={styles.welcome}> {this.state.getData} </Text>
</View>
</View>
);
}
}