Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}: CarouselItemPr
isHovered={isModalHovered}
isFocused={isFocused}
duration={item.duration}
isUsedInCarousel
/>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ function AttachmentCarouselPager(
{items, activeSource, initialPage, setShouldShowArrows, onPageSelected, onClose}: AttachmentCarouselPagerProps,
ref: ForwardedRef<AttachmentCarouselPagerHandle>,
) {
const {handleTap, handleScaleChange} = useCarouselContextEvents(setShouldShowArrows);
const {handleTap, handleScaleChange, isScrollEnabled} = useCarouselContextEvents(setShouldShowArrows);
const styles = useThemeStyles();
const pagerRef = useRef<PagerView>(null);

const isPagerScrolling = useSharedValue(false);
const isScrollEnabled = useSharedValue(true);

const activePage = useSharedValue(initialPage);
const [activePageIndex, setActivePageIndex] = useState(initialPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function useCarouselContextEvents(setShouldShowArrows: (show?: SetStateAction<bo
onRequestToggleArrows();
}, [isScrollEnabled.value, onRequestToggleArrows]);

return {handleTap, handleScaleChange, scale};
return {handleTap, handleScaleChange, scale, isScrollEnabled};
}

export default useCarouselContextEvents;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function BaseAttachmentViewPdf({
file,
encryptedSourceUrl,
isFocused,
isUsedInCarousel,
onPress: onPressProp,
onScaleChanged: onScaleChangedProp,
onToggleKeyboard,
Expand Down Expand Up @@ -40,11 +39,11 @@ function BaseAttachmentViewPdf({
}

// When a pdf is shown in a carousel, we want to disable the pager scroll when the pdf is zoomed in
if (isUsedInCarousel && attachmentCarouselPagerContext) {
if (attachmentCarouselPagerContext?.pagerRef) {
attachmentCarouselPagerContext.onScaleChanged(newScale);
}
},
[attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp],
[attachmentCarouselPagerContext, onScaleChangedProp],
);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {StyleProp, ViewStyle} from 'react-native';
import type {AttachmentViewProps} from '..';

type AttachmentViewPdfProps = Pick<AttachmentViewProps, 'file' | 'onPress' | 'isUsedInCarousel' | 'isFocused' | 'onToggleKeyboard'> & {
type AttachmentViewPdfProps = Pick<AttachmentViewProps, 'file' | 'onPress' | 'isFocused' | 'onToggleKeyboard'> & {
encryptedSourceUrl: string;
onLoadComplete: (path: string) => void;

Expand Down
9 changes: 4 additions & 5 deletions src/components/Attachments/AttachmentView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Str} from 'expensify-common';
import React, {memo, useEffect, useState} from 'react';
import React, {memo, useContext, useEffect, useState} from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import type {Attachment, AttachmentSource} from '@components/Attachments/types';
import DistanceEReceipt from '@components/DistanceEReceipt';
import EReceipt from '@components/EReceipt';
Expand Down Expand Up @@ -42,9 +43,6 @@ type AttachmentViewProps = AttachmentViewOnyxProps &
/** Function for handle on press */
onPress?: (e?: GestureResponderEvent | KeyboardEvent) => void;

/** Whether this AttachmentView is shown as part of a AttachmentCarousel */
isUsedInCarousel?: boolean;

isUsedInAttachmentModal?: boolean;

/** Flag to show/hide download icon */
Expand Down Expand Up @@ -89,7 +87,6 @@ function AttachmentView({
containerStyles,
onToggleKeyboard,
isFocused,
isUsedInCarousel,
isUsedInAttachmentModal,
isWorkspaceAvatar,
maybeIcon,
Expand All @@ -103,13 +100,15 @@ function AttachmentView({
}: AttachmentViewProps) {
const {translate} = useLocalize();
const {updateCurrentlyPlayingURL} = usePlaybackContext();
const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext);
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const [loadComplete, setLoadComplete] = useState(false);
const [isHighResolution, setIsHighResolution] = useState<boolean>(false);
const [hasPDFFailedToLoad, setHasPDFFailedToLoad] = useState(false);
const isVideo = (typeof source === 'string' && Str.isVideo(source)) || (file?.name && Str.isVideo(file.name));
const isUsedInCarousel = !!attachmentCarouselPagerContext?.pagerRef;

useEffect(() => {
if (!isFocused && !(file && isUsedInAttachmentModal)) {
Expand Down