forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogWithRadioBtns.js
113 lines (107 loc) · 3.43 KB
/
DialogWithRadioBtns.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
/* @flow */
import * as React from 'react';
import { ScrollView, View, StyleSheet } from 'react-native';
import {
Subheading,
Button,
Portal,
Dialog,
RadioButton,
TouchableRipple,
} from 'react-native-paper';
type Props = {
visible: boolean,
close: Function,
};
type State = {
checked: 'normal' | 'first' | 'second' | 'third' | 'fourth',
};
export default class extends React.Component<Props, State> {
state = {
checked: 'normal',
};
render() {
const { checked } = this.state;
const { visible, close } = this.props;
return (
<Portal>
<Dialog onDismiss={close} visible={visible}>
<Dialog.Title>Choose an option</Dialog.Title>
<Dialog.ScrollArea style={{ maxHeight: 170, paddingHorizontal: 0 }}>
<ScrollView>
<View>
<TouchableRipple
onPress={() => this.setState({ checked: 'normal' })}
>
<View style={styles.row}>
<View pointerEvents="none">
<RadioButton
value="normal"
status={checked === 'normal' ? 'checked' : 'unchecked'}
/>
</View>
<Subheading style={styles.text}>Option 1</Subheading>
</View>
</TouchableRipple>
<TouchableRipple
onPress={() => this.setState({ checked: 'second' })}
>
<View style={styles.row}>
<View pointerEvents="none">
<RadioButton
value="second"
status={checked === 'second' ? 'checked' : 'unchecked'}
/>
</View>
<Subheading style={styles.text}>Option 2</Subheading>
</View>
</TouchableRipple>
<TouchableRipple
onPress={() => this.setState({ checked: 'third' })}
>
<View style={styles.row}>
<View pointerEvents="none">
<RadioButton
value="third"
status={checked === 'third' ? 'checked' : 'unchecked'}
/>
</View>
<Subheading style={styles.text}>Option 3</Subheading>
</View>
</TouchableRipple>
<TouchableRipple
onPress={() => this.setState({ checked: 'fourth' })}
>
<View style={styles.row}>
<View pointerEvents="none">
<RadioButton
value="fourth"
status={checked === 'fourth' ? 'checked' : 'unchecked'}
/>
</View>
<Subheading style={styles.text}>Option 4</Subheading>
</View>
</TouchableRipple>
</View>
</ScrollView>
</Dialog.ScrollArea>
<Dialog.Actions>
<Button onPress={close}>Cancel</Button>
<Button onPress={close}>Ok</Button>
</Dialog.Actions>
</Dialog>
</Portal>
);
}
}
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 16,
paddingVertical: 8,
},
text: {
paddingLeft: 8,
},
});