-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
104 lines (95 loc) · 2.64 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from 'react';
import {
Button,
KeyboardAvoidingView,
Platform,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import { AlertPrompt } from './src/index';
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
alertVisible: false,
deleted: 0,
}
}
turnOnAlert() {
this.setState({
alertVisible: true
})
}
rePromptText = () => {
return (
<Text>
<Text style={{fontWeight: 'bold'}}>Oops!</Text> That wasn't correct. Please enter exactly <Text style={{fontWeight: 'bold'}}>DELETE</Text> to confirm deletion. This post will be deleted.
</Text>
)
}
render() {
const { deleted } = this.state;
return (
<View style={styles.container}>
{deleted === 1 || deleted === 2 ? (
<View>
<Text style={{ marginTop: 30 }}>Account successfully deleted!</Text>
</View>
) : (
<View style={styles.buttonBackground}>
<Button onPress= {() => this.turnOnAlert()} title="Delete this account" color="black" />
</View>
)}
{deleted === 2 ? (
<View>
<Text style={{ marginTop: 30 }}>Account successfully deleted!</Text>
</View>
) : (
<View style={styles.buttonBackground}>
<Button onPress= {() => this.turnOnAlert()} title="Delete this account" color="black" />
</View>
)}
<AlertPrompt
alertOnly={false}
animation={"fade"}
androidColor={'rgba(0, 150, 136,1)'}
checkDelay={20}
autoFocus={true}
cancelButtonText={'Cancel'}
confirmButtonText={'Confirm'}
placeHolderText={'Enter here'}
validationCaseSensitive={false}
validationText={'DELETE'}
visible={this.state.alertVisible}
alertSubject={"Are you sure?"}
promptText={<Text>Are you sure you want to delete this post? Enter exactly DELETE to delete it.</Text>}
rePromptText={this.rePromptText}
successfulAnswer={() => this.setState({ alertVisible: false, deleted: this.state.deleted+1 })}
closePrompt={() => this.setState({ alertVisible: false})}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#D3D3D3',
justifyContent: 'center',
},
buttonBackground: {
marginTop: 30,
padding: 5,
}
});