Skip to content

Commit

Permalink
Merge pull request #25691 from Expensify/andrewli-fixstyling
Browse files Browse the repository at this point in the history
[CP Staging] Remove global styling in BaseHTMLEngineProvider

(cherry picked from commit c11abdc)
  • Loading branch information
mountiny authored and OSBotify committed Aug 22, 2023
1 parent 8e2c903 commit 93c6f30
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
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
11 changes: 3 additions & 8 deletions src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.js
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

0 comments on commit 93c6f30

Please sign in to comment.