Skip to main content

Carousel

AMA Provides an accessible Carousel component built on top of React Native FlatList using the useCarousel hook.

Example

import { Carousel } from '@react-native-ama/extras';

const Component = () => {
const data = [
{ key: '1', image: image_1 },
{ key: '2', image: image_2 },
{ key: '3', image: image_3 },
];
const ref = React.useRef<FlatList<(typeof data)[number]>>(null);

const renderItem: ListRenderItem<(typeof data)[number]> = ({ item }) => {
return <Image source={item.image} resizeMode="cover" />;
};

return (
<Carousel
ref={ref}
accessibilityLabel="Carousel of dog portraits"
data={data}
renderItem={renderItem}
/>
);
};

Accessibility

  • Provides / abstracts accessibilityActions array to Carousel with increment and decrement actions
  • Provides / abstracts onAccessibilityAction handler to Carousel to manage the AccessibilityActionEvent change and scroll to the new index in the FlatList
  • Provides / abstracts accessibilityRole to Carousel as adjustable/ slider

Props

Required ref

The carousel reference provides access to underlying FlatList methods and is required for accessibility actions to work on iOS.

TypeDefault
React.RefObject<FlatList<ItemT>>undefined

Required accessibilityLabel

The accessibilityLabel is required and should describe what the carousel displays, this is announced by the screen reader when the element gains focus, then it announces its role ('adjustable').

TypeDefault
stringundefined

Required data (Inherited from FlatList)

An array (or array-like list) of items to render. Other data types can be used by targeting VirtualizedList directly.

TypeDefault
ArrayLike<ItemT> | null | undefinedundefined

Required renderItem (Inherited from FlatList)

Takes an item from data and renders it into the list. Typical usage:

const renderItem = ({item}) => (
<TouchableOpacity onPress={() => onPress(item)}>
<Text>{item.title}</Text>
</TouchableOpacity>
);

...

<FlatList data={[{title: 'Title Text', key: 'item1'}]} renderItem={renderItem} />

Provides additional metadata like index if you need it.

TypeDefault
ListRenderItem<ItemT> | null | undefinedundefined