Skip to content

Commit 525100f

Browse files
fix: fix null check and tinder animation (#25)
1 parent 1f4bf50 commit 525100f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/CarouselMomentum.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const CarouselMomentum = <Item,>(
173173
: event.contentOffset.y; // Get the horizontal scroll offset
174174
scrollX.set(offsetX); // Update the scroll position for animations
175175
const nextIndex = Math.round(
176-
offsetX / (!vertical ? itemWidth : itemHeight)
176+
offsetX / (!vertical ? itemWidth! : itemHeight!)
177177
); // Calculate the current index
178178
// If the index changes, call the onSnap callback
179179
if (nextIndex !== currentIndex) {
@@ -190,8 +190,8 @@ const CarouselMomentum = <Item,>(
190190
* This is used when we want to programmatically scroll to a specific item.
191191
*/
192192
const calculateItemOffsetStatic = useCallback(
193-
(index: number) => index * (!vertical ? itemWidth : itemHeight),
194-
[itemWidth, itemHeight]
193+
(index: number) => index * (!vertical ? itemWidth! : itemHeight!),
194+
[vertical, itemWidth, itemHeight]
195195
);
196196

197197
/**
@@ -322,11 +322,11 @@ const CarouselMomentum = <Item,>(
322322
itemStyle={itemStyle}
323323
renderItem={renderItem}
324324
info={info}
325-
itemWidth={itemWidth}
325+
itemWidth={itemWidth!}
326326
inactiveScale={inactiveScale}
327327
scrollX={scrollX}
328328
animation={animation}
329-
itemHeight={itemHeight}
329+
itemHeight={itemHeight!}
330330
vertical={vertical}
331331
customAnimation={customAnimation}
332332
/>
@@ -373,10 +373,10 @@ const CarouselMomentum = <Item,>(
373373
contentContainerStyle={
374374
!vertical
375375
? {
376-
paddingHorizontal: (sliderWidth - itemWidth) / 2, // Center the items within the container
376+
paddingHorizontal: (sliderWidth! - itemWidth!) / 2, // Center the items within the container
377377
}
378378
: {
379-
paddingVertical: (sliderHeight - itemHeight) / 2,
379+
paddingVertical: (sliderHeight! - itemHeight!) / 2,
380380
}
381381
}
382382
showsVerticalScrollIndicator={false}

src/useLayoutAnimation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function useLayoutTinderAnimation(data: ItemCarouselProps) {
159159
translateX: interpolate(
160160
data.scrollX.value,
161161
inputRange,
162-
[100, 0, data.itemWidth], // Move the item horizontally for the "stack" effect
162+
[100, 0, 100], // Move the item horizontally for the "stack" effect
163163
Extrapolation.CLAMP
164164
),
165165
},

0 commit comments

Comments
 (0)