11'use strict' ;
2- import { Text , FlatList , View } from 'react-native' ;
2+ import { Text , FlatList , View , Pressable } from 'react-native' ;
33import React from 'react' ;
44import { Example } from '../components/Example' ;
55import { Page } from '../components/Page' ;
@@ -96,11 +96,11 @@ export const FlatListExamplePage: React.FunctionComponent<{navigation?: any}> =
9696
9797 const example1jsx = `<FlatList
9898 data={Data}
99- renderItem={renderItem }
99+ renderItem={renderAccessibleItem }
100100 keyExtractor={(item) => item.id}/>` ;
101101 const example2jsx = `<FlatList
102102 data={Data}
103- renderItem={renderItem }
103+ renderItem={renderAccessibleItem }
104104 keyExtractor={(item) => item.id}
105105 ListHeaderComponent={
106106 <Text style={{fontStyle: 'italic'}}>
@@ -114,26 +114,68 @@ export const FlatListExamplePage: React.FunctionComponent<{navigation?: any}> =
114114 }/>` ;
115115 const example3jsx = `<FlatList
116116 data={Data}
117- renderItem={renderItem }
117+ renderItem={renderAccessibleItem }
118118 keyExtractor={(item) => item.id}
119119 horizontal={true}
120120 inverted={true}/>` ;
121- const example4jsx = `<FlatList
122- data={Data}
123- renderItem={renderItem}
124- keyExtractor={(item) => item.id}
125- initialNumToRender={3}
126- style={{height: 50}}/>` ;
121+ const example4jsx = `<View style={{height: 150, backgroundColor: colors.card, borderRadius: 8, padding: 5}}>
122+ <FlatList
123+ data={Data}
124+ renderItem={renderAccessibleItem}
125+ keyExtractor={(item) => item.id}
126+ initialNumToRender={10}
127+ showsVerticalScrollIndicator={true}
128+ style={{flex: 1}}
129+ contentContainerStyle={{paddingVertical: 5}}
130+ accessible={true}
131+ accessibilityLabel="Scrollable list of items in a fixed height container"
132+ accessibilityHint="Use arrow keys to navigate through the list items"
133+ />
134+ </View>` ;
127135 const example5jsx = `<FlatList
128136 data={Data}
129- renderItem={renderItem }
137+ renderItem={renderAccessibleItem }
130138 keyExtractor={(item) => item.id}
131139 numColumns={3}/>` ;
132140
133- const renderItem = ( { item} ) => (
134- < View style = { { padding : 5 } } >
141+ const renderItem = ( { item} : { item : any } ) => (
142+ < Pressable
143+ style = { { padding : 5 } }
144+ accessibilityRole = "button"
145+ accessibilityLabel = { `List item: ${ item . title } ` }
146+ onPress = { ( ) => {
147+ // Handle item selection - for demo purposes, could show selection state
148+ console . log ( `Selected: ${ item . title } ` ) ;
149+ } }
150+ onAccessibilityTap = { ( ) => {
151+ console . log ( `Accessibility tap: ${ item . title } ` ) ;
152+ } } >
135153 < Text style = { { color : colors . text } } > { item . title } </ Text >
136- </ View >
154+ </ Pressable >
155+ ) ;
156+
157+ // Create a specialized render function for the fixed-height example to improve accessibility
158+ const renderAccessibleItem = ( { item} : { item : any } ) => (
159+ < Pressable
160+ style = { {
161+ padding : 10 ,
162+ marginVertical : 2 ,
163+ backgroundColor : colors . background ,
164+ borderWidth : 1 ,
165+ borderColor : colors . border ,
166+ borderRadius : 4 ,
167+ } }
168+ accessibilityRole = "button"
169+ accessibilityLabel = { `List item ${ item . id } : ${ item . title } ` }
170+ accessibilityHint = "Tap to select this item"
171+ onPress = { ( ) => {
172+ console . log ( `Selected: ${ item . title } ` ) ;
173+ } }
174+ onAccessibilityTap = { ( ) => {
175+ console . log ( `Accessibility tap: ${ item . title } ` ) ;
176+ } } >
177+ < Text style = { { color : colors . text , fontSize : 14 } } > { item . title } </ Text >
178+ </ Pressable >
137179 ) ;
138180
139181 return (
@@ -155,14 +197,14 @@ export const FlatListExamplePage: React.FunctionComponent<{navigation?: any}> =
155197 < Example ref = { firstFlatListRef } title = "A simple FlatList." code = { example1jsx } >
156198 < FlatList
157199 data = { Data }
158- renderItem = { renderItem }
200+ renderItem = { renderAccessibleItem }
159201 keyExtractor = { ( item ) => item . id }
160202 />
161203 </ Example >
162204 < Example title = "A FlatList with header and footer." code = { example2jsx } >
163205 < FlatList
164206 data = { Data }
165- renderItem = { renderItem }
207+ renderItem = { renderAccessibleItem }
166208 keyExtractor = { ( item ) => item . id }
167209 ListHeaderComponent = {
168210 < Text style = { { fontStyle : 'italic' , color : colors . text } } >
@@ -181,7 +223,7 @@ export const FlatListExamplePage: React.FunctionComponent<{navigation?: any}> =
181223 code = { example3jsx } >
182224 < FlatList
183225 data = { Data }
184- renderItem = { renderItem }
226+ renderItem = { renderAccessibleItem }
185227 keyExtractor = { ( item ) => item . id }
186228 horizontal = { true }
187229 inverted = { true }
@@ -190,18 +232,25 @@ export const FlatListExamplePage: React.FunctionComponent<{navigation?: any}> =
190232 < Example
191233 title = "A FlatList inside of a fixed-height view."
192234 code = { example4jsx } >
193- < FlatList
194- data = { Data }
195- renderItem = { renderItem }
196- keyExtractor = { ( item ) => item . id }
197- initialNumToRender = { 10 }
198- style = { { height : 50 } }
199- />
235+ < View style = { { height : 150 , backgroundColor : colors . card , borderRadius : 8 , padding : 5 } } >
236+ < FlatList
237+ data = { Data }
238+ renderItem = { renderAccessibleItem }
239+ keyExtractor = { ( item ) => item . id }
240+ initialNumToRender = { 10 }
241+ showsVerticalScrollIndicator = { true }
242+ style = { { flex : 1 } }
243+ contentContainerStyle = { { paddingVertical : 5 } }
244+ accessible = { true }
245+ accessibilityLabel = "Scrollable list of items in a fixed height container"
246+ accessibilityHint = "Use arrow keys to navigate through the list items"
247+ />
248+ </ View >
200249 </ Example >
201250 < Example title = "A mutli-column FlatList." code = { example5jsx } >
202251 < FlatList
203252 data = { Data }
204- renderItem = { renderItem }
253+ renderItem = { renderAccessibleItem }
205254 keyExtractor = { ( item ) => item . id }
206255 numColumns = { 3 }
207256 />
0 commit comments