File tree 5 files changed +64
-31
lines changed
5 files changed +64
-31
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @react-native-ama/internal ' : minor
3
+ ' @react-native-ama/extras ' : minor
4
+ ' @react-native-ama/forms ' : minor
5
+ ' @react-native-ama/animations ' : minor
6
+ ' @react-native-ama/core ' : minor
7
+ ' @react-native-ama/lists ' : minor
8
+ ' @react-native-ama/react-native ' : minor
9
+ ---
10
+
11
+ Added Carousel and useCarousel to extras package
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import { FlatListProps } from 'react-native' ;
3
+ import { FlatList } from 'react-native-gesture-handler' ;
4
+
5
+ import { useCarousel } from '../hooks/useCarousel' ;
6
+
7
+ function fixedForwardRef < T , P = { } > (
8
+ render : ( props : P , ref : React . Ref < T > ) => React . ReactNode ,
9
+ ) : ( props : P & React . RefAttributes < T > ) => React . ReactNode {
10
+ return React . forwardRef ( render ) as any ;
11
+ }
12
+
13
+ export type CarouselProps < T = any > = Omit <
14
+ FlatListProps < T > ,
15
+ | 'accessibilityLabel'
16
+ | 'accessibilityRole'
17
+ | 'accessibilityActions'
18
+ | 'onAccessibilityAction'
19
+ > & {
20
+ accessibilityLabel : string ;
21
+ } ;
22
+
23
+ const CarouselInner = < T , > (
24
+ props : CarouselProps < T > ,
25
+ forwardedRef : React . ForwardedRef < FlatList < T > > ,
26
+ ) => {
27
+ const a11yProps = useCarousel ( {
28
+ data : props . data ,
29
+ flatListRef : forwardedRef ,
30
+ } ) ;
31
+
32
+ return (
33
+ < FlatList
34
+ ref = { forwardedRef }
35
+ showsHorizontalScrollIndicator = { false }
36
+ showsVerticalScrollIndicator = { false }
37
+ decelerationRate = "fast"
38
+ horizontal
39
+ { ...props }
40
+ { ...a11yProps }
41
+ />
42
+ ) ;
43
+ } ;
44
+
45
+ export const Carousel = fixedForwardRef ( CarouselInner ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import { useRef } from 'react' ;
2
+ // import { FlatList } from 'react-native';
2
3
import { FlatList } from 'react-native-gesture-handler' ;
3
4
import {
4
5
AccessibilityActionEvent ,
5
6
AccessibilityRole ,
6
7
} from 'react-native/types' ;
7
8
8
- type UseCarousel = {
9
- data : ArrayLike < any > | null | undefined ;
10
- flatListRef : React . ForwardedRef < FlatList < any > | null > ;
9
+ type UseCarousel < T > = {
10
+ data : ArrayLike < T > | null | undefined ;
11
+ flatListRef : React . Ref < FlatList < T > | null > ;
11
12
} ;
12
13
13
- export const useCarousel = ( { data, flatListRef } : UseCarousel ) => {
14
+ export const useCarousel = < T = any > ( { data, flatListRef } : UseCarousel < T > ) => {
14
15
const carouselIndexForScreenReader = useRef ( 0 ) ;
15
16
const totalItems = data ?. length || 0 ;
16
17
@@ -29,6 +30,7 @@ export const useCarousel = ({ data, flatListRef }: UseCarousel) => {
29
30
} ;
30
31
31
32
return {
33
+ accessible : true ,
32
34
accessibilityRole : 'adjustable' as AccessibilityRole ,
33
35
accessibilityActions,
34
36
onAccessibilityAction,
Original file line number Diff line number Diff line change 1
1
// Components
2
2
export { BottomSheet } from './components/BottomSheet' ;
3
+ export { Carousel } from './components/Carousel' ;
3
4
4
5
// Hooks
5
6
export { useBottomSheetGestureHandler } from './hooks/useBottomSheetGestureHandler' ;
6
7
export { useKeyboard } from './hooks/useKeyboard' ;
8
+ export { useCarousel } from './hooks/useCarousel' ;
You can’t perform that action at this time.
0 commit comments