-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
...so the logic for rendering attachments is clearly separated from the logic for rendering textual comments. This fixes #25415
- Loading branch information
Showing
5 changed files
with
184 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/pages/home/report/comment/AttachmentCommentFragment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../../../styles/styles'; | ||
import RenderCommentHTML from './RenderCommentHTML'; | ||
|
||
const propTypes = { | ||
/** The reportAction's source */ | ||
source: PropTypes.oneOf(['Chronos', 'email', 'ios', 'android', 'web', 'email', '']).isRequired, | ||
|
||
/** The message fragment's HTML */ | ||
html: PropTypes.string.isRequired, | ||
|
||
/** Should extra margin be added on top of the component? */ | ||
addExtraMargin: PropTypes.bool.isRequired, | ||
}; | ||
|
||
function AttachmentCommentFragment(props) { | ||
return ( | ||
<View style={props.addExtraMargin ? styles.mt2 : {}}> | ||
<RenderCommentHTML | ||
source={props.source} | ||
html={props.html} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
AttachmentCommentFragment.propTypes = propTypes; | ||
AttachmentCommentFragment.displayName = 'AttachmentCommentFragment'; | ||
|
||
export default AttachmentCommentFragment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import RenderHTML from '../../../../components/RenderHTML'; | ||
|
||
const propTypes = { | ||
/** The reportAction's source */ | ||
source: PropTypes.oneOf(['Chronos', 'email', 'ios', 'android', 'web', 'email', '']).isRequired, | ||
|
||
/** The comment's HTML */ | ||
html: PropTypes.string.isRequired, | ||
}; | ||
|
||
function RenderCommentHTML(props) { | ||
const html = props.html; | ||
|
||
return <RenderHTML html={props.source === 'email' ? `<email-comment>${html}</email-comment>` : `<comment>${html}</comment>`} />; | ||
} | ||
|
||
RenderCommentHTML.propTypes = propTypes; | ||
RenderCommentHTML.displayName = 'RenderCommentHTML'; | ||
|
||
export default RenderCommentHTML; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, {memo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Str from 'expensify-common/lib/str'; | ||
import reportActionFragmentPropTypes from '../reportActionFragmentPropTypes'; | ||
import styles from '../../../../styles/styles'; | ||
import variables from '../../../../styles/variables'; | ||
import themeColors from '../../../../styles/themes/default'; | ||
import Text from '../../../../components/Text'; | ||
import * as EmojiUtils from '../../../../libs/EmojiUtils'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize'; | ||
import * as DeviceCapabilities from '../../../../libs/DeviceCapabilities'; | ||
import compose from '../../../../libs/compose'; | ||
import convertToLTR from '../../../../libs/convertToLTR'; | ||
import CONST from '../../../../CONST'; | ||
import editedLabelStyles from '../../../../styles/editedLabelStyles'; | ||
import RenderCommentHTML from './RenderCommentHTML'; | ||
|
||
const propTypes = { | ||
/** The reportAction's source */ | ||
source: PropTypes.oneOf(['Chronos', 'email', 'ios', 'android', 'web', 'email', '']).isRequired, | ||
|
||
/** The message fragment needing to be displayed */ | ||
fragment: reportActionFragmentPropTypes.isRequired, | ||
|
||
/** Should this message fragment be styled as deleted? */ | ||
styleAsDeleted: PropTypes.bool.isRequired, | ||
|
||
/** Additional styles to add after local styles. */ | ||
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]).isRequired, | ||
|
||
...windowDimensionsPropTypes, | ||
|
||
/** localization props */ | ||
...withLocalizePropTypes, | ||
}; | ||
|
||
function TextCommentFragment(props) { | ||
const {fragment, styleAsDeleted} = props; | ||
const {html, text} = fragment; | ||
|
||
// If the only difference between fragment.text and fragment.html is <br /> tags | ||
// we render it as text, not as html. | ||
// This is done to render emojis with line breaks between them as text. | ||
const differByLineBreaksOnly = Str.replaceAll(html, '<br />', '\n') === text; | ||
|
||
// Only render HTML if we have html in the fragment | ||
if (!differByLineBreaksOnly) { | ||
const editedTag = fragment.isEdited ? `<edited ${styleAsDeleted ? 'deleted' : ''}></edited>` : ''; | ||
const htmlContent = styleAsDeleted ? `<del>${html}</del>` : html; | ||
|
||
const htmlWithTag = editedTag ? `${htmlContent}${editedTag}` : htmlContent; | ||
|
||
return ( | ||
<RenderCommentHTML | ||
source={props.source} | ||
html={htmlWithTag} | ||
/> | ||
); | ||
} | ||
|
||
const containsOnlyEmojis = EmojiUtils.containsOnlyEmojis(text); | ||
|
||
return ( | ||
<Text style={[containsOnlyEmojis ? styles.onlyEmojisText : undefined, styles.ltr, ...props.style]}> | ||
<Text | ||
selectable={!DeviceCapabilities.canUseTouchScreen() || !props.isSmallScreenWidth} | ||
style={[containsOnlyEmojis ? styles.onlyEmojisText : undefined, styles.ltr, ...props.style, styleAsDeleted ? styles.offlineFeedback.deleted : undefined]} | ||
> | ||
{convertToLTR(props.iouMessage || text)} | ||
</Text> | ||
{Boolean(fragment.isEdited) && ( | ||
<> | ||
<Text | ||
selectable={false} | ||
style={[containsOnlyEmojis ? styles.onlyEmojisTextLineHeight : undefined, styles.userSelectNone]} | ||
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}} | ||
> | ||
{' '} | ||
</Text> | ||
<Text | ||
fontSize={variables.fontSizeSmall} | ||
color={themeColors.textSupporting} | ||
style={[editedLabelStyles, styleAsDeleted ? styles.offlineFeedback.deleted : undefined, ...props.style]} | ||
> | ||
{props.translate('reportActionCompose.edited')} | ||
</Text> | ||
</> | ||
)} | ||
</Text> | ||
); | ||
} | ||
|
||
TextCommentFragment.propTypes = propTypes; | ||
TextCommentFragment.displayName = 'TextCommentFragment'; | ||
|
||
export default compose(withWindowDimensions, withLocalize)(memo(TextCommentFragment)); |