11import * as React from 'react' ;
2- import { StyleSheet , Text , Image , View , ScrollView } from 'react-native' ;
2+ import {
3+ StyleSheet ,
4+ Text ,
5+ Image ,
6+ View ,
7+ ScrollView ,
8+ findNodeHandle ,
9+ AccessibilityInfo ,
10+ Platform ,
11+ UIManager ,
12+ } from 'react-native' ;
313import TouchableNativeFeedbackSafe from './TouchableNativeFeedbackSafe' ;
414import { ActionSheetOptions } from '../types' ;
515
@@ -14,6 +24,28 @@ const BLACK_54PC_TRANSPARENT = '#0000008a';
1424const BLACK_87PC_TRANSPARENT = '#000000de' ;
1525const DESTRUCTIVE_COLOR = '#d32f2f' ;
1626
27+ /**
28+ * Can be used as a React ref for a component to auto-focus for accessibility on render.
29+ * @param ref The component to auto-focus
30+ */
31+ const focusViewOnRender = ( ref : React . Component | null ) => {
32+ if ( ref ) {
33+ const reactTag = findNodeHandle ( ref ) ;
34+ if ( reactTag ) {
35+ if ( Platform . OS === 'android' ) {
36+ // @ts -ignore: sendAccessibilityEvent is missing from @types/react-native
37+ UIManager . sendAccessibilityEvent (
38+ reactTag ,
39+ // @ts -ignore: AccessibilityEventTypes is missing from @types/react-native
40+ UIManager . AccessibilityEventTypes . typeViewFocused
41+ ) ;
42+ } else {
43+ AccessibilityInfo . setAccessibilityFocus ( reactTag ) ;
44+ }
45+ }
46+ }
47+ } ;
48+
1749export default class ActionGroup extends React . Component < Props > {
1850 static defaultProps = {
1951 title : null ,
@@ -80,6 +112,7 @@ export default class ActionGroup extends React.Component<Props> {
80112 length,
81113 textStyle,
82114 tintColor,
115+ autoFocus,
83116 showSeparators,
84117 } = this . props ;
85118 const optionViews : React . ReactNode [ ] = [ ] ;
@@ -97,11 +130,13 @@ export default class ActionGroup extends React.Component<Props> {
97130
98131 optionViews . push (
99132 < TouchableNativeFeedbackSafe
133+ ref = { autoFocus && i === 0 ? focusViewOnRender : undefined }
100134 key = { i }
101135 pressInDelay = { 0 }
102136 background = { nativeFeedbackBackground }
103137 onPress = { ( ) => onSelect ( i ) }
104138 style = { styles . button }
139+ accessibilityRole = "button"
105140 accessibilityLabel = { options [ i ] } >
106141 { this . _renderIconElement ( iconSource , color ) }
107142 < Text style = { [ styles . text , textStyle , { color } ] } > { options [ i ] } </ Text >
0 commit comments