Skip to content
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
32 changes: 26 additions & 6 deletions src/components/MenuItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import React, {useEffect} from 'react';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import Text from './Text';
Expand All @@ -25,6 +25,10 @@ import * as Session from '../libs/actions/Session';
import Hoverable from './Hoverable';
import useWindowDimensions from '../hooks/useWindowDimensions';
import RenderHTML from './RenderHTML';
import getPlatform from '../libs/getPlatform';

const platform = getPlatform();
const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;

const propTypes = menuItemPropTypes;

Expand Down Expand Up @@ -119,6 +123,18 @@ const MenuItem = React.forwardRef((props, ref) => {
titleRef.current = props.title;
}, [props.title, props.shouldParseTitle]);

const getProcessedTitle = useMemo(() => {
if (props.shouldRenderAsHTML) {
return convertToLTR(props.title);
}

if (props.shouldParseTitle) {
return html;
}

return '';
}, [props.title, props.shouldRenderAsHTML, props.shouldParseTitle, html]);

return (
<Hoverable>
{(isHovered) => (
Expand Down Expand Up @@ -235,10 +251,15 @@ const MenuItem = React.forwardRef((props, ref) => {
</Text>
)}
<View style={[styles.flexRow, styles.alignItemsCenter]}>
{Boolean(props.title) && Boolean(props.shouldRenderAsHTML) && <RenderHTML html={convertToLTR(props.title)} />}

{Boolean(props.shouldParseTitle) && Boolean(html.length) && !props.shouldRenderAsHTML && <RenderHTML html={`<comment>${html}</comment>`} />}

{Boolean(props.title) &&
(Boolean(props.shouldRenderAsHTML) || (Boolean(props.shouldParseTitle) && Boolean(html.length))) &&
(isNative ? (
<RenderHTML html={getProcessedTitle} />
) : (
<View style={styles.chatItemMessage}>
<RenderHTML html={getProcessedTitle} />
</View>
))}
Comment on lines +256 to +262

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in my initial review, but writing platform specific code like this is against our guidelines

{!props.shouldRenderAsHTML && !html.length && Boolean(props.title) && (
<Text
style={titleTextStyle}
Expand All @@ -248,7 +269,6 @@ const MenuItem = React.forwardRef((props, ref) => {
{convertToLTR(props.title)}
</Text>
)}

{Boolean(props.shouldShowTitleIcon) && (
<View style={[styles.ml2]}>
<Icon
Expand Down