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

Create different files for HTML Render and fix scroll width #27769

Merged
merged 10 commits into from
Sep 22, 2023
27 changes: 11 additions & 16 deletions src/components/MenuItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'underscore';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import {ScrollView, View} from 'react-native';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import Text from './Text';
import styles from '../styles/styles';
Expand All @@ -24,11 +24,8 @@ import variables from '../styles/variables';
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;
import MenuItemRenderHTMLTitle from './MenuItemRenderHTMLTitle';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';

const propTypes = menuItemPropTypes;

Expand Down Expand Up @@ -251,16 +248,14 @@ const MenuItem = React.forwardRef((props, ref) => {
</Text>
)}
<View style={[styles.flexRow, styles.alignItemsCenter]}>
{Boolean(props.title) &&
(Boolean(props.shouldRenderAsHTML) || (Boolean(props.shouldParseTitle) && Boolean(html.length))) &&
(isNative ? (
<RenderHTML html={getProcessedTitle} />
) : (
<View style={styles.chatItemMessage}>
<RenderHTML html={getProcessedTitle} />
</View>
))}
{!props.shouldRenderAsHTML && !html.length && Boolean(props.title) && (
{Boolean(props.title) && (Boolean(props.shouldRenderAsHTML) || (Boolean(props.shouldParseTitle) && Boolean(html.length))) && (
<ScrollView style={styles.menuItemHtmlRendererScrollView}>
<PressableWithoutFeedback accessibilityRole={CONST.ACCESSIBILITY_ROLE.ADJUSTABLE}>
<MenuItemRenderHTMLTitle title={getProcessedTitle} />
</PressableWithoutFeedback>
</ScrollView>
)}
{!props.shouldRenderAsHTML && !props.shouldParseTitle && Boolean(props.title) && (
<Text
style={titleTextStyle}
numberOfLines={props.numberOfLinesTitle || undefined}
Expand Down
23 changes: 23 additions & 0 deletions src/components/MenuItemRenderHTMLTitle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import {View} from 'react-native';
import styles from '../../styles/styles';
import RenderHTML from '../RenderHTML';
import menuItemRenderHTMLTitlePropTypes from './propTypes';

const propTypes = menuItemRenderHTMLTitlePropTypes;

const defaultProps = {};

function MenuItemRenderHTMLTitle(props) {
return (
<View style={styles.chatItemMessage}>
jeet-dhandha marked this conversation as resolved.
Show resolved Hide resolved
<RenderHTML html={props.title} />
</View>
);
}

MenuItemRenderHTMLTitle.propTypes = propTypes;
MenuItemRenderHTMLTitle.defaultProps = defaultProps;
MenuItemRenderHTMLTitle.displayName = 'MenuItemRenderHTMLTitle';

export default MenuItemRenderHTMLTitle;
17 changes: 17 additions & 0 deletions src/components/MenuItemRenderHTMLTitle/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import RenderHTML from '../RenderHTML';
import menuItemRenderHTMLTitlePropTypes from './propTypes';

const propTypes = menuItemRenderHTMLTitlePropTypes;

const defaultProps = {};

function MenuItemRenderHTMLTitle(props) {
return <RenderHTML html={props.title} />;
}

MenuItemRenderHTMLTitle.propTypes = propTypes;
MenuItemRenderHTMLTitle.defaultProps = defaultProps;
MenuItemRenderHTMLTitle.displayName = 'MenuItemRenderHTMLTitle';

export default MenuItemRenderHTMLTitle;
8 changes: 8 additions & 0 deletions src/components/MenuItemRenderHTMLTitle/propTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import PropTypes from 'prop-types';

const propTypes = {
/** Processed title to display for the MenuItem */
title: PropTypes.string.isRequired,
};

export default propTypes;
4 changes: 4 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,10 @@ const styles = (theme) => ({
height: 30,
width: '100%',
},

menuItemHtmlRendererScrollView: {
maxHeight: 115,
},
});

// For now we need to export the styles function that takes the theme as an argument
Expand Down
Loading