Skip to content

Commit

Permalink
Merge pull request #3659 from Viacheslav80/fix_copy_message_menu
Browse files Browse the repository at this point in the history
fix contextMenu on Mobile
  • Loading branch information
roryabraham authored Jun 29, 2021
2 parents 5cde3ca + a1f2c94 commit b5a3bab
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 29 deletions.
10 changes: 10 additions & 0 deletions src/components/PressableWithSecondaryInteraction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ class PressableWithSecondaryInteraction extends Component {
this.props.forwardedRef(this.pressableRef);
}
this.pressableRef.addEventListener('contextmenu', this.executeSecondaryInteractionOnContextMenu);
this.pressableRef.addEventListener('touchstart', this.preventDefault);
}

componentWillUnmount() {
this.pressableRef.removeEventListener('contextmenu', this.executeSecondaryInteractionOnContextMenu);
this.pressableRef.removeEventListener('touchstart', this.preventDefault);
}

/**
* @param {touchstart} e - TouchEvent.
* https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
*/
preventDefault = (e) => {
e.preventDefault();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
/* eslint-disable react/prop-types */
import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {useWindowDimensions, TouchableOpacity} from 'react-native';
import HTML, {
defaultHTMLElementModels,
TNodeChildrenRenderer,
splitBoxModelStyle,
} from 'react-native-render-html';
import Config from '../CONFIG';
import styles, {webViewStyles, getFontFamilyMonospace} from '../styles/styles';
import fontFamily from '../styles/fontFamily';
import AnchorForCommentsOnly from './AnchorForCommentsOnly';
import InlineCodeBlock from './InlineCodeBlock';
import AttachmentModal from './AttachmentModal';
import ThumbnailImage from './ThumbnailImage';
import variables from '../styles/variables';
import themeColors from '../styles/themes/default';
import Text from './Text';
import PropTypes from 'prop-types';
import Config from '../../CONFIG';
import styles, {webViewStyles, getFontFamilyMonospace} from '../../styles/styles';
import fontFamily from '../../styles/fontFamily';
import AnchorForCommentsOnly from '../AnchorForCommentsOnly';
import InlineCodeBlock from '../InlineCodeBlock';
import AttachmentModal from '../AttachmentModal';
import ThumbnailImage from '../ThumbnailImage';
import variables from '../../styles/variables';
import themeColors from '../../styles/themes/default';
import Text from '../Text';
import {
propTypes as renderHTMLPropTypes,
defaultProps as renderHTMLDefaultProps,
} from './renderHTMLPropTypes';

const propTypes = {
/** Whether text elements should be selectable */
textSelectable: PropTypes.bool,
...renderHTMLPropTypes,
};

const defaultProps = {
textSelectable: false,
...renderHTMLDefaultProps,
};

const MAX_IMG_DIMENSIONS = 512;

Expand Down Expand Up @@ -192,20 +207,12 @@ const renderers = {
edited: EditedRenderer,
};

const propTypes = {
/** HTML string to render */
html: PropTypes.string.isRequired,

/** Optional debug flag */
debug: PropTypes.bool,
};

const RenderHTML = ({html, debug = false}) => {
const BaseRenderHTML = ({html, debug, textSelectable}) => {
const {width} = useWindowDimensions();
const containerWidth = width * 0.8;
return (
<HTML
textSelectable
textSelectable={textSelectable}
renderers={renderers}
baseStyle={webViewStyles.baseFontStyle}
tagsStyles={webViewStyles.tagStyles}
Expand All @@ -223,10 +230,8 @@ const RenderHTML = ({html, debug = false}) => {
);
};

RenderHTML.displayName = 'RenderHTML';
RenderHTML.propTypes = propTypes;
RenderHTML.defaultProps = {
debug: false,
};
BaseRenderHTML.displayName = 'BaseRenderHTML';
BaseRenderHTML.propTypes = propTypes;
BaseRenderHTML.defaultProps = defaultProps;

export default RenderHTML;
export default BaseRenderHTML;
21 changes: 21 additions & 0 deletions src/components/RenderHTML/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import BaseRenderHTML from './BaseRenderHTML';
import withWindowDimensions from '../withWindowDimensions';
import {
propTypes,
defaultProps,
} from './renderHTMLPropTypes';

const RenderHTML = ({html, debug, isSmallScreenWidth}) => (
<BaseRenderHTML
textSelectable={!isSmallScreenWidth}
html={html}
debug={debug}
/>
);

RenderHTML.displayName = 'RenderHTML';
RenderHTML.propTypes = propTypes;
RenderHTML.defaultProps = defaultProps;

export default withWindowDimensions(RenderHTML);
19 changes: 19 additions & 0 deletions src/components/RenderHTML/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import BaseRenderHTML from './BaseRenderHTML';
import {
propTypes,
defaultProps,
} from './renderHTMLPropTypes';

const RenderHTML = ({html, debug}) => (
<BaseRenderHTML
html={html}
debug={debug}
/>
);

RenderHTML.displayName = 'RenderHTML';
RenderHTML.propTypes = propTypes;
RenderHTML.defaultProps = defaultProps;

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

const propTypes = {
/** HTML string to render */
html: PropTypes.string.isRequired,

/** Optional debug flag */
debug: PropTypes.bool,
};

const defaultProps = {
debug: false,
};

export {propTypes, defaultProps};
7 changes: 5 additions & 2 deletions src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import RenderHTML from '../../../components/RenderHTML';
import Text from '../../../components/Text';
import Tooltip from '../../../components/Tooltip';
import {isSingleEmoji} from '../../../libs/ValidationUtils';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';

const propTypes = {
/** The message fragment needing to be displayed */
Expand All @@ -23,6 +24,8 @@ const propTypes = {

/** Does this fragment belong to a reportAction that has not yet loaded? */
loading: PropTypes.bool,

...windowDimensionsPropTypes,
};

const defaultProps = {
Expand Down Expand Up @@ -58,7 +61,7 @@ class ReportActionItemFragment extends React.PureComponent {
/>
) : (
<Text
selectable
selectable={!this.props.isSmallScreenWidth}
style={isSingleEmoji(fragment.text) ? styles.singleEmojiText : undefined}
>
{Str.htmlDecode(fragment.text)}
Expand Down Expand Up @@ -109,4 +112,4 @@ ReportActionItemFragment.propTypes = propTypes;
ReportActionItemFragment.defaultProps = defaultProps;
ReportActionItemFragment.displayName = 'ReportActionItemFragment';

export default ReportActionItemFragment;
export default withWindowDimensions(ReportActionItemFragment);

0 comments on commit b5a3bab

Please sign in to comment.