Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] create UserMentionRenderer for rendering mentions inside chat #18495

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const customHTMLElementModels = {
tagName: 'strong',
mixedUAStyles: {whiteSpace: 'pre'},
}),
'mention-user': defaultHTMLElementModels.span.extend({tagName: 'mention-user'}),
};

// We are using the explicit composite architecture for performance gains.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import _ from 'underscore';
import {
TNodeChildrenRenderer,
} from 'react-native-render-html';
import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import Text from '../../Text';
import Tooltip from '../../Tooltip';
import htmlRendererPropTypes from './htmlRendererPropTypes';
import withCurrentUserPersonalDetails from '../../withCurrentUserPersonalDetails';
import personalDetailsPropType from '../../../pages/personalDetailsPropType';
import * as StyleUtils from '../../../styles/StyleUtils';

const propTypes = {
...htmlRendererPropTypes,

/**
* Current user personal details
*/
currentUserPersonalDetails: personalDetailsPropType.isRequired,
};

/**
* Navigates to user details screen based on email
* @param {String} email
* @returns {void}
* */
const showUserDetails = email => Navigation.navigate(ROUTES.getDetailsRoute(email));

const MentionUserRenderer = (props) => {
const defaultRendererProps = _.omit(props, ['TDefaultRenderer', 'style']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #18892:
style was omitted from props and defined custom mention style.
But this caused issue - some parent styles are not applied to child. i.e. bold from heading1.
More details about the root cause: #18892 (comment)

const Renderer = props.TDefaultRenderer;
robertKozik marked this conversation as resolved.
Show resolved Hide resolved
// We need to remove the leading @ from data as it is not part of the login
const loginWhithoutLeadingAt = props.tnode.data.slice(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #23811:
It's possible that props.tnode.data doesn't exist, which makes crash on this line. Especially on nested mention

More details about root cause: #23811 (comment)

Repro step: #23811 (comment)


const isOurMention = loginWhithoutLeadingAt === props.currentUserPersonalDetails.login;

return (
<Text>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this Wrapper Text needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens without it:
image

text consumes whole line, when there is only mention inside the message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't like that in initial PR. So I traced why it is looking like this after rebasing this branch. After bisecting for a while I found this PR and it changes the defaultViewProps for native platforms from styles.alignItemsStart to styles.dFlex and thats why the initial Text component want to span whole line. I saw that you @parasharrajat were reviewer for this PR too, so maybe you know if it can be switched back for native platforms, as issue resolved by this PR was connected with pointer behaviour - so specifically desktop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you are saying that we should remove Dflex from native platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to try and get this merged today if we can as we have a pretty quick timeline we're working with. So if we don't get a response soon, let's go forward with what we have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will get this merged today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we decided to keep it as-is?

Copy link
Contributor Author

@robertKozik robertKozik May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it, I'm here in case something would have to be changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let me test it and finish up the checklist.

<Tooltip absolute text={loginWhithoutLeadingAt}>
<Text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Coming from #19303
Since mention is a link (to user details), it should have used TextLink instead of Text
Not sure if this can be called a regression or a different expected behavior at the time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh good to know. I didn't even know about the TextLink component.

// eslint-disable-next-line react/jsx-props-no-spreading
{...defaultRendererProps}
color={StyleUtils.getUserMentionTextColor(isOurMention)}
style={StyleUtils.getUserMentionStyle(isOurMention)}
onPress={() => showUserDetails(loginWhithoutLeadingAt)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #27951. When you press and hold on a mention, the context menu should open, but this doesn't work on native. Text possesses an onLongPress event, which is not a bubble event, so it will not propagate to the parent component responsible for implementing the context menu. More context here

>
<TNodeChildrenRenderer tnode={props.tnode} />
</Text>
</Tooltip>
</Text>
);
};

MentionUserRenderer.propTypes = propTypes;
MentionUserRenderer.displayName = 'MentionUserRenderer';

export default withCurrentUserPersonalDetails(MentionUserRenderer);
2 changes: 2 additions & 0 deletions src/components/HTMLEngineProvider/HTMLRenderers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AnchorRenderer from './AnchorRenderer';
import CodeRenderer from './CodeRenderer';
import EditedRenderer from './EditedRenderer';
import ImageRenderer from './ImageRenderer';
import MentionUserRenderer from './MentionUserRenderer';
import PreRenderer from './PreRenderer';

/**
Expand All @@ -16,4 +17,5 @@ export default {
// Custom tag renderers
edited: EditedRenderer,
pre: PreRenderer,
'mention-user': MentionUserRenderer,
};
25 changes: 25 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,29 @@ function getGoogleListViewStyle(shouldDisplayBorder) {
};
}

/**
* Returns style object for the user mention component based on whether the mention is ours or not.
* @param {Boolean} isOurMention
* @returns {Object}
*/
function getUserMentionStyle(isOurMention) {
const backgroundColor = isOurMention ? themeColors.ourMentionBG : themeColors.mentionBG;
return {
backgroundColor,
borderRadius: variables.componentBorderRadiusSmall,
paddingHorizontal: 2,
};
}

/**
* Returns text color for the user mention text based on whether the mention is ours or not.
* @param {Boolean} isOurMention
* @returns {Object}
*/
function getUserMentionTextColor(isOurMention) {
return isOurMention ? themeColors.ourMentionText : themeColors.mentionText;
}

export {
getAvatarSize,
getAvatarStyle,
Expand Down Expand Up @@ -1169,4 +1192,6 @@ export {
getFontSizeStyle,
getSignInWordmarkWidthStyle,
getGoogleListViewStyle,
getUserMentionStyle,
getUserMentionTextColor,
};
4 changes: 4 additions & 0 deletions src/styles/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export default {
midnight: '#002140',

// Brand Colors from Figma
blue100: '#B0D9FF',
blue200: '#8DC8FF',
blue400: '#0185FF',
blue600: '#0164BF',
blue700: '#003C73',
blue800: '#002140',

green100: '#B1F2D6',
green200: '#8EECC4',
green400: '#03D47C',
green600: '#008C59',
green700: '#085239',
green800: '#002E22',

Expand Down
4 changes: 4 additions & 0 deletions src/styles/themes/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const darkTheme = {
reactionActive: '#003C73',
badgeAdHoc: colors.pink600,
badgeAdHocHover: colors.pink700,
mentionText: colors.blue100,
mentionBG: colors.blue600,
ourMentionText: colors.green100,
ourMentionBG: colors.green600,
};

const oldTheme = {
Expand Down