Skip to content

Commit 5034433

Browse files
authored
Merge pull request #23152 from koko57/fix/19483-close-anchor-popup
Fix/19483 close anchor popup
2 parents 09b29cc + 782e029 commit 5034433

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'underscore';
2-
import React from 'react';
2+
import React, {useEffect} from 'react';
33
import {StyleSheet} from 'react-native';
44
import PropTypes from 'prop-types';
55
import lodashGet from 'lodash/get';
@@ -12,74 +12,74 @@ import Tooltip from '../Tooltip';
1212
import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
1313
import styles from '../../styles/styles';
1414
import * as StyleUtils from '../../styles/StyleUtils';
15-
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
16-
import {propTypes as anchorForCommentsOnlyPropTypes, defaultProps as anchorForCommentsOnlyDefaultProps} from './anchorForCommentsOnlyPropTypes';
15+
import {propTypes as anchorForCommentsOnlyPropTypes} from './anchorForCommentsOnlyPropTypes';
1716
import CONST from '../../CONST';
17+
import useWindowDimensions from '../../hooks/useWindowDimensions';
1818

1919
const propTypes = {
2020
/** Press in handler for the link */
21+
// eslint-disable-next-line react/require-default-props
2122
onPressIn: PropTypes.func,
2223

2324
/** Press out handler for the link */
25+
// eslint-disable-next-line react/require-default-props
2426
onPressOut: PropTypes.func,
2527

26-
// eslint-disable-next-line react/forbid-prop-types
27-
containerStyles: PropTypes.arrayOf(PropTypes.object),
28-
2928
...anchorForCommentsOnlyPropTypes,
30-
...windowDimensionsPropTypes,
31-
};
32-
33-
const defaultProps = {
34-
onPressIn: undefined,
35-
onPressOut: undefined,
36-
containerStyles: [],
37-
...anchorForCommentsOnlyDefaultProps,
3829
};
3930

4031
/*
4132
* This is a default anchor component for regular links.
4233
*/
43-
function BaseAnchorForCommentsOnly(props) {
34+
function BaseAnchorForCommentsOnly({onPressIn, onPressOut, href = '', rel = '', target = '', children = null, style = {}, onPress, ...rest}) {
35+
useEffect(
36+
() => () => {
37+
ReportActionContextMenu.hideContextMenu();
38+
},
39+
[],
40+
);
41+
42+
const {isSmallScreenWidth} = useWindowDimensions();
43+
4444
let linkRef;
45-
const rest = _.omit(props, _.keys(propTypes));
45+
4646
const linkProps = {};
47-
if (_.isFunction(props.onPress)) {
48-
linkProps.onPress = props.onPress;
47+
if (_.isFunction(onPress)) {
48+
linkProps.onPress = onPress;
4949
} else {
50-
linkProps.href = props.href;
50+
linkProps.href = href;
5151
}
52-
const defaultTextStyle = DeviceCapabilities.canUseTouchScreen() || props.isSmallScreenWidth ? {} : {...styles.userSelectText, ...styles.cursorPointer};
53-
const isEmail = Str.isValidEmailMarkdown(props.href.replace(/mailto:/i, ''));
52+
const defaultTextStyle = DeviceCapabilities.canUseTouchScreen() || isSmallScreenWidth ? {} : {...styles.userSelectText, ...styles.cursorPointer};
53+
const isEmail = Str.isValidEmailMarkdown(href.replace(/mailto:/i, ''));
5454

5555
return (
5656
<PressableWithSecondaryInteraction
5757
inline
58-
style={[styles.cursorDefault, StyleUtils.getFontSizeStyle(props.style.fontSize)]}
58+
style={[styles.cursorDefault, StyleUtils.getFontSizeStyle(style.fontSize)]}
5959
onSecondaryInteraction={(event) => {
6060
ReportActionContextMenu.showContextMenu(
6161
isEmail ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
6262
event,
63-
props.href,
63+
href,
6464
lodashGet(linkRef, 'current'),
6565
);
6666
}}
6767
onPress={linkProps.onPress}
68-
onPressIn={props.onPressIn}
69-
onPressOut={props.onPressOut}
68+
onPressIn={onPressIn}
69+
onPressOut={onPressOut}
7070
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
71-
accessibilityLabel={props.href}
71+
accessibilityLabel={href}
7272
>
73-
<Tooltip text={props.href}>
73+
<Tooltip text={href}>
7474
<Text
7575
ref={(el) => (linkRef = el)}
76-
style={StyleSheet.flatten([props.style, defaultTextStyle])}
76+
style={StyleSheet.flatten([style, defaultTextStyle])}
7777
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
7878
hrefAttrs={{
79-
rel: props.rel,
80-
target: isEmail || !linkProps.href ? '_self' : props.target,
79+
rel,
80+
target: isEmail || !linkProps.href ? '_self' : target,
8181
}}
82-
href={linkProps.href || props.href}
82+
href={linkProps.href || href}
8383
onPress={(event) => {
8484
if (!linkProps.onPress) {
8585
return;
@@ -93,15 +93,14 @@ function BaseAnchorForCommentsOnly(props) {
9393
// eslint-disable-next-line react/jsx-props-no-spreading
9494
{...rest}
9595
>
96-
{props.children}
96+
{children}
9797
</Text>
9898
</Tooltip>
9999
</PressableWithSecondaryInteraction>
100100
);
101101
}
102102

103103
BaseAnchorForCommentsOnly.propTypes = propTypes;
104-
BaseAnchorForCommentsOnly.defaultProps = defaultProps;
105104
BaseAnchorForCommentsOnly.displayName = 'BaseAnchorForCommentsOnly';
106105

107-
export default withWindowDimensions(BaseAnchorForCommentsOnly);
106+
export default BaseAnchorForCommentsOnly;

src/components/AnchorForCommentsOnly/anchorForCommentsOnlyPropTypes.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ const propTypes = {
1616
/** Any children to display */
1717
children: PropTypes.node,
1818

19-
/** Anchor text of URLs or emails. */
20-
displayName: PropTypes.string,
21-
2219
/** Any additional styles to apply */
2320
style: stylePropTypes,
2421

@@ -32,7 +29,6 @@ const defaultProps = {
3229
target: '',
3330
children: null,
3431
style: {},
35-
displayName: '',
3632
onPress: undefined,
3733
};
3834

0 commit comments

Comments
 (0)