Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3294027
D9394.id31741.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9394.id31741.diff
View Options
diff --git a/native/markdown/markdown-user-mention.react.js b/native/markdown/markdown-user-mention.react.js
new file mode 100644
--- /dev/null
+++ b/native/markdown/markdown-user-mention.react.js
@@ -0,0 +1,66 @@
+// @flow
+
+import { useFocusEffect } from '@react-navigation/native';
+import * as React from 'react';
+import { Text } from 'react-native';
+
+import { useMarkdownOnPressUtils } from './markdown-utils.js';
+import { getMarkdownStyles } from './styles.js';
+import { useNavigateToUserProfileBottomSheet } from '../user-profile/user-profile-utils.js';
+
+type TextProps = React.ElementConfig<typeof Text>;
+type Props = {
+ +children: React.Node,
+ +userID: string,
+ +useDarkStyle: boolean,
+ ...TextProps,
+};
+
+function MarkdownUserMention(props: Props): React.Node {
+ const { userID, useDarkStyle, ...rest } = props;
+
+ const { messageKey, isRevealed, onLongPressHandler, markdownContext } =
+ useMarkdownOnPressUtils();
+
+ const styles = getMarkdownStyles(useDarkStyle ? 'dark' : 'light');
+
+ const { setUserProfileBottomSheetActive } = markdownContext;
+
+ const navigateToUserProfileBottomSheet =
+ useNavigateToUserProfileBottomSheet();
+
+ useFocusEffect(
+ React.useCallback(() => {
+ if (!messageKey) {
+ return;
+ }
+
+ setUserProfileBottomSheetActive({ [messageKey]: false });
+ }, [messageKey, setUserProfileBottomSheetActive]),
+ );
+
+ const onPressUser = React.useCallback(() => {
+ if (!messageKey) {
+ return;
+ }
+
+ setUserProfileBottomSheetActive({ [messageKey]: true });
+ navigateToUserProfileBottomSheet(userID);
+ }, [
+ messageKey,
+ navigateToUserProfileBottomSheet,
+ setUserProfileBottomSheetActive,
+ userID,
+ ]);
+
+ return (
+ <Text
+ onPress={isRevealed ? onPressUser : null}
+ onLongPress={isRevealed ? onLongPressHandler : null}
+ style={styles.bold}
+ {...rest}
+ />
+ );
+}
+
+export default MarkdownUserMention;
diff --git a/native/markdown/rules.react.js b/native/markdown/rules.react.js
--- a/native/markdown/rules.react.js
+++ b/native/markdown/rules.react.js
@@ -17,6 +17,7 @@
import MarkdownLink from './markdown-link.react.js';
import MarkdownParagraph from './markdown-paragraph.react.js';
import MarkdownSpoiler from './markdown-spoiler.react.js';
+import MarkdownUserMention from './markdown-user-mention.react.js';
import { getMarkdownStyles } from './styles.js';
export type MarkdownRules = {
@@ -376,7 +377,6 @@
chatMentionCandidates: ChatMentionCandidates,
useDarkStyle: boolean,
): MarkdownRules {
- const styles = getMarkdownStyles(useDarkStyle ? 'dark' : 'light');
const baseRules = fullMarkdownRules(useDarkStyle);
const membersMap = SharedMarkdown.createMemberMapForUserMentions(members);
@@ -395,9 +395,13 @@
output: SharedMarkdown.Output<SharedMarkdown.ReactElement>,
state: SharedMarkdown.State,
) => (
- <Text key={state.key} style={styles.bold}>
+ <MarkdownUserMention
+ key={state.key}
+ userID={node.userID}
+ useDarkStyle={useDarkStyle}
+ >
{node.content}
- </Text>
+ </MarkdownUserMention>
),
},
chatMention: {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 6:27 PM (19 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531080
Default Alt Text
D9394.id31741.diff (3 KB)
Attached To
Mode
D9394: [native] introduce MarkdownUserMention component
Attached
Detach File
Event Timeline
Log In to Comment