Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix receipt image modal logic #26815

Merged
merged 2 commits into from
Sep 5, 2023
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
67 changes: 32 additions & 35 deletions src/components/ReportActionItem/ReportActionItemImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,44 @@ const defaultProps = {

function ReportActionItemImage({thumbnail, image, enablePreviewModal}) {
const {translate} = useLocalize();
const imageSource = tryResolveUrlFromApiRoot(image || '');
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail || '');

if (thumbnail) {
const imageSource = tryResolveUrlFromApiRoot(image);
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail);
const thumbnailComponent = (
<ThumbnailImage
previewSourceURL={thumbnailSource}
style={[styles.w100, styles.h100]}
isAuthTokenRequired
shouldDynamicallyResize={false}
/>
);

if (enablePreviewModal) {
return (
<ShowContextMenuContext.Consumer>
{({report}) => (
<PressableWithoutFocus
style={[styles.noOutline, styles.w100, styles.h100]}
onPress={() => {
const route = ROUTES.getReportAttachmentRoute(report.reportID, imageSource);
Navigation.navigate(route);
}}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={translate('accessibilityHints.viewAttachment')}
>
{thumbnailComponent}
</PressableWithoutFocus>
)}
</ShowContextMenuContext.Consumer>
);
}
return thumbnailComponent;
}

return (
const receiptImageComponent = thumbnail ? (
<ThumbnailImage
previewSourceURL={thumbnailSource}
style={[styles.w100, styles.h100]}
isAuthTokenRequired
shouldDynamicallyResize={false}
/>
) : (
<Image
source={{uri: image}}
style={[styles.w100, styles.h100]}
/>
);

if (enablePreviewModal) {
return (
<ShowContextMenuContext.Consumer>
{({report}) => (
<PressableWithoutFocus
style={[styles.noOutline, styles.w100, styles.h100]}
onPress={() => {
const route = ROUTES.getReportAttachmentRoute(report.reportID, imageSource);
Navigation.navigate(route);
}}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={translate('accessibilityHints.viewAttachment')}
>
{receiptImageComponent}
</PressableWithoutFocus>
)}
</ShowContextMenuContext.Consumer>
);
}

return receiptImageComponent;
}

ReportActionItemImage.propTypes = propTypes;
Expand Down