Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3395856
D8915.id30236.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8915.id30236.diff
View Options
diff --git a/native/components/user-profile.react.js b/native/components/user-profile.react.js
--- a/native/components/user-profile.react.js
+++ b/native/components/user-profile.react.js
@@ -1,7 +1,8 @@
// @flow
+import Clipboard from '@react-native-clipboard/clipboard';
import * as React from 'react';
-import { View, Text } from 'react-native';
+import { View, Text, TouchableOpacity } from 'react-native';
import type { AccountUserInfo } from 'lib/types/user-types';
@@ -16,8 +17,47 @@
function UserProfile(props: Props): React.Node {
const { userInfo } = props;
+ const [usernameCopied, setUsernameCopied] = React.useState<boolean>(false);
+
const styles = useStyles(unboundStyles);
+ const onPressCopyUsername = React.useCallback(() => {
+ Clipboard.setString(userInfo.username);
+ setUsernameCopied(true);
+ setTimeout(() => setUsernameCopied(false), 3000);
+ }, [userInfo.username]);
+
+ const copyUsernameButton = React.useMemo(() => {
+ if (usernameCopied) {
+ return (
+ <View style={styles.copyUsernameContainer}>
+ <SWMansionIcon
+ name="check"
+ style={styles.copyUsernameIcon}
+ size={16}
+ />
+ <Text style={styles.copyUsernameText}>Username copied!</Text>
+ </View>
+ );
+ }
+
+ return (
+ <TouchableOpacity
+ style={styles.copyUsernameContainer}
+ onPress={onPressCopyUsername}
+ >
+ <SWMansionIcon name="copy" style={styles.copyUsernameIcon} size={16} />
+ <Text style={styles.copyUsernameText}>Copy username</Text>
+ </TouchableOpacity>
+ );
+ }, [
+ onPressCopyUsername,
+ styles.copyUsernameContainer,
+ styles.copyUsernameIcon,
+ styles.copyUsernameText,
+ usernameCopied,
+ ]);
+
return (
<View style={styles.container}>
<SWMansionIcon name="menu-vertical" size={24} style={styles.moreIcon} />
@@ -25,14 +65,7 @@
<UserAvatar size="profile" userID={userInfo.id} />
<View style={styles.usernameContainer}>
<Text style={styles.usernameText}>{userInfo.username}</Text>
- <View style={styles.copyUsernameContainer}>
- <SWMansionIcon
- name="copy"
- style={styles.copyUsernameIcon}
- size={16}
- />
- <Text style={styles.copyUsernameText}>Copy username</Text>
- </View>
+ {copyUsernameButton}
</View>
</View>
</View>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 8:11 AM (17 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607086
Default Alt Text
D8915.id30236.diff (2 KB)
Attached To
Mode
D8915: [native] introduce copy username functionality to user profiles
Attached
Detach File
Event Timeline
Log In to Comment