@@ -12,6 +12,7 @@ const Batchinator = require('../Interaction/Batchinator');
12
12
const FillRateHelper = require ( './FillRateHelper' ) ;
13
13
const ReactNative = require ( '../Renderer/shims/ReactNative' ) ;
14
14
const RefreshControl = require ( '../Components/RefreshControl/RefreshControl' ) ;
15
+ const Platform = require ( '../Utilities/Platform' ) ;
15
16
const ScrollView = require ( '../Components/ScrollView/ScrollView' ) ;
16
17
const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
17
18
const View = require ( '../Components/View/View' ) ;
@@ -52,10 +53,20 @@ export type Separators = {
52
53
...
53
54
} ;
54
55
56
+ export type AccessibilityCollectionItem = {
57
+ itemIndex : number ,
58
+ rowIndex : number ,
59
+ rowSpan : number ,
60
+ columnIndex : number ,
61
+ columnSpan : number ,
62
+ heading : boolean ,
63
+ } ;
64
+
55
65
export type RenderItemProps < ItemT > = {
56
66
item : ItemT ,
57
67
index : number ,
58
68
separators : Separators ,
69
+ accessibilityCollectionItem : AccessibilityCollectionItem ,
59
70
...
60
71
} ;
61
72
@@ -84,9 +95,19 @@ type RequiredProps = {|
84
95
*/
85
96
getItem : ( data : any , index : number ) => ?Item ,
86
97
/**
87
- * Determines how many items are in the data blob.
98
+ * Determines how many items (rows) are in the data blob.
88
99
*/
89
100
getItemCount : ( data : any ) => number ,
101
+ /**
102
+ * Determines how many cells are in the data blob
103
+ * see https://bit.ly/35RKX7H
104
+ */
105
+ getCellsInItemCount ?: ( data : any ) => number ,
106
+ /**
107
+ * The number of columns used in FlatList.
108
+ * The default of 1 is used in other components to calculate the accessibilityCollection prop.
109
+ */
110
+ numColumns ?: ?number ,
90
111
| } ;
91
112
type OptionalProps = { |
92
113
renderItem ?: ?RenderItemType < Item > ,
@@ -306,6 +327,10 @@ type Props = {|
306
327
...OptionalProps ,
307
328
| } ;
308
329
330
+ function numColumnsOrDefault ( numColumns : ?number ) {
331
+ return numColumns ?? 1 ;
332
+ }
333
+
309
334
let _usedIndexForKey = false ;
310
335
let _keylessItemComponentName : string = '' ;
311
336
@@ -1242,8 +1267,33 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1242
1267
) ;
1243
1268
}
1244
1269
1270
+ _getCellsInItemCount = props => {
1271
+ const { getCellsInItemCount, data} = props ;
1272
+ if ( getCellsInItemCount ) {
1273
+ return getCellsInItemCount ( data ) ;
1274
+ }
1275
+ if ( Array . isArray ( data ) ) {
1276
+ return data . length ;
1277
+ }
1278
+ return 0 ;
1279
+ } ;
1280
+
1245
1281
_defaultRenderScrollComponent = props => {
1282
+ const { getItemCount, data} = props ;
1246
1283
const onRefresh = props . onRefresh ;
1284
+ const numColumns = numColumnsOrDefault ( props . numColumns ) ;
1285
+ const accessibilityRole = Platform . select ( {
1286
+ android : numColumns > 1 ? 'grid' : 'list' ,
1287
+ } ) ;
1288
+ const rowCount = getItemCount ( data ) ;
1289
+ const accessibilityCollection = {
1290
+ // over-ride _getCellsInItemCount to handle Objects or other data formats
1291
+ // see https://bit.ly/35RKX7H
1292
+ itemCount : this . _getCellsInItemCount ( props ) ,
1293
+ rowCount,
1294
+ columnCount : numColumns ,
1295
+ hierarchical : false ,
1296
+ } ;
1247
1297
if ( this . _isNestedWithSameOrientation ( ) ) {
1248
1298
// $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
1249
1299
return < View { ...props } /> ;
@@ -1258,6 +1308,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1258
1308
// $FlowFixMe[prop-missing] Invalid prop usage
1259
1309
< ScrollView
1260
1310
{ ...props }
1311
+ accessibilityRole = { accessibilityRole }
1312
+ accessibilityCollection = { accessibilityCollection }
1261
1313
refreshControl = {
1262
1314
props . refreshControl == null ? (
1263
1315
< RefreshControl
@@ -1272,8 +1324,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1272
1324
/>
1273
1325
) ;
1274
1326
} else {
1275
- // $FlowFixMe[prop-missing] Invalid prop usage
1276
- return < ScrollView { ...props } /> ;
1327
+ return (
1328
+ // $FlowFixMe[prop-missing] Invalid prop usage
1329
+ < ScrollView
1330
+ { ...props }
1331
+ accessibilityRole = { accessibilityRole }
1332
+ accessibilityCollection = { accessibilityCollection }
1333
+ />
1334
+ ) ;
1277
1335
}
1278
1336
} ;
1279
1337
@@ -2018,10 +2076,19 @@ class CellRenderer extends React.Component<
2018
2076
}
2019
2077
2020
2078
if ( renderItem ) {
2079
+ const accessibilityCollectionItem = {
2080
+ itemIndex : index ,
2081
+ rowIndex : index ,
2082
+ rowSpan : 1 ,
2083
+ columnIndex : 0 ,
2084
+ columnSpan : 1 ,
2085
+ heading : false ,
2086
+ } ;
2021
2087
return renderItem ( {
2022
2088
item,
2023
2089
index,
2024
2090
separators : this . _separators ,
2091
+ accessibilityCollectionItem,
2025
2092
} ) ;
2026
2093
}
2027
2094
0 commit comments