Page MenuHomePhabricator

D8915.id30236.diff
No OneTemporary

D8915.id30236.diff

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

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)

Event Timeline