fix: typo and render data

This commit is contained in:
Jakub Grzywacz 2021-07-30 13:43:51 +02:00
parent 55ae233a94
commit 69e05326ce
No known key found for this signature in database
GPG Key ID: 5BBB685871FF63C4
1 changed files with 19 additions and 10 deletions

View File

@ -39,7 +39,7 @@ export const Categories = ({ flatListRef, scrollNav }: CategoriesProps) => {
[disabledCategory, flatListRef] [disabledCategory, flatListRef]
); );
const rendarItem = React.useCallback( const renderItem = React.useCallback(
({ item, index }: { item: CategoryNavigationItem; index: number }) => ( ({ item, index }: { item: CategoryNavigationItem; index: number }) => (
<CategoryItem <CategoryItem
item={item} item={item}
@ -66,9 +66,6 @@ export const Categories = ({ flatListRef, scrollNav }: CategoriesProps) => {
), ),
[activeCategoryContainerColor, scrollNav] [activeCategoryContainerColor, scrollNav]
); );
const isRecentlyUsedHidden = (category: CategoryTypes) =>
category === 'recently_used' &&
(keyboardState.recentlyUsed.length === 0 || !enableRecentlyUsed);
const getStylesBasedOnPosition = () => { const getStylesBasedOnPosition = () => {
const style: ViewStyle[] = [styles.navigation]; const style: ViewStyle[] = [styles.navigation];
@ -96,17 +93,29 @@ export const Categories = ({ flatListRef, scrollNav }: CategoriesProps) => {
return style; return style;
}; };
const renderData = React.useMemo(() => {
const isRecentlyUsedHidden = (category: CategoryTypes) =>
category === 'recently_used' &&
(keyboardState.recentlyUsed.length === 0 || !enableRecentlyUsed);
return CATEGORIES_NAVIGATION.filter(({ category }) => {
if (searchPhrase === '' && category === 'search') return false;
if (isRecentlyUsedHidden(category)) return false;
return !disabledCategory.includes(category);
});
}, [
disabledCategory,
enableRecentlyUsed,
keyboardState.recentlyUsed.length,
searchPhrase,
]);
return ( return (
<View style={[categoryPosition === 'floating' && styles.floating]}> <View style={[categoryPosition === 'floating' && styles.floating]}>
<View style={getStylesBasedOnPosition()}> <View style={getStylesBasedOnPosition()}>
<FlatList <FlatList
data={CATEGORIES_NAVIGATION.filter(({ category }) => { data={renderData}
if (searchPhrase === '' && category === 'search') return false;
if (isRecentlyUsedHidden(category)) return false;
return !disabledCategory.includes(category);
})}
keyExtractor={(item) => item.category} keyExtractor={(item) => item.category}
renderItem={rendarItem} renderItem={renderItem}
ItemSeparatorComponent={() => <View style={styles.separator} />} ItemSeparatorComponent={() => <View style={styles.separator} />}
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
horizontal={true} horizontal={true}