Skip to content

Commit 6fab881

Browse files
authored
feat: Add copy button for email and number (#786)
1 parent a823ce1 commit 6fab881

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@
169169
"OPERATING_SYSTEM": "Operating System",
170170
"INITIATED_AT": "Initiated at",
171171
"INITIATED_FROM": "Initiated from",
172-
"IP_ADDRESS": "IP Address"
172+
"IP_ADDRESS": "IP Address",
173+
"CLIPBOARD_SUCCESS": "Copied to clipboard"
173174
},
174175
"CONVERSATION_PARTICIPANTS": {
175176
"TITLE": "Conversation participants",

src/screens/ConversationDetails/components/ContactDetails.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React, { useMemo } from 'react';
2-
import { StyleSheet } from 'react-native';
2+
import i18n from 'i18n';
3+
import { StyleSheet, View } from 'react-native';
34
import { useTheme } from '@react-navigation/native';
45
import PropTypes from 'prop-types';
56
import { Icon, Text, Pressable } from 'components';
7+
import Clipboard from '@react-native-clipboard/clipboard';
68

79
import { openNumber } from 'src/helpers/UrlHelper';
10+
import { showToast } from 'helpers/ToastHelper';
811

912
const createStyles = theme => {
1013
const { spacing } = theme;
@@ -15,8 +18,9 @@ const createStyles = theme => {
1518
alignItems: 'center',
1619
marginTop: spacing.smaller,
1720
marginBottom: spacing.micro,
21+
gap: spacing.micro,
1822
},
19-
detailText: {
23+
copyButton: {
2024
marginLeft: spacing.micro,
2125
},
2226
});
@@ -33,20 +37,39 @@ const ContactDetails = ({ type, value, iconName }) => {
3337
const { colors } = theme;
3438
const styles = useMemo(() => createStyles(theme), [theme]);
3539

40+
// Avoid rendering if the value is empty or whitespace (Case: identifier)
41+
if (!value || value === ' ') {
42+
return null;
43+
}
44+
3645
const onClickOpen = () => {
3746
if (type === 'phoneNumber') {
3847
openNumber({ phoneNumber: value });
3948
} else {
4049
return;
4150
}
4251
};
52+
53+
const showCopyButton = type === 'phoneNumber' || type === 'email';
54+
55+
const onClickCopy = () => {
56+
Clipboard.setString(value);
57+
showToast({ message: i18n.t('CONVERSATION_DETAILS.CLIPBOARD_SUCCESS') });
58+
};
4359
return (
44-
<Pressable style={styles.detailsContainer} onPress={() => onClickOpen()}>
60+
<View style={styles.detailsContainer}>
4561
<Icon icon={iconName} color={colors.primaryColor} size={14} />
46-
<Text sm color={colors.textDark} style={styles.detailText}>
47-
{value}
48-
</Text>
49-
</Pressable>
62+
<Pressable onPress={() => onClickOpen()}>
63+
<Text sm color={colors.textDark}>
64+
{value}
65+
</Text>
66+
</Pressable>
67+
{showCopyButton && (
68+
<Pressable style={styles.copyButton} onPress={() => onClickCopy()}>
69+
<Icon icon="copy-outline" color={colors.text} size={14} />
70+
</Pressable>
71+
)}
72+
</View>
5073
);
5174
};
5275

0 commit comments

Comments
 (0)