1
1
import React from 'react' ;
2
- import { Platform , View } from 'react-native' ;
2
+ import { Platform , Pressable , View , type ViewStyle } from 'react-native' ;
3
3
4
4
import { ButtonV1 as Button } from '@fluentui-react-native/button' ;
5
5
import { Checkbox } from '@fluentui-react-native/experimental-checkbox' ;
6
+ import { TextV1 } from '@fluentui-react-native/text' ;
6
7
7
8
import { mobileStyles } from '../Common/styles' ;
8
9
10
+ const pressableStyle : ViewStyle = { borderWidth : 1 , padding : 4 , gap : 4 , flexDirection : 'row' , alignItems : 'center' } ;
11
+
9
12
export const OtherCheckbox : React . FunctionComponent = ( ) => {
10
13
const [ isChecked , setisChecked ] = React . useState ( false ) ;
11
14
@@ -17,24 +20,44 @@ export const OtherCheckbox: React.FunctionComponent = () => {
17
20
setisChecked ( false ) ;
18
21
} , [ ] ) ;
19
22
20
- const memoizedStyles = React . useMemo ( ( ) => ( Platform . OS === 'android' ? { ...mobileStyles . containerSpacedEvenly , height : 150 } : { } ) , [ ] ) ;
23
+ const onChange = React . useCallback ( ( _e , checked : boolean ) => {
24
+ setisChecked ( checked ) ;
25
+ } , [ ] ) ;
26
+
27
+ const onPress = React . useCallback ( ( ) => {
28
+ setisChecked ( ! isChecked ) ;
29
+ } , [ isChecked ] ) ;
30
+
31
+ const memoizedStyles = React . useMemo (
32
+ ( ) => ( Platform . OS === 'android' ? { ...mobileStyles . containerSpacedEvenly , height : 150 } : { gap : 8 } ) ,
33
+ [ ] ,
34
+ ) ;
21
35
22
36
return (
23
37
< View style = { memoizedStyles } >
24
- < Button onClick = { setCheckedTrue } size = "small" >
25
- Check controlled checkboxes below
26
- </ Button >
27
- < Button onClick = { setCheckedFalse } size = "small" >
28
- Uncheck controlled checkboxes below
29
- </ Button >
30
-
31
- < Checkbox label = "This is a controlled Checkbox" checked = { isChecked } />
32
- { Platform . OS !== 'android' && (
33
- < >
34
- < Checkbox label = "Checkbox rendered with labelPosition 'before' (controlled)" labelPosition = "before" checked = { isChecked } />
35
- < Checkbox label = "A required checkbox with other required text" required = "**" />
36
- </ >
37
- ) }
38
+ < View >
39
+ < Button onClick = { setCheckedTrue } size = "small" >
40
+ Check controlled checkboxes below
41
+ </ Button >
42
+ < Button onClick = { setCheckedFalse } size = "small" >
43
+ Uncheck controlled checkboxes below
44
+ </ Button >
45
+ </ View >
46
+
47
+ < View >
48
+ < Checkbox label = "This is a controlled Checkbox" checked = { isChecked } onChange = { onChange } />
49
+ < Pressable style = { pressableStyle } onPress = { onPress } >
50
+ < Checkbox checked = { isChecked } onChange = { onChange } />
51
+ < TextV1 > A controlled checkbox in a Pressable. Pressing Pressable also toggles Checkbox</ TextV1 >
52
+ </ Pressable >
53
+
54
+ { Platform . OS !== 'android' && (
55
+ < >
56
+ < Checkbox label = "Checkbox rendered with labelPosition 'before' (controlled)" labelPosition = "before" checked = { isChecked } />
57
+ < Checkbox label = "A required checkbox with other required text" required = "**" />
58
+ </ >
59
+ ) }
60
+ </ View >
38
61
</ View >
39
62
) ;
40
63
} ;
0 commit comments