Skip to content

Commit

Permalink
prevent swiping down when scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Nov 13, 2024
1 parent 4e53b33 commit d55ddee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Attachments/AttachmentCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
const styles = useThemeStyles();
const {isFullScreenRef} = useFullScreenContext();
const scrollRef = useAnimatedRef<Animated.FlatList<ListRenderItemInfo<Attachment>>>();
const nope = useSharedValue(false);
const isPagerScrolling = useSharedValue(false);
const pagerRef = useRef<GestureType>(null);
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {canEvict: false});
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false});
Expand Down Expand Up @@ -200,13 +200,13 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
pagerItems: [{source, index: 0, isActive: true}],
activePage: 0,
pagerRef,
isPagerScrolling: nope,
isPagerScrolling,
isScrollEnabled,
onTap: handleTap,
onScaleChanged: handleScaleChange,
onSwipeDown: onClose,
}),
[source, nope, isScrollEnabled, handleTap, handleScaleChange, onClose],
[source, isPagerScrolling, isScrollEnabled, handleTap, handleScaleChange, onClose],
);

/** Defines how a single attachment should be rendered */
Expand All @@ -233,6 +233,10 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
return;
}

if (translationX !== 0) {
isPagerScrolling.value = true;
}

scrollTo(scrollRef, page * cellWidth - translationX, 0, false);
})
.onEnd(({translationX, velocityX}) => {
Expand All @@ -253,6 +257,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
newIndex = Math.min(attachments.length - 1, Math.max(0, page + delta));
}

isPagerScrolling.value = false;
scrollTo(scrollRef, newIndex * cellWidth, 0, true);
})
// eslint-disable-next-line react-compiler/react-compiler
Expand Down

0 comments on commit d55ddee

Please sign in to comment.