-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor: create reusable emoji component (issue #6535) #6813
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
Open
Sumanth2377
wants to merge
8
commits into
RocketChat:develop
Choose a base branch
from
Sumanth2377:feat/reusable-emoji-component
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6128b2b
refactor: create reusable emoji component (issue #6535)
Sumanth2377 29d5c00
fix: use type-only imports for StyleProp and TextStyle
Sumanth2377 ccfe315
refactor: extract duplicate size calculations and remove Android-only…
Sumanth2377 dec868c
Merge branch 'develop' into feat/reusable-emoji-component
Sumanth2377 003ae89
refactor: polish emoji component, fix lints and add tests
Sumanth2377 f7d04b0
Merge branch 'feat/reusable-emoji-component' of https://github.com/Su…
Sumanth2377 c190e40
refactor: remove unused imports in Emoji.tsx
Sumanth2377 b7bcaf2
refactor: improve emoji accessibility and cleanup unused params
Sumanth2377 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,85 @@ | ||
| import React from 'react'; | ||
| import { Text, useWindowDimensions } from 'react-native'; | ||
| import type { StyleProp, TextStyle } from 'react-native'; | ||
|
|
||
| import { useTheme } from '../../theme'; | ||
| import useShortnameToUnicode from '../../lib/hooks/useShortnameToUnicode'; | ||
| import CustomEmoji from '../EmojiPicker/CustomEmoji'; | ||
| import { useAppSelector } from '../../lib/hooks/useAppSelector'; | ||
| import { getUserSelector } from '../../selectors/login'; | ||
| import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout'; | ||
|
|
||
| interface ISharedEmojiProps { | ||
| literal?: string; | ||
| isBigEmoji?: boolean; | ||
| style?: StyleProp<TextStyle>; | ||
| isAvatar?: boolean; | ||
| getCustomEmoji?: (name: string) => any; | ||
| customEmoji?: any; | ||
| } | ||
|
|
||
| const Emoji = ({ literal, isBigEmoji, style, isAvatar, getCustomEmoji, customEmoji }: ISharedEmojiProps) => { | ||
| const { colors } = useTheme(); | ||
| const { formatShortnameToUnicode } = useShortnameToUnicode(); | ||
| const { fontScale } = useWindowDimensions(); | ||
| const { fontScaleLimited } = useResponsiveLayout(); | ||
| const convertAsciiEmoji = useAppSelector(state => getUserSelector(state)?.settings?.preferences?.convertAsciiEmoji); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (customEmoji) { | ||
| const customEmojiSize = { | ||
| width: 15 * fontScale, | ||
| height: 15 * fontScale | ||
| }; | ||
| const customEmojiBigSize = { | ||
| width: 30 * fontScale, | ||
| height: 30 * fontScale | ||
| }; | ||
| return <CustomEmoji style={[isBigEmoji ? customEmojiBigSize : customEmojiSize, style]} emoji={customEmoji} />; | ||
| } | ||
|
|
||
| if (!literal) { | ||
| return null; | ||
| } | ||
|
|
||
| const emojiUnicode = formatShortnameToUnicode(literal); | ||
| const emojiName = literal.replace(/:/g, ''); | ||
| const foundCustomEmoji = getCustomEmoji?.(emojiName); | ||
|
|
||
| if (foundCustomEmoji) { | ||
| const customEmojiSize = { | ||
| width: 15 * fontScale, | ||
| height: 15 * fontScale | ||
| }; | ||
| const customEmojiBigSize = { | ||
| width: 30 * fontScale, | ||
| height: 30 * fontScale | ||
| }; | ||
| return <CustomEmoji style={[isBigEmoji ? customEmojiBigSize : customEmojiSize, style]} emoji={foundCustomEmoji} />; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Handle ASCII emojis if needed, though usually handled by parser or formatShortnameToUnicode if configured | ||
| // But here we follow the logic from markdown/components/emoji/Emoji.tsx | ||
| // logic for ASCII is a bit specific to the block structure there, but here we deal with string literal. | ||
| // If formatShortnameToUnicode returns the same string, it might be an ASCII or unknown. | ||
|
|
||
| const avatarStyle = { | ||
| fontSize: 30 * fontScaleLimited, | ||
| lineHeight: 30 * fontScaleLimited, | ||
| textAlign: 'center', | ||
| textAlignVertical: 'center' | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| return ( | ||
| <Text | ||
| style={[ | ||
| { color: colors.fontDefault }, | ||
| isBigEmoji ? { fontSize: 30, lineHeight: 43 } : { fontSize: 16, lineHeight: 22 }, | ||
| style, | ||
| isAvatar && avatarStyle | ||
| ]}> | ||
| {emojiUnicode} | ||
| </Text> | ||
| ); | ||
| }; | ||
|
|
||
| export default Emoji; | ||
This file contains hidden or 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 @@ | ||
| export { default as Emoji } from './Emoji'; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,12 @@ | ||
| import React from 'react'; | ||
| import { Text } from 'react-native'; | ||
|
|
||
| import useShortnameToUnicode from '../../lib/hooks/useShortnameToUnicode'; | ||
| import styles from './styles'; | ||
| import CustomEmoji from './CustomEmoji'; | ||
| import { type IEmojiProps } from './interfaces'; | ||
| import SharedEmoji from '../Emoji/Emoji'; | ||
|
|
||
| export const Emoji = ({ emoji }: IEmojiProps): React.ReactElement => { | ||
| const { formatShortnameToUnicode } = useShortnameToUnicode(true); | ||
| const unicodeEmoji = formatShortnameToUnicode(`:${emoji}:`); | ||
|
|
||
| if (typeof emoji === 'string') { | ||
| return <Text style={styles.categoryEmoji}>{unicodeEmoji}</Text>; | ||
| return <SharedEmoji literal={`:${emoji}:`} style={styles.categoryEmoji} />; | ||
| } | ||
| return <CustomEmoji style={styles.customCategoryEmoji} emoji={emoji} />; | ||
| return <SharedEmoji customEmoji={emoji} style={styles.customCategoryEmoji} />; | ||
| }; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.