@@ -35,6 +35,7 @@ const ScrollView = require('../Components/ScrollView/ScrollView');
3535const View = require ( '../Components/View/View' ) ;
3636const Batchinator = require ( '../Interaction/Batchinator' ) ;
3737const ReactNative = require ( '../Renderer/shims/ReactNative' ) ;
38+ const Platform = require ( '../Utilities/Platform' ) ;
3839const flattenStyle = require ( '../StyleSheet/flattenStyle' ) ;
3940const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
4041const infoLog = require ( '../Utilities/infoLog' ) ;
@@ -53,10 +54,20 @@ export type Separators = {
5354 ...
5455} ;
5556
57+ export type AccessibilityCollectionItem = {
58+ itemIndex : number ,
59+ rowIndex : number ,
60+ rowSpan : number ,
61+ columnIndex : number ,
62+ columnSpan : number ,
63+ heading : boolean ,
64+ } ;
65+
5666export type RenderItemProps < ItemT > = {
5767 item : ItemT ,
5868 index : number ,
5969 separators : Separators ,
70+ accessibilityCollectionItem : AccessibilityCollectionItem ,
6071 ...
6172} ;
6273
@@ -85,9 +96,19 @@ type RequiredProps = {|
8596 */
8697 getItem : ( data : any , index : number ) => ?Item ,
8798 /**
88- * Determines how many items are in the data blob.
99+ * Determines how many items (rows) are in the data blob.
89100 */
90101 getItemCount : ( data : any ) => number ,
102+ /**
103+ * Determines how many cells are in the data blob
104+ * see https://bit.ly/35RKX7H
105+ */
106+ getCellsInItemCount ?: ( data : any ) => number ,
107+ /**
108+ * The number of columns used in FlatList.
109+ * The default of 1 is used in other components to calculate the accessibilityCollection prop.
110+ */
111+ numColumns ?: ?number ,
91112| } ;
92113type OptionalProps = { |
93114 renderItem ?: ?RenderItemType < Item > ,
@@ -308,6 +329,10 @@ type Props = {|
308329 ...OptionalProps ,
309330| } ;
310331
332+ function numColumnsOrDefault ( numColumns : ?number ) {
333+ return numColumns ?? 1 ;
334+ }
335+
311336let _usedIndexForKey = false ;
312337let _keylessItemComponentName : string = '' ;
313338
@@ -1253,8 +1278,33 @@ class VirtualizedList extends React.PureComponent<Props, State> {
12531278 ) ;
12541279 }
12551280
1281+ _getCellsInItemCount = props => {
1282+ const { getCellsInItemCount, data} = props ;
1283+ if ( getCellsInItemCount ) {
1284+ return getCellsInItemCount ( data ) ;
1285+ }
1286+ if ( Array . isArray ( data ) ) {
1287+ return data . length ;
1288+ }
1289+ return 0 ;
1290+ } ;
1291+
12561292 _defaultRenderScrollComponent = props => {
1293+ const { getItemCount, data} = props ;
12571294 const onRefresh = props . onRefresh ;
1295+ const numColumns = numColumnsOrDefault ( props . numColumns ) ;
1296+ const accessibilityRole = Platform . select ( {
1297+ android : numColumns > 1 ? 'grid' : 'list' ,
1298+ } ) ;
1299+ const rowCount = getItemCount ( data ) ;
1300+ const accessibilityCollection = {
1301+ // over-ride _getCellsInItemCount to handle Objects or other data formats
1302+ // see https://bit.ly/35RKX7H
1303+ itemCount : this . _getCellsInItemCount ( props ) ,
1304+ rowCount,
1305+ columnCount : numColumns ,
1306+ hierarchical : false ,
1307+ } ;
12581308 if ( this . _isNestedWithSameOrientation ( ) ) {
12591309 // $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
12601310 return < View { ...props } /> ;
@@ -1269,6 +1319,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
12691319 // $FlowFixMe[prop-missing] Invalid prop usage
12701320 < ScrollView
12711321 { ...props }
1322+ accessibilityRole = { accessibilityRole }
1323+ accessibilityCollection = { accessibilityCollection }
12721324 refreshControl = {
12731325 props . refreshControl == null ? (
12741326 < RefreshControl
@@ -1284,8 +1336,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
12841336 />
12851337 ) ;
12861338 } else {
1287- // $FlowFixMe[prop-missing] Invalid prop usage
1288- return < ScrollView { ...props } /> ;
1339+ return (
1340+ // $FlowFixMe[prop-missing] Invalid prop usage
1341+ < ScrollView
1342+ { ...props }
1343+ accessibilityRole = { accessibilityRole }
1344+ accessibilityCollection = { accessibilityCollection }
1345+ />
1346+ ) ;
12891347 }
12901348 } ;
12911349
@@ -2056,10 +2114,19 @@ class CellRenderer extends React.Component<
20562114 }
20572115
20582116 if ( renderItem ) {
2117+ const accessibilityCollectionItem = {
2118+ itemIndex : index ,
2119+ rowIndex : index ,
2120+ rowSpan : 1 ,
2121+ columnIndex : 0 ,
2122+ columnSpan : 1 ,
2123+ heading : false ,
2124+ } ;
20592125 return renderItem ( {
20602126 item,
20612127 index,
20622128 separators : this . _separators ,
2129+ accessibilityCollectionItem,
20632130 } ) ;
20642131 }
20652132
0 commit comments