feat: copy username on long press in user info screen (#5633)
* copy usename on longpress * copy name too --------- Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
This commit is contained in:
parent
7caefa805c
commit
a3a7b951c5
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Text, View } from 'react-native';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
|
||||
import { ISubscription, SubscriptionType } from '../../../definitions';
|
||||
import styles from '../styles';
|
||||
|
@ -7,6 +8,9 @@ import { useTheme } from '../../../theme';
|
|||
import RoomTypeIcon from '../../../containers/RoomTypeIcon';
|
||||
import { getRoomTitle } from '../../../lib/methods/helpers';
|
||||
import CollapsibleText from '../../../containers/CollapsibleText';
|
||||
import EventEmitter from '../../../lib/methods/helpers/events';
|
||||
import { LISTENER } from '../../../containers/Toast';
|
||||
import I18n from '../../../i18n';
|
||||
|
||||
interface IRoomInfoViewTitle {
|
||||
room?: ISubscription;
|
||||
|
@ -18,14 +22,27 @@ interface IRoomInfoViewTitle {
|
|||
|
||||
const RoomInfoViewTitle = ({ room, name, username, statusText, type }: IRoomInfoViewTitle): React.ReactElement => {
|
||||
const { colors } = useTheme();
|
||||
|
||||
const copyInfoToClipboard = (data: string) => {
|
||||
Clipboard.setString(data);
|
||||
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
||||
};
|
||||
|
||||
if (type === SubscriptionType.DIRECT) {
|
||||
return (
|
||||
<View style={styles.roomInfoViewTitleContainer}>
|
||||
<Text testID='room-info-view-name' style={[styles.roomTitle, { color: colors.titleText }]}>
|
||||
{name}
|
||||
</Text>
|
||||
{name && (
|
||||
<Text
|
||||
onLongPress={() => copyInfoToClipboard(name)}
|
||||
testID='room-info-view-name'
|
||||
style={[styles.roomTitle, { color: colors.titleText }]}
|
||||
>
|
||||
{name}
|
||||
</Text>
|
||||
)}
|
||||
{username && (
|
||||
<Text
|
||||
onLongPress={() => copyInfoToClipboard(username)}
|
||||
testID='room-info-view-username'
|
||||
style={[styles.roomUsername, { color: colors.auxiliaryText }]}
|
||||
>{`@${username}`}</Text>
|
||||
|
|
Loading…
Reference in New Issue