-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
144 lines (136 loc) · 3.57 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as React from "react";
import { StyleSheet, Text, View, Button, Alert } from "react-native";
import PINCode, {
hasUserSetPinCode,
resetPinCodeInternalStates,
deleteUserPinCode,
} from "@haskkor/react-native-pincode";
class App extends React.Component {
constructor() {
super();
this.state = {
showPinLock: false,
PINCodeStatus: "choose",
};
}
_showChoosePinLock = () => {
this.setState({ PINCodeStatus: "choose", showPinLock: true });
};
_showEnterPinLock = async () => {
const hasPin = await hasUserSetPinCode();
if (hasPin) {
this.setState({ PINCodeStatus: "enter", showPinLock: true });
} else {
Alert.alert(null, "You have not set your pin.", [
{
title: "Ok",
onPress: () => {
// do nothing
},
},
]);
}
};
_clearPin = async () => {
await deleteUserPinCode();
await resetPinCodeInternalStates();
Alert.alert(null, "You have cleared your pin.", [
{
title: "Ok",
onPress: () => {
// do nothing
},
},
]);
};
_finishProcess = async () => {
const hasPin = await hasUserSetPinCode();
if (hasPin) {
Alert.alert(null, "You have successfully set/entered your pin.", [
{
title: "Ok",
onPress: () => {
// do nothing
},
},
]);
this.setState({ showPinLock: false });
}
};
render() {
return (
<View style={styles.container}>
{!this.state.showPinLock && (
<View>
<View>
<Text style={styles.title}><Text style={styles.bold}>Welcome to React Native Tutorial!</Text>{
`\n\nIn this tutorial, we will use buttons to show how to use the\n`}
<Text style={styles.bold}>@haskkor/react-native-pincode</Text>
{`\npackage.`}
</Text>
</View>
<View style={styles.button}>
<Text style={styles.title}>
Click on this button to set your PIN.
</Text>
<Button
onPress={() => this._showChoosePinLock()}
title="Set Pin"
/>
</View>
<View style={styles.seperator} />
<View style={styles.button}>
<Text style={styles.title}>
Click on this button to enter your PIN.
</Text>
<Button
onPress={() => this._showEnterPinLock()}
title="Enter Pin"
/>
</View>
<View style={styles.seperator} />
<View style={styles.button}>
<Text style={styles.title}>
Click on this button to clear your PIN.
</Text>
<Button onPress={() => this._clearPin()} title="Clear Pin" />
</View>
</View>
)}
{this.state.showPinLock && (
<PINCode
status={this.state.PINCodeStatus}
touchIDDisabled={true}
finishProcess={() => this._finishProcess()}
/>
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#F5FCFF",
},
title: {
fontSize: 20,
textAlign: "center",
margin: 10,
marginTop: 20,
},
button: {
marginBottom: 10,
padding: 10,
},
bold: {
fontWeight: 'bold',
},
seperator: {
margin: 10,
marginVertical: 8,
borderBottomColor: "#737373",
borderBottomWidth: StyleSheet.hairlineWidth,
},
});
export default App;