Skip to content

Commit

Permalink
feat: expose scrollViewProps
Browse files Browse the repository at this point in the history
  • Loading branch information
r0b0t3d committed May 5, 2021
1 parent 8afff0c commit c264a28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
5 changes: 4 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type CarouselData = {
id: string;
source: ImageProps['source'];
url: string;
}
};

const data: CarouselData[] = [
{
Expand Down Expand Up @@ -113,6 +113,9 @@ export default function App() {
spaceHeadTail={20}
animatedPage={currentPage}
additionalPagesPerSide={3}
scrollViewProps={{
scrollEnabled: true,
}}
renderItem={({ item }) => {
return (
<Image
Expand Down
12 changes: 3 additions & 9 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Animated, {
useSharedValue,
useAnimatedScrollHandler,
runOnJS,
useAnimatedProps,
} from 'react-native-reanimated';
import type { CarouselProps, CarouselHandles } from '../types';
import PageItem from './PageItem';
Expand Down Expand Up @@ -42,6 +41,7 @@ function Carousel<TData>(
renderItem,
onPageChange,
animatedPage = useSharedValue(0),
scrollViewProps = {},
keyExtractor,
}: CarouselProps<TData>,
ref: Ref<CarouselHandles>
Expand Down Expand Up @@ -257,12 +257,6 @@ function Carousel<TData>(
[beginDrag, endDrag, refreshPage]
);

const scrollViewProps = useAnimatedProps(() => {
return {
scrollEnabled: !freeze.value,
};
}, []);

function renderPage(item: TData, i: number) {
const containerStyle = useMemo(() => {
if (firstItemAlignment === 'start') {
Expand Down Expand Up @@ -299,10 +293,11 @@ function Carousel<TData>(
<View style={[style]}>
<Animated.ScrollView
ref={scrollViewRef}
{...scrollViewProps}
style={styles.container}
horizontal
disableScrollViewPanResponder
disableIntervalMomentum={false}
disableIntervalMomentum
showsHorizontalScrollIndicator={false}
snapToOffsets={offsets}
snapToStart
Expand All @@ -314,7 +309,6 @@ function Carousel<TData>(
contentContainerStyle={{
paddingHorizontal: horizontalPadding,
}}
{...{ scrollViewProps }}
>
{pageItems.map(renderPage)}
</Animated.ScrollView>
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StyleProp, ViewStyle } from 'react-native';
import type { ScrollViewProps, StyleProp, ViewStyle } from 'react-native';
import type Animated from 'react-native-reanimated';

export type CarouselProps<T = any> = {
Expand All @@ -18,6 +18,7 @@ export type CarouselProps<T = any> = {
spaceBetween?: number;
spaceHeadTail?: number;
animatedPage?: Animated.SharedValue<number>;
scrollViewProps?: ScrollViewProps;
renderItem: (
data: { item: T; index?: number },
animatedData?: {
Expand Down

0 comments on commit c264a28

Please sign in to comment.