Skip to content

Commit

Permalink
Merge branch 'main' into upgrade/react-native-reanimated
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-solecki committed Mar 5, 2024
2 parents 210c5ee + 9411a08 commit 2f3e3fb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 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
1 change: 1 addition & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ function MoneyRequestConfirmationList(props) {
/>
) : (
<ButtonWithDropdownMenu
success
pressOnEnter
isDisabled={shouldDisableButton}
onPress={(_event, value) => confirm(value)}
Expand Down
8 changes: 4 additions & 4 deletions src/components/MultiGestureCanvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ function MultiGestureCanvas({
const reset = useWorkletCallback((animated: boolean, callback?: () => void) => {
stopAnimation();

offsetX.value = 0;
offsetY.value = 0;
pinchScale.value = 1;

if (animated) {
offsetX.value = 0;
offsetY.value = 0;
panTranslateX.value = withSpring(0, SPRING_CONFIG);
panTranslateY.value = withSpring(0, SPRING_CONFIG);
pinchTranslateX.value = withSpring(0, SPRING_CONFIG);
Expand All @@ -128,8 +130,6 @@ function MultiGestureCanvas({
return;
}

offsetX.value = 0;
offsetY.value = 0;
panTranslateX.value = 0;
panTranslateY.value = 0;
pinchTranslateX.value = 0;
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
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function HeaderView(props) {
),
);

const canJoinOrLeave = isChatThread || !isSelfDM || isUserCreatedPolicyRoom || canLeaveRoom;
const canJoinOrLeave = !isSelfDM && (isChatThread || isUserCreatedPolicyRoom || canLeaveRoom);
const canJoin = canJoinOrLeave && !isWhisperAction && props.report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const canLeave = canJoinOrLeave && ((isChatThread && props.report.notificationPreference.length) || isUserCreatedPolicyRoom || canLeaveRoom);
if (canJoin) {
Expand Down

0 comments on commit 2f3e3fb

Please sign in to comment.