Skip to content

Commit

Permalink
Merge pull request #37630 from margelo/fix/freezing-swipe-down-to-clo…
Browse files Browse the repository at this point in the history
…se-gesture

fix: no action after swipe down to close action
  • Loading branch information
youssef-lr authored Mar 5, 2024
2 parents e7a067d + a534558 commit 9c49ab6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
45 changes: 32 additions & 13 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Animated, Keyboard, View} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {useSharedValue} from 'react-native-reanimated';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -28,6 +29,7 @@ import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type ModalType from '@src/types/utils/ModalType';
import AttachmentCarousel from './Attachments/AttachmentCarousel';
import AttachmentCarouselPagerContext from './Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import AttachmentView from './Attachments/AttachmentView';
import BlockingView from './BlockingViews/BlockingView';
import Button from './Button';
Expand Down Expand Up @@ -184,6 +186,7 @@ function AttachmentModal({
const [isConfirmButtonDisabled, setIsConfirmButtonDisabled] = useState(false);
const [confirmButtonFadeAnimation] = useState(() => new Animated.Value(1));
const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true);
const nope = useSharedValue(false);
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const isOverlayModalVisible = (isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!isReceiptAttachment && isAttachmentInvalid);

Expand Down Expand Up @@ -466,6 +469,19 @@ function AttachmentModal({
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !isReceiptAttachment && !isOffline;
shouldShowThreeDotsButton = isReceiptAttachment && isModalOpen && threeDotsMenuItems.length !== 0;
}
const context = useMemo(
() => ({
pagerItems: [],
activePage: 0,
pagerRef: undefined,
isPagerScrolling: nope,
isScrollEnabled: nope,
onTap: () => {},
onScaleChanged: () => {},
onSwipeDown: closeModal,
}),
[closeModal, nope],
);

return (
<>
Expand Down Expand Up @@ -518,6 +534,7 @@ function AttachmentModal({
<AttachmentCarousel
report={report}
onNavigate={onNavigate}
onClose={closeModal}
source={source}
onToggleKeyboard={updateConfirmButtonVisibility}
setDownloadButtonVisibility={setDownloadButtonVisibility}
Expand All @@ -527,19 +544,21 @@ function AttachmentModal({
shouldLoadAttachment &&
!isLoading &&
!shouldShowNotFoundPage && (
<AttachmentView
// @ts-expect-error TODO: Remove this once Attachments (https://github.com/Expensify/App/issues/24969) is migrated to TypeScript.
containerStyles={[styles.mh5]}
source={sourceForAttachmentView}
isAuthTokenRequired={isAuthTokenRequired}
file={file}
onToggleKeyboard={updateConfirmButtonVisibility}
isWorkspaceAvatar={isWorkspaceAvatar}
maybeIcon={maybeIcon}
fallbackSource={fallbackSource}
isUsedInAttachmentModal
transactionID={transaction?.transactionID}
/>
<AttachmentCarouselPagerContext.Provider value={context}>
<AttachmentView
// @ts-expect-error TODO: Remove this once Attachments (https://github.com/Expensify/App/issues/24969) is migrated to TypeScript.
containerStyles={[styles.mh5]}
source={sourceForAttachmentView}
isAuthTokenRequired={isAuthTokenRequired}
file={file}
onToggleKeyboard={updateConfirmButtonVisibility}
isWorkspaceAvatar={isWorkspaceAvatar}
maybeIcon={maybeIcon}
fallbackSource={fallbackSource}
isUsedInAttachmentModal
transactionID={transaction?.transactionID}
/>
</AttachmentCarouselPagerContext.Provider>
)
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type AttachmentCarouselPagerContextValue = {

/** The index of the active page */
activePage: number;
pagerRef: ForwardedRef<PagerView>;
pagerRef?: ForwardedRef<PagerView>;
isPagerScrolling: SharedValue<boolean>;
isScrollEnabled: SharedValue<boolean>;
onTap: () => void;
Expand Down
8 changes: 2 additions & 6 deletions src/components/Attachments/AttachmentCarousel/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import extractAttachmentsFromReport from './extractAttachmentsFromReport';
import AttachmentCarouselPager from './Pager';
import useCarouselArrows from './useCarouselArrows';

function AttachmentCarousel({report, reportActions, parentReportActions, source, onNavigate, setDownloadButtonVisibility, translate}) {
function AttachmentCarousel({report, reportActions, parentReportActions, source, onNavigate, setDownloadButtonVisibility, translate, onClose}) {
const styles = useThemeStyles();
const pagerRef = useRef(null);
const [page, setPage] = useState();
Expand Down Expand Up @@ -102,10 +102,6 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
[setShouldShowArrows],
);

const goBack = useCallback(() => {
Navigation.goBack();
}, []);

const containerStyles = [styles.flex1, styles.attachmentCarouselContainer];

if (page == null) {
Expand Down Expand Up @@ -143,7 +139,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
activeSource={activeSource}
onRequestToggleArrows={toggleArrows}
onPageSelected={({nativeEvent: {position: newPage}}) => updatePage(newPage)}
onClose={goBack}
onClose={onClose}
ref={pagerRef}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Lightbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Lightbox({isAuthTokenRequired = false, uri, onScaleChanged: onScaleChan
const foundPage = attachmentCarouselPagerContext.pagerItems.findIndex((item) => item.source === uri);
return {
...attachmentCarouselPagerContext,
isUsedInCarousel: true,
isUsedInCarousel: !!attachmentCarouselPagerContext.pagerRef,
isSingleCarouselItem: attachmentCarouselPagerContext.pagerItems.length === 1,
page: foundPage,
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/MultiGestureCanvas/usePanGesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ const usePanGesture = ({
if (finalTranslateY > SNAP_POINT && zoomScale.value <= 1) {
offsetY.value = withSpring(SNAP_POINT_HIDDEN, SPRING_CONFIG, () => {
isSwipingDownToClose.value = false;
});

if (onSwipeDown) {
runOnJS(onSwipeDown)();
}
if (onSwipeDown) {
runOnJS(onSwipeDown)();
}
});
} else {
// Animated back to the boundary
offsetY.value = withSpring(clampedOffset.y, SPRING_CONFIG, () => {
Expand Down

0 comments on commit 9c49ab6

Please sign in to comment.