1
1
import React from 'react' ;
2
2
import { Pressable } from 'react-native' ;
3
- import * as anchorForAttachmentsOnlyPropTypes from './anchorForAttachmentsOnlyPropTypes' ;
3
+ import PropTypes from 'prop-types' ;
4
+ import {
5
+ propTypes as anchorForAttachmentsOnlyPropTypes ,
6
+ defaultProps as anchorForAttachmentsOnlyDefaultProps ,
7
+ } from './anchorForAttachmentsOnlyPropTypes' ;
4
8
import AttachmentView from '../AttachmentView' ;
5
9
import fileDownload from '../../libs/fileDownload' ;
6
10
import addEncryptedAuthTokenToURL from '../../libs/addEncryptedAuthTokenToURL' ;
11
+ import { ShowContextMenuContext , showContextMenuForReport } from '../ShowContextMenuContext' ;
12
+
13
+ const propTypes = {
14
+ /** Press in handler for the link */
15
+ onPressIn : PropTypes . func ,
16
+
17
+ /** Press out handler for the link */
18
+ onPressOut : PropTypes . func ,
19
+
20
+ ...anchorForAttachmentsOnlyPropTypes ,
21
+ } ;
22
+
23
+ const defaultProps = {
24
+ onPressIn : undefined ,
25
+ onPressOut : undefined ,
26
+ ...anchorForAttachmentsOnlyDefaultProps ,
27
+ } ;
7
28
8
29
class BaseAnchorForAttachmentsOnly extends React . Component {
9
30
constructor ( props ) {
@@ -30,27 +51,45 @@ class BaseAnchorForAttachmentsOnly extends React.Component {
30
51
const source = addEncryptedAuthTokenToURL ( this . props . source ) ;
31
52
32
53
return (
33
- < Pressable
34
- style = { this . props . style }
35
- onPress = { ( ) => {
36
- if ( this . state . isDownloading ) {
37
- return ;
38
- }
39
- this . processDownload ( source , this . props . displayName ) ;
40
- } }
41
- >
42
- < AttachmentView
43
- sourceURL = { source }
44
- file = { { name : this . props . displayName } }
45
- shouldShowDownloadIcon
46
- shouldShowLoadingSpinnerIcon = { this . state . isDownloading }
47
- />
48
- </ Pressable >
54
+ < ShowContextMenuContext . Consumer >
55
+ { ( {
56
+ anchor,
57
+ reportID,
58
+ action,
59
+ checkIfContextMenuActive,
60
+ } ) => (
61
+ < Pressable
62
+ style = { this . props . style }
63
+ onPress = { ( ) => {
64
+ if ( this . state . isDownloading ) {
65
+ return ;
66
+ }
67
+ this . processDownload ( source , this . props . displayName ) ;
68
+ } }
69
+ onPressIn = { this . props . onPressIn }
70
+ onPressOut = { this . props . onPressOut }
71
+ onLongPress = { event => showContextMenuForReport (
72
+ event ,
73
+ anchor ,
74
+ reportID ,
75
+ action ,
76
+ checkIfContextMenuActive ,
77
+ ) }
78
+ >
79
+ < AttachmentView
80
+ sourceURL = { source }
81
+ file = { { name : this . props . displayName } }
82
+ shouldShowDownloadIcon
83
+ shouldShowLoadingSpinnerIcon = { this . state . isDownloading }
84
+ />
85
+ </ Pressable >
86
+ ) }
87
+ </ ShowContextMenuContext . Consumer >
49
88
) ;
50
89
}
51
90
}
52
91
53
- BaseAnchorForAttachmentsOnly . propTypes = anchorForAttachmentsOnlyPropTypes . propTypes ;
54
- BaseAnchorForAttachmentsOnly . defaultProps = anchorForAttachmentsOnlyPropTypes . defaultProps ;
92
+ BaseAnchorForAttachmentsOnly . propTypes = propTypes ;
93
+ BaseAnchorForAttachmentsOnly . defaultProps = defaultProps ;
55
94
56
95
export default BaseAnchorForAttachmentsOnly ;
0 commit comments