Skip to content

Commit

Permalink
Merge pull request Expensify#31703 from callstack-internal/adhorodysk…
Browse files Browse the repository at this point in the history
…i/refactor/flashlist-migration-bacs

chore: memoed renderItem on emoji and mention suggestion lists
  • Loading branch information
roryabraham authored Dec 1, 2023
2 parents 16c5d39 + 9070a4e commit 414c08c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 75 deletions.
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

0 comments on commit 414c08c

Please sign in to comment.