Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/components/Attachments/AttachmentCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {MutableRefObject} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {ListRenderItemInfo} from 'react-native';
import {Keyboard, PixelRatio, View} from 'react-native';
import type {GestureType} from 'react-native-gesture-handler';
import type {ComposedGesture, GestureType} from 'react-native-gesture-handler';
import {Gesture, GestureDetector} from 'react-native-gesture-handler';
import {useOnyx} from 'react-native-onyx';
import Animated, {scrollTo, useAnimatedRef, useSharedValue} from 'react-native-reanimated';
Expand Down Expand Up @@ -38,6 +38,19 @@ const viewabilityConfig = {

const MIN_FLING_VELOCITY = 500;

type DeviceAwareGestureDetectorProps = {
canUseTouchScreen: boolean;
gesture: ComposedGesture | GestureType;
children: React.ReactNode;
};

function DeviceAwareGestureDetector({canUseTouchScreen, gesture, children}: DeviceAwareGestureDetectorProps) {
// Don't render GestureDetector on non-touchable devices to prevent unexpected pointer event capture.
// This issue is left out on touchable devices since finger touch works fine.
// See: https://github.com/Expensify/App/issues/51246
return canUseTouchScreen ? <GestureDetector gesture={gesture}>{children}</GestureDetector> : children;
}

function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibility, type, accountID, onClose, attachmentLink}: AttachmentCarouselProps) {
const theme = useTheme();
const {translate} = useLocalize();
Expand Down Expand Up @@ -290,7 +303,10 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
cancelAutoHideArrow={cancelAutoHideArrows}
/>
<AttachmentCarouselPagerContext.Provider value={context}>
<GestureDetector gesture={pan}>
<DeviceAwareGestureDetector
canUseTouchScreen={canUseTouchScreen}
gesture={pan}
>
<Animated.FlatList
keyboardShouldPersistTaps="handled"
horizontal
Expand All @@ -309,7 +325,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi
viewabilityConfig={viewabilityConfig}
onViewableItemsChanged={updatePage}
/>
</GestureDetector>
</DeviceAwareGestureDetector>
</AttachmentCarouselPagerContext.Provider>

<CarouselActions onCycleThroughAttachments={cycleThroughAttachments} />
Expand Down