Open bobbyziom opened 1 month ago
I solved it with useAnimatedReaction.
const scrollPosition = useSharedValue(0);
let centeredElement: number | undefined;
const onCenterItemChange = (currentIndex: any) => {
if (centeredElement != currentIndex) {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Soft)
centeredElement = currentIndex;
}};
useAnimatedReaction(
() => Math.round(scrollPosition.value),
(currentIndex) => {
runOnJS(onCenterItemChange)(currentIndex);
},
[scrollPosition] );
<Carousel
...
onProgressChange={(_, absoluteProgress) => {
scrollPosition.value = absoluteProgress;
}}>
...
Working with the circlular carousel, and I'm missing one feature
Wondering if there is a way to fire an event (e.g. haptic) when an item is passing by the center.
I've tried both onScrollEnd and ProgressChange trying to convert the absolute valute to index and then firing. But when scrolling faster it seems to not be possible.
Basically just the implementation from examples im playing with atm.