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

chore: memoed renderItem on emoji and mention suggestion lists #31703

Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 27 additions & 24 deletions src/components/EmojiSuggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {ReactElement} from 'react';
import React, {ReactElement, useCallback} from 'react';
import {View} from 'react-native';
import type {SimpleEmoji} from '@libs/EmojiTrie';
import * as EmojiUtils from '@libs/EmojiUtils';
Expand Down Expand Up @@ -48,30 +48,33 @@ function EmojiSuggestions({emojis, onSelect, prefix, isEmojiPickerLarge, preferr
/**
* Render an emoji suggestion menu item component.
*/
const renderSuggestionMenuItem = (item: SimpleEmoji): ReactElement => {
const styledTextArray = getStyledTextArray(item.name, prefix);
const renderSuggestionMenuItem = useCallback(
(item: SimpleEmoji): ReactElement => {
const styledTextArray = getStyledTextArray(item.name, prefix);

return (
<View style={styles.autoCompleteSuggestionContainer}>
<Text style={styles.emojiSuggestionsEmoji}>{EmojiUtils.getEmojiCodeWithSkinColor(item, preferredSkinToneIndex)}</Text>
<Text
numberOfLines={2}
style={styles.emojiSuggestionsText}
>
:
{styledTextArray.map(({text, isColored}) => (
<Text
key={`${text}+${isColored}`}
style={StyleUtils.getColoredBackgroundStyle(theme, isColored)}
>
{text}
</Text>
))}
:
</Text>
</View>
);
};
return (
<View style={styles.autoCompleteSuggestionContainer}>
<Text style={styles.emojiSuggestionsEmoji}>{EmojiUtils.getEmojiCodeWithSkinColor(item, preferredSkinToneIndex)}</Text>
<Text
numberOfLines={2}
style={styles.emojiSuggestionsText}
>
:
{styledTextArray.map(({text, isColored}) => (
<Text
key={`${text}+${isColored}`}
style={StyleUtils.getColoredBackgroundStyle(theme, isColored)}
>
{text}
</Text>
))}
:
</Text>
</View>
);
},
[styles, theme, prefix, preferredSkinToneIndex],
);

return (
<AutoCompleteSuggestions
Expand Down
105 changes: 54 additions & 51 deletions src/components/MentionSuggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import getStyledTextArray from '@libs/GetStyledTextArray';
import * as StyleUtils from '@styles/StyleUtils';
Expand Down Expand Up @@ -57,57 +57,60 @@ function MentionSuggestions({prefix, mentions, highlightedMentionIndex = 0, onSe
/**
* Render a suggestion menu item component.
*/
const renderSuggestionMenuItem = (item: Mention) => {
const isIcon = item.text === CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT;
const styledDisplayName = getStyledTextArray(item.text, prefix);
const styledHandle = item.text === item.alternateText ? undefined : getStyledTextArray(item.alternateText, prefix);

return (
<View style={[styles.autoCompleteSuggestionContainer, styles.ph2]}>
<View style={styles.mentionSuggestionsAvatarContainer}>
<Avatar
source={item.icons[0].source}
size={isIcon ? CONST.AVATAR_SIZE.MENTION_ICON : CONST.AVATAR_SIZE.SMALLER}
name={item.icons[0].name}
type={item.icons[0].type}
fill={theme.success}
fallbackIcon={item.icons[0].fallbackIcon}
/>
const renderSuggestionMenuItem = useCallback(
(item: Mention) => {
const isIcon = item.text === CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT;
const styledDisplayName = getStyledTextArray(item.text, prefix);
const styledHandle = item.text === item.alternateText ? undefined : getStyledTextArray(item.alternateText, prefix);

return (
<View style={[styles.autoCompleteSuggestionContainer, styles.ph2]}>
<View style={styles.mentionSuggestionsAvatarContainer}>
<Avatar
source={item.icons[0].source}
size={isIcon ? CONST.AVATAR_SIZE.MENTION_ICON : CONST.AVATAR_SIZE.SMALLER}
name={item.icons[0].name}
type={item.icons[0].type}
fill={theme.success}
fallbackIcon={item.icons[0].fallbackIcon}
/>
</View>
<Text
style={[styles.mentionSuggestionsText, styles.flexShrink1]}
numberOfLines={1}
>
{styledDisplayName?.map(({text, isColored}, i) => (
<Text
// eslint-disable-next-line react/no-array-index-key
key={`${text}${i}`}
style={[StyleUtils.getColoredBackgroundStyle(theme, isColored), styles.mentionSuggestionsDisplayName]}
>
{text}
</Text>
))}
</Text>
<Text
style={[styles.mentionSuggestionsText, styles.flex1]}
numberOfLines={1}
>
{styledHandle?.map(
({text, isColored}, i) =>
Boolean(text) && (
<Text
// eslint-disable-next-line react/no-array-index-key
key={`${text}${i}`}
style={[StyleUtils.getColoredBackgroundStyle(theme, isColored), styles.mentionSuggestionsHandle]}
>
{text}
</Text>
),
)}
</Text>
</View>
<Text
style={[styles.mentionSuggestionsText, styles.flexShrink1]}
numberOfLines={1}
>
{styledDisplayName?.map(({text, isColored}, i) => (
<Text
// eslint-disable-next-line react/no-array-index-key
key={`${text}${i}`}
style={[StyleUtils.getColoredBackgroundStyle(theme, isColored), styles.mentionSuggestionsDisplayName]}
>
{text}
</Text>
))}
</Text>
<Text
style={[styles.mentionSuggestionsText, styles.flex1]}
numberOfLines={1}
>
{styledHandle?.map(
({text, isColored}, i) =>
Boolean(text) && (
<Text
// eslint-disable-next-line react/no-array-index-key
key={`${text}${i}`}
style={[StyleUtils.getColoredBackgroundStyle(theme, isColored), styles.mentionSuggestionsHandle]}
>
{text}
</Text>
),
)}
</Text>
</View>
);
};
);
},
[styles, theme, prefix],
);

return (
<AutoCompleteSuggestions
Expand Down
Loading