@@ -42,6 +42,7 @@ const ScrollView = require('../Components/ScrollView/ScrollView');
4242const View = require ( '../Components/View/View' ) ;
4343const Batchinator = require ( '../Interaction/Batchinator' ) ;
4444const ReactNative = require ( '../Renderer/shims/ReactNative' ) ;
45+ const Platform = require ( '../Utilities/Platform' ) ;
4546const flattenStyle = require ( '../StyleSheet/flattenStyle' ) ;
4647const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
4748const infoLog = require ( '../Utilities/infoLog' ) ;
@@ -74,6 +75,11 @@ type State = {
7475 * Use the following helper functions for default values
7576 */
7677
78+ // numColumnsOrDefault(this.props.numColumns)
79+ function numColumnsOrDefault ( numColumns : ?number ) {
80+ return numColumns ?? 1 ;
81+ }
82+
7783// horizontalOrDefault(this.props.horizontal)
7884function horizontalOrDefault ( horizontal : ?boolean ) {
7985 return horizontal ?? false ;
@@ -1010,10 +1016,35 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10101016 ) ;
10111017 }
10121018
1019+ _getCellsInItemCount = ( props : Props ) => {
1020+ const { getCellsInItemCount, data} = props ;
1021+ if ( getCellsInItemCount ) {
1022+ return getCellsInItemCount ( data ) ;
1023+ }
1024+ if ( Array . isArray ( data ) ) {
1025+ return data . length ;
1026+ }
1027+ return 0 ;
1028+ } ;
1029+
10131030 /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
10141031 * LTI update could not be added via codemod */
10151032 _defaultRenderScrollComponent = props => {
1033+ const { getItemCount, data} = props ;
10161034 const onRefresh = props . onRefresh ;
1035+ const numColumns = numColumnsOrDefault ( props . numColumns ) ;
1036+ const accessibilityRole = Platform . select ( {
1037+ android : numColumns > 1 ? 'grid' : 'list' ,
1038+ } ) ;
1039+ const rowCount = getItemCount ( data ) ;
1040+ const accessibilityCollection = {
1041+ // over-ride _getCellsInItemCount to handle Objects or other data formats
1042+ // see https://bit.ly/35RKX7H
1043+ itemCount : this . _getCellsInItemCount ( props ) ,
1044+ rowCount,
1045+ columnCount : numColumns ,
1046+ hierarchical : false ,
1047+ } ;
10171048 if ( this . _isNestedWithSameOrientation ( ) ) {
10181049 // $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
10191050 return < View { ...props } /> ;
@@ -1028,6 +1059,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10281059 // $FlowFixMe[prop-missing] Invalid prop usage
10291060 < ScrollView
10301061 { ...props }
1062+ accessibilityRole = { accessibilityRole }
1063+ accessibilityCollection = { accessibilityCollection }
10311064 refreshControl = {
10321065 props . refreshControl == null ? (
10331066 < RefreshControl
@@ -1043,8 +1076,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10431076 />
10441077 ) ;
10451078 } else {
1046- // $FlowFixMe[prop-missing] Invalid prop usage
1047- return < ScrollView { ...props } /> ;
1079+ return (
1080+ // $FlowFixMe[prop-missing] Invalid prop usage
1081+ < ScrollView
1082+ { ...props }
1083+ accessibilityRole = { accessibilityRole }
1084+ accessibilityCollection = { accessibilityCollection }
1085+ />
1086+ ) ;
10481087 }
10491088 } ;
10501089
@@ -1821,10 +1860,19 @@ class CellRenderer extends React.Component<
18211860 }
18221861
18231862 if ( renderItem ) {
1863+ const accessibilityCollectionItem = {
1864+ itemIndex : index ,
1865+ rowIndex : index ,
1866+ rowSpan : 1 ,
1867+ columnIndex : 0 ,
1868+ columnSpan : 1 ,
1869+ heading : false ,
1870+ } ;
18241871 return renderItem ( {
18251872 item,
18261873 index,
18271874 separators : this . _separators ,
1875+ accessibilityCollectionItem,
18281876 } ) ;
18291877 }
18301878
0 commit comments