11import React from 'react' ;
2- import { Platform , View } from 'react-native' ;
2+ import { Platform , Pressable , View , type ViewStyle } from 'react-native' ;
33
44import { ButtonV1 as Button } from '@fluentui-react-native/button' ;
55import { Checkbox } from '@fluentui-react-native/experimental-checkbox' ;
6+ import { TextV1 } from '@fluentui-react-native/text' ;
67
78import { mobileStyles } from '../Common/styles' ;
89
10+ const pressableStyle : ViewStyle = { borderWidth : 1 , padding : 4 , gap : 4 , flexDirection : 'row' , alignItems : 'center' } ;
11+
912export const OtherCheckbox : React . FunctionComponent = ( ) => {
1013 const [ isChecked , setisChecked ] = React . useState ( false ) ;
1114
@@ -17,24 +20,44 @@ export const OtherCheckbox: React.FunctionComponent = () => {
1720 setisChecked ( false ) ;
1821 } , [ ] ) ;
1922
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+ ) ;
2135
2236 return (
2337 < 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 >
3861 </ View >
3962 ) ;
4063} ;
0 commit comments