1
1
import _ from 'underscore' ;
2
- import React from 'react' ;
2
+ import React , { useEffect } from 'react' ;
3
3
import { StyleSheet } from 'react-native' ;
4
4
import PropTypes from 'prop-types' ;
5
5
import lodashGet from 'lodash/get' ;
@@ -12,74 +12,74 @@ import Tooltip from '../Tooltip';
12
12
import * as DeviceCapabilities from '../../libs/DeviceCapabilities' ;
13
13
import styles from '../../styles/styles' ;
14
14
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' ;
17
16
import CONST from '../../CONST' ;
17
+ import useWindowDimensions from '../../hooks/useWindowDimensions' ;
18
18
19
19
const propTypes = {
20
20
/** Press in handler for the link */
21
+ // eslint-disable-next-line react/require-default-props
21
22
onPressIn : PropTypes . func ,
22
23
23
24
/** Press out handler for the link */
25
+ // eslint-disable-next-line react/require-default-props
24
26
onPressOut : PropTypes . func ,
25
27
26
- // eslint-disable-next-line react/forbid-prop-types
27
- containerStyles : PropTypes . arrayOf ( PropTypes . object ) ,
28
-
29
28
...anchorForCommentsOnlyPropTypes ,
30
- ...windowDimensionsPropTypes ,
31
- } ;
32
-
33
- const defaultProps = {
34
- onPressIn : undefined ,
35
- onPressOut : undefined ,
36
- containerStyles : [ ] ,
37
- ...anchorForCommentsOnlyDefaultProps ,
38
29
} ;
39
30
40
31
/*
41
32
* This is a default anchor component for regular links.
42
33
*/
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
+
44
44
let linkRef ;
45
- const rest = _ . omit ( props , _ . keys ( propTypes ) ) ;
45
+
46
46
const linkProps = { } ;
47
- if ( _ . isFunction ( props . onPress ) ) {
48
- linkProps . onPress = props . onPress ;
47
+ if ( _ . isFunction ( onPress ) ) {
48
+ linkProps . onPress = onPress ;
49
49
} else {
50
- linkProps . href = props . href ;
50
+ linkProps . href = href ;
51
51
}
52
- const defaultTextStyle = DeviceCapabilities . canUseTouchScreen ( ) || props . isSmallScreenWidth ? { } : { ...styles . userSelectText , ...styles . cursorPointer } ;
53
- const isEmail = Str . isValidEmailMarkdown ( props . href . replace ( / m a i l t o : / i, '' ) ) ;
52
+ const defaultTextStyle = DeviceCapabilities . canUseTouchScreen ( ) || isSmallScreenWidth ? { } : { ...styles . userSelectText , ...styles . cursorPointer } ;
53
+ const isEmail = Str . isValidEmailMarkdown ( href . replace ( / m a i l t o : / i, '' ) ) ;
54
54
55
55
return (
56
56
< PressableWithSecondaryInteraction
57
57
inline
58
- style = { [ styles . cursorDefault , StyleUtils . getFontSizeStyle ( props . style . fontSize ) ] }
58
+ style = { [ styles . cursorDefault , StyleUtils . getFontSizeStyle ( style . fontSize ) ] }
59
59
onSecondaryInteraction = { ( event ) => {
60
60
ReportActionContextMenu . showContextMenu (
61
61
isEmail ? ContextMenuActions . CONTEXT_MENU_TYPES . EMAIL : ContextMenuActions . CONTEXT_MENU_TYPES . LINK ,
62
62
event ,
63
- props . href ,
63
+ href ,
64
64
lodashGet ( linkRef , 'current' ) ,
65
65
) ;
66
66
} }
67
67
onPress = { linkProps . onPress }
68
- onPressIn = { props . onPressIn }
69
- onPressOut = { props . onPressOut }
68
+ onPressIn = { onPressIn }
69
+ onPressOut = { onPressOut }
70
70
accessibilityRole = { CONST . ACCESSIBILITY_ROLE . LINK }
71
- accessibilityLabel = { props . href }
71
+ accessibilityLabel = { href }
72
72
>
73
- < Tooltip text = { props . href } >
73
+ < Tooltip text = { href } >
74
74
< Text
75
75
ref = { ( el ) => ( linkRef = el ) }
76
- style = { StyleSheet . flatten ( [ props . style , defaultTextStyle ] ) }
76
+ style = { StyleSheet . flatten ( [ style , defaultTextStyle ] ) }
77
77
accessibilityRole = { CONST . ACCESSIBILITY_ROLE . LINK }
78
78
hrefAttrs = { {
79
- rel : props . rel ,
80
- target : isEmail || ! linkProps . href ? '_self' : props . target ,
79
+ rel,
80
+ target : isEmail || ! linkProps . href ? '_self' : target ,
81
81
} }
82
- href = { linkProps . href || props . href }
82
+ href = { linkProps . href || href }
83
83
onPress = { ( event ) => {
84
84
if ( ! linkProps . onPress ) {
85
85
return ;
@@ -93,15 +93,14 @@ function BaseAnchorForCommentsOnly(props) {
93
93
// eslint-disable-next-line react/jsx-props-no-spreading
94
94
{ ...rest }
95
95
>
96
- { props . children }
96
+ { children }
97
97
</ Text >
98
98
</ Tooltip >
99
99
</ PressableWithSecondaryInteraction >
100
100
) ;
101
101
}
102
102
103
103
BaseAnchorForCommentsOnly . propTypes = propTypes ;
104
- BaseAnchorForCommentsOnly . defaultProps = defaultProps ;
105
104
BaseAnchorForCommentsOnly . displayName = 'BaseAnchorForCommentsOnly' ;
106
105
107
- export default withWindowDimensions ( BaseAnchorForCommentsOnly ) ;
106
+ export default BaseAnchorForCommentsOnly ;
0 commit comments