Skip to content

Commit

Permalink
Merge pull request #52009 from huult/51310-fix-emoji-picker-empty-cat…
Browse files Browse the repository at this point in the history
…egories-on-search

fix empty categories from briefly displaying when search begins
  • Loading branch information
lakchote authored Nov 8, 2024
2 parents c658375 + 3a43cb9 commit 17cae11
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type {ListRenderItem} from '@shopify/flash-list';
import lodashDebounce from 'lodash/debounce';
import React, {useCallback} from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import type {Emoji} from '@assets/emojis/types';
import EmojiPickerMenuItem from '@components/EmojiPicker/EmojiPickerMenuItem';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
Expand Down Expand Up @@ -43,25 +44,28 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r
} = useEmojiPickerMenu();
const StyleUtils = useStyleUtils();

const updateEmojiList = (emojiData: EmojiUtils.EmojiPickerList | Emoji[], headerData: number[] = []) => {
setFilteredEmojis(emojiData);
setHeaderIndices(headerData);

InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
emojiListRef.current?.scrollToOffset({offset: 0, animated: false});
});
});
};

/**
* Filter the entire list of emojis to only emojis that have the search term in their keywords
*/
const filterEmojis = lodashDebounce((searchTerm: string) => {
const [normalizedSearchTerm, newFilteredEmojiList] = suggestEmojis(searchTerm);

if (emojiListRef.current) {
emojiListRef.current.scrollToOffset({offset: 0, animated: false});
}

if (normalizedSearchTerm === '') {
setFilteredEmojis(allEmojis);
setHeaderIndices(headerRowIndices);

return;
updateEmojiList(allEmojis, headerRowIndices);
} else {
updateEmojiList(newFilteredEmojiList ?? [], []);
}

setFilteredEmojis(newFilteredEmojiList ?? []);
setHeaderIndices([]);
}, 300);

const scrollToHeader = (headerIndex: number) => {
Expand Down

0 comments on commit 17cae11

Please sign in to comment.