-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18495 from robertKozik/17885_custom_user_mentions…
…_renderer_text_based create UserMentionRenderer for rendering mentions inside chat
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
|
||
// We need to remove the leading @ from data as it is not part of the login | ||
const loginWhithoutLeadingAt = props.tnode.data.slice(1); | ||
|
||
const isOurMention = loginWhithoutLeadingAt === props.currentUserPersonalDetails.login; | ||
|
||
return ( | ||
<Text> | ||
<Tooltip absolute text={loginWhithoutLeadingAt}> | ||
<Text | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...defaultRendererProps} | ||
color={StyleUtils.getUserMentionTextColor(isOurMention)} | ||
style={StyleUtils.getUserMentionStyle(isOurMention)} | ||
onPress={() => showUserDetails(loginWhithoutLeadingAt)} | ||
> | ||
<TNodeChildrenRenderer tnode={props.tnode} /> | ||
</Text> | ||
</Tooltip> | ||
</Text> | ||
); | ||
}; | ||
|
||
MentionUserRenderer.propTypes = propTypes; | ||
MentionUserRenderer.displayName = 'MentionUserRenderer'; | ||
|
||
export default withCurrentUserPersonalDetails(MentionUserRenderer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters