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

[CP Staging] Remove global styling in BaseHTMLEngineProvider #25691

Merged
merged 1 commit into from
Aug 22, 2023
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 @@ -48,7 +48,7 @@ const customHTMLElementModels = {
'mention-here': defaultHTMLElementModels.span.extend({tagName: 'mention-here'}),
};

const defaultViewProps = {style: [styles.alignItemsStart, styles.userSelectText, styles.w100, styles.h100]};
const defaultViewProps = {style: [styles.alignItemsStart, styles.userSelectText]};

// We are using the explicit composite architecture for performance gains.
// Configuration for RenderHTML is handled in a top-level component providing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,19 @@ function ImageRenderer(props) {
const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;
const imagePreviewModalDisabled = htmlAttribs['data-expensify-preview-modal-disabled'] === 'true';

const shouldFitContainer = htmlAttribs['data-expensify-fit-container'] === 'true';
const sizingStyle = shouldFitContainer ? [styles.w100, styles.h100] : [];

return imagePreviewModalDisabled ? (
<ThumbnailImage
previewSourceURL={previewSource}
style={shouldFitContainer ? [styles.w100, styles.h100] : styles.webViewStyles.tagStyles.img}
style={styles.webViewStyles.tagStyles.img}
isAuthTokenRequired={isAttachmentOrReceipt}
imageWidth={imageWidth}
imageHeight={imageHeight}
shouldDynamicallyResize={!shouldFitContainer}
/>
) : (
<ShowContextMenuContext.Consumer>
{({anchor, report, action, checkIfContextMenuActive}) => (
<PressableWithoutFocus
style={[styles.noOutline, ...sizingStyle]}
style={[styles.noOutline]}
onPress={() => {
const route = ROUTES.getReportAttachmentRoute(report.reportID, source);
Navigation.navigate(route);
Expand All @@ -70,11 +66,10 @@ function ImageRenderer(props) {
>
<ThumbnailImage
previewSourceURL={previewSource}
style={shouldFitContainer ? [styles.w100, styles.h100] : styles.webViewStyles.tagStyles.img}
style={styles.webViewStyles.tagStyles.img}
isAuthTokenRequired={isAttachmentOrReceipt}
imageWidth={imageWidth}
imageHeight={imageHeight}
shouldDynamicallyResize={!shouldFitContainer}
/>
</PressableWithoutFocus>
)}
Expand Down
56 changes: 45 additions & 11 deletions src/components/ReportActionItem/ReportActionItemImage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
import RenderHTML from '../RenderHTML';
import Image from '../Image';
import ThumbnailImage from '../ThumbnailImage';
import tryResolveUrlFromApiRoot from '../../libs/tryResolveUrlFromApiRoot';
import ROUTES from '../../ROUTES';
import CONST from '../../CONST';
import {ShowContextMenuContext} from '../ShowContextMenuContext';
import Navigation from '../../libs/Navigation/Navigation';
import PressableWithoutFocus from '../Pressable/PressableWithoutFocus';
import useLocalize from '../../hooks/useLocalize';

const propTypes = {
/** thumbnail URI for the image */
Expand All @@ -20,20 +27,47 @@ const defaultProps = {
enablePreviewModal: false,
};

/**
* An image with an optional thumbnail that fills its parent container. If the thumbnail is passed,
* we try to resolve both the image and thumbnail from the API. Similar to ImageRenderer, we show
* and optional preview modal as well.
*/

function ReportActionItemImage({thumbnail, image, enablePreviewModal}) {
const {translate} = useLocalize();

if (thumbnail) {
return (
<RenderHTML
html={`
<img
src="${thumbnail}"
data-expensify-source="${image}"
data-expensify-fit-container="true"
data-expensify-preview-modal-disabled="${!enablePreviewModal}"
/>
`}
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 (
Expand Down
Loading