Skip to content

Commit a3a7b95

Browse files
jsathu07dnlsilva
andauthoredApr 9, 2024··
feat: copy username on long press in user info screen (#5633)
* copy usename on longpress * copy name too --------- Co-authored-by: Gleidson Daniel Silva <[email protected]>
1 parent 7caefa8 commit a3a7b95

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
 

‎app/views/RoomInfoView/components/RoomInfoViewTitle.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React from 'react';
22
import { Text, View } from 'react-native';
3+
import Clipboard from '@react-native-clipboard/clipboard';
34

45
import { ISubscription, SubscriptionType } from '../../../definitions';
56
import styles from '../styles';
67
import { useTheme } from '../../../theme';
78
import RoomTypeIcon from '../../../containers/RoomTypeIcon';
89
import { getRoomTitle } from '../../../lib/methods/helpers';
910
import CollapsibleText from '../../../containers/CollapsibleText';
11+
import EventEmitter from '../../../lib/methods/helpers/events';
12+
import { LISTENER } from '../../../containers/Toast';
13+
import I18n from '../../../i18n';
1014

1115
interface IRoomInfoViewTitle {
1216
room?: ISubscription;
@@ -18,14 +22,27 @@ interface IRoomInfoViewTitle {
1822

1923
const RoomInfoViewTitle = ({ room, name, username, statusText, type }: IRoomInfoViewTitle): React.ReactElement => {
2024
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+
2131
if (type === SubscriptionType.DIRECT) {
2232
return (
2333
<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+
)}
2743
{username && (
2844
<Text
45+
onLongPress={() => copyInfoToClipboard(username)}
2946
testID='room-info-view-username'
3047
style={[styles.roomUsername, { color: colors.auxiliaryText }]}
3148
>{`@${username}`}</Text>

0 commit comments

Comments
 (0)
Please sign in to comment.