1
1
import React from 'react' ;
2
2
import { Text , View } from 'react-native' ;
3
+ import Clipboard from '@react-native-clipboard/clipboard' ;
3
4
4
5
import { ISubscription , SubscriptionType } from '../../../definitions' ;
5
6
import styles from '../styles' ;
6
7
import { useTheme } from '../../../theme' ;
7
8
import RoomTypeIcon from '../../../containers/RoomTypeIcon' ;
8
9
import { getRoomTitle } from '../../../lib/methods/helpers' ;
9
10
import CollapsibleText from '../../../containers/CollapsibleText' ;
11
+ import EventEmitter from '../../../lib/methods/helpers/events' ;
12
+ import { LISTENER } from '../../../containers/Toast' ;
13
+ import I18n from '../../../i18n' ;
10
14
11
15
interface IRoomInfoViewTitle {
12
16
room ?: ISubscription ;
@@ -18,14 +22,27 @@ interface IRoomInfoViewTitle {
18
22
19
23
const RoomInfoViewTitle = ( { room, name, username, statusText, type } : IRoomInfoViewTitle ) : React . ReactElement => {
20
24
const { colors } = useTheme ( ) ;
25
+
26
+ const copyInfoToClipboard = ( data : string ) => {
27
+ Clipboard . setString ( data ) ;
28
+ EventEmitter . emit ( LISTENER , { message : I18n . t ( 'Copied_to_clipboard' ) } ) ;
29
+ } ;
30
+
21
31
if ( type === SubscriptionType . DIRECT ) {
22
32
return (
23
33
< View style = { styles . roomInfoViewTitleContainer } >
24
- < Text testID = 'room-info-view-name' style = { [ styles . roomTitle , { color : colors . titleText } ] } >
25
- { name }
26
- </ Text >
34
+ { name && (
35
+ < Text
36
+ onLongPress = { ( ) => copyInfoToClipboard ( name ) }
37
+ testID = 'room-info-view-name'
38
+ style = { [ styles . roomTitle , { color : colors . titleText } ] }
39
+ >
40
+ { name }
41
+ </ Text >
42
+ ) }
27
43
{ username && (
28
44
< Text
45
+ onLongPress = { ( ) => copyInfoToClipboard ( username ) }
29
46
testID = 'room-info-view-username'
30
47
style = { [ styles . roomUsername , { color : colors . auxiliaryText } ] }
31
48
> { `@${ username } ` } </ Text >
0 commit comments