Dialogs.tsx
1.28 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
import React from 'react';
import { BGScroll, Card, ListItem } from '../component/View';
import Dialogs from 'react-native-native-dialogs';
const companies = ['Apple', 'Google', 'Facebook'];
const RNDialogs = () => {
const [selectedItem, setSelectedItem] = React.useState<number>();
const [promptText, setPromptText] = React.useState('default string');
return (
<BGScroll>
<Card round>
<ListItem
title="ActionSheet"
onPress={() => {
Dialogs.showActionSheet({
title: 'Choose a company',
options: companies,
textAlign: 'left',
selectedIndex: selectedItem,
})
.then(setSelectedItem)
.catch(() => {});
}}
rightTitle={companies[selectedItem ?? -1]}
/>
<ListItem
title="Prompt"
rightTitle={promptText}
onPress={() => {
Dialogs.showPrompt({
message: 'It is useless, trust me. :)',
title: 'Your Name?',
placeholder: 'Say something',
defaultValue: promptText,
})
.then(setPromptText)
.catch(() => {});
}}
/>
</Card>
</BGScroll>
);
};
export default RNDialogs;