@@ -13,18 +13,30 @@ const React = require('react');
13
13
const {
14
14
AccessibilityInfo,
15
15
Button,
16
+ Image,
16
17
Text,
17
18
View,
18
19
TouchableOpacity,
19
20
TouchableWithoutFeedback,
20
21
Alert,
21
- UIManager,
22
- findNodeHandle,
23
- Platform,
22
+ StyleSheet,
24
23
} = require ( 'react-native' ) ;
25
24
26
25
const RNTesterBlock = require ( '../../components/RNTesterBlock' ) ;
27
26
27
+ const checkImageSource = require ( './check.png' ) ;
28
+ const uncheckImageSource = require ( './uncheck.png' ) ;
29
+ const mixedCheckboxImageSource = require ( './mixed.png' ) ;
30
+
31
+ const styles = StyleSheet . create ( {
32
+ image : {
33
+ width : 20 ,
34
+ height : 20 ,
35
+ resizeMode : 'contain' ,
36
+ marginRight : 10 ,
37
+ } ,
38
+ } ) ;
39
+
28
40
class AccessibilityExample extends React . Component {
29
41
render ( ) {
30
42
return (
@@ -161,13 +173,6 @@ class CheckboxExample extends React.Component {
161
173
this . setState ( {
162
174
checkboxState : checkboxState ,
163
175
} ) ;
164
-
165
- if ( Platform . OS === 'android' ) {
166
- UIManager . sendAccessibilityEvent (
167
- findNodeHandle ( this ) ,
168
- UIManager . AccessibilityEventTypes . typeViewClicked ,
169
- ) ;
170
- }
171
176
} ;
172
177
173
178
render ( ) {
@@ -195,13 +200,6 @@ class SwitchExample extends React.Component {
195
200
this . setState ( {
196
201
switchState : switchState ,
197
202
} ) ;
198
-
199
- if ( Platform . OS === 'android' ) {
200
- UIManager . sendAccessibilityEvent (
201
- findNodeHandle ( this ) ,
202
- UIManager . AccessibilityEventTypes . typeViewClicked ,
203
- ) ;
204
- }
205
203
} ;
206
204
207
205
render ( ) {
@@ -252,13 +250,6 @@ class SelectionExample extends React.Component {
252
250
isSelected : ! this . state . isSelected ,
253
251
} ) ;
254
252
}
255
-
256
- if ( Platform . OS === 'android' ) {
257
- UIManager . sendAccessibilityEvent (
258
- findNodeHandle ( this . selectableElement . current ) ,
259
- UIManager . AccessibilityEventTypes . typeViewClicked ,
260
- ) ;
261
- }
262
253
} }
263
254
accessibilityLabel = "element 19"
264
255
accessibilityState = { {
@@ -292,13 +283,6 @@ class ExpandableElementExample extends React.Component {
292
283
this . setState ( {
293
284
expandState : expandState ,
294
285
} ) ;
295
-
296
- if ( Platform . OS === 'android' ) {
297
- UIManager . sendAccessibilityEvent (
298
- findNodeHandle ( this ) ,
299
- UIManager . AccessibilityEventTypes . typeViewClicked ,
300
- ) ;
301
- }
302
286
} ;
303
287
304
288
render ( ) {
@@ -314,6 +298,114 @@ class ExpandableElementExample extends React.Component {
314
298
}
315
299
}
316
300
301
+ class NestedCheckBox extends React . Component {
302
+ state = {
303
+ checkbox1 : false ,
304
+ checkbox2 : false ,
305
+ checkbox3 : false ,
306
+ } ;
307
+
308
+ _onPress1 = ( ) => {
309
+ let checkbox1 = false ;
310
+ if ( this . state . checkbox1 === false ) {
311
+ checkbox1 = true ;
312
+ } else if ( this . state . checkbox1 === 'mixed' ) {
313
+ checkbox1 = false ;
314
+ } else {
315
+ checkbox1 = false ;
316
+ }
317
+ setTimeout ( ( ) => {
318
+ this . setState ( {
319
+ checkbox1 : checkbox1 ,
320
+ checkbox2 : checkbox1 ,
321
+ checkbox3 : checkbox1 ,
322
+ } ) ;
323
+ } , 2000 ) ;
324
+ } ;
325
+
326
+ _onPress2 = ( ) => {
327
+ const checkbox2 = ! this . state . checkbox2 ;
328
+
329
+ this . setState ( {
330
+ checkbox2 : checkbox2 ,
331
+ checkbox1 :
332
+ checkbox2 && this . state . checkbox3
333
+ ? true
334
+ : checkbox2 || this . state . checkbox3
335
+ ? 'mixed'
336
+ : false ,
337
+ } ) ;
338
+ } ;
339
+
340
+ _onPress3 = ( ) => {
341
+ const checkbox3 = ! this . state . checkbox3 ;
342
+
343
+ this . setState ( {
344
+ checkbox3 : checkbox3 ,
345
+ checkbox1 :
346
+ this . state . checkbox2 && checkbox3
347
+ ? true
348
+ : this . state . checkbox2 || checkbox3
349
+ ? 'mixed'
350
+ : false ,
351
+ } ) ;
352
+ } ;
353
+
354
+ render ( ) {
355
+ return (
356
+ < View >
357
+ < TouchableOpacity
358
+ style = { { flex : 1 , flexDirection : 'row' } }
359
+ onPress = { this . _onPress1 }
360
+ accessibilityLabel = "Meat"
361
+ accessibilityHint = "State changes in 2 seconds after clicking."
362
+ accessibilityRole = "checkbox"
363
+ accessibilityState = { { checked : this . state . checkbox1 } } >
364
+ < Image
365
+ style = { styles . image }
366
+ source = {
367
+ this . state . checkbox1 === 'mixed'
368
+ ? mixedCheckboxImageSource
369
+ : this . state . checkbox1
370
+ ? checkImageSource
371
+ : uncheckImageSource
372
+ }
373
+ />
374
+ < Text > Meat</ Text >
375
+ </ TouchableOpacity >
376
+ < TouchableOpacity
377
+ style = { { flex : 1 , flexDirection : 'row' } }
378
+ onPress = { this . _onPress2 }
379
+ accessibilityLabel = "Beef"
380
+ accessibilityRole = "checkbox"
381
+ accessibilityState = { { checked : this . state . checkbox2 } } >
382
+ < Image
383
+ style = { styles . image }
384
+ source = {
385
+ this . state . checkbox2 ? checkImageSource : uncheckImageSource
386
+ }
387
+ />
388
+ < Text > Beef</ Text >
389
+ </ TouchableOpacity >
390
+ < TouchableOpacity
391
+ style = { { flex : 1 , flexDirection : 'row' } }
392
+ onPress = { this . _onPress3 }
393
+ accessibilityLabel = "Bacon"
394
+ accessibilityRole = "checkbox"
395
+ accessibilityState = { { checked : this . state . checkbox3 } } >
396
+ < Image
397
+ style = { styles . image }
398
+ source = {
399
+ this . state . checkbox3 ? checkImageSource : uncheckImageSource
400
+ }
401
+ />
402
+ < Text > Bacon</ Text >
403
+ </ TouchableOpacity >
404
+ </ View >
405
+ ) ;
406
+ }
407
+ }
408
+
317
409
class AccessibilityRoleAndStateExample extends React . Component < { } > {
318
410
render ( ) {
319
411
return (
@@ -412,6 +504,9 @@ class AccessibilityRoleAndStateExample extends React.Component<{}> {
412
504
</ View >
413
505
< ExpandableElementExample />
414
506
< SelectionExample />
507
+ < RNTesterBlock title = "Nested checkbox with delayed state change" >
508
+ < NestedCheckBox />
509
+ </ RNTesterBlock >
415
510
</ View >
416
511
) ;
417
512
}
0 commit comments