Skip to content
Draft
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
43 changes: 27 additions & 16 deletions app/modules/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useCallback, type FC } from 'react';
import { FlatList, ScrollView, View } from 'react-native';
import React, { useCallback, useMemo, type FC } from 'react';
import { ScrollView, View } from 'react-native';
import { FlashList } from '@shopify/flash-list';
import { CustomButton, Spinner, Text } from '../../components';
import { Strings } from '../../constants';
import { useTheme } from '../../hooks';
import { scale } from '../../theme';
import styleSheet from './HomeStyles';
import { CategoryChip } from './sub-components/category-chip';
import { CategoryChipShimmer } from './sub-components/category-chip-shimmer';
Expand All @@ -17,7 +19,7 @@ import type { Category, Product } from './HomeTypes';
* SafeAreaView (screenBackground)
* └── HomeHeader (branded greeting)
* └── ScrollView horizontal (category chip row — sticky)
* └── FlatList numColumns={2} (product grid or empty state)
* └── FlashList numColumns={2} (product grid or empty state)
*
* All state and logic delegated to useHome().
*/
Expand Down Expand Up @@ -190,11 +192,24 @@ const HomeScreen: FC = (): React.ReactElement => {
);
}, [shouldShowRefreshError, styles.productStatusContainer, styles.productStatusText]);

const productFeedback =
renderCategoryProductsLoadingState() ||
renderCategoryProductRetryState() ||
renderProductsLoadingState() ||
renderProductRetryState();
const productFeedback = useMemo(
() =>
renderCategoryProductsLoadingState() ||
renderCategoryProductRetryState() ||
renderProductsLoadingState() ||
renderProductRetryState(),
[
renderCategoryProductsLoadingState,
renderCategoryProductRetryState,
renderProductsLoadingState,
renderProductRetryState
]
);

const flashListContentContainerStyle = useMemo(
() => [styles.grid, filteredProducts.length === 0 ? styles.gridEmptyContent : undefined],
[filteredProducts.length, styles.grid, styles.gridEmptyContent]
);

return (
<View style={styles.screen}>
Expand All @@ -212,17 +227,13 @@ const HomeScreen: FC = (): React.ReactElement => {
{renderCategoryStatus()}
{renderProductStatus()}
{productFeedback || (
<FlatList<Product>
removeClippedSubviews
columnWrapperStyle={filteredProducts.length > 0 ? styles.columnWrapper : undefined}
contentContainerStyle={[
styles.grid,
filteredProducts.length === 0 ? styles.gridEmptyContent : undefined
]}
<FlashList<Product>
contentContainerStyle={flashListContentContainerStyle}
data={filteredProducts}
// Estimated height of a ProductCard in the 2-column grid (image + info section), scaled to device.
estimatedItemSize={scale(300)}
ListEmptyComponent={renderEmptyState}
numColumns={2}
windowSize={5}
keyExtractor={keyExtractor}
refreshing={activeCategory === 'all' ? isProductsRefreshing : false}
renderItem={renderProductItem}
Expand Down
6 changes: 1 addition & 5 deletions app/modules/home/HomeStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const styles = (theme: ThemeMode) =>
paddingHorizontal: scale(10),
paddingTop: scale(4)
},
/** columnWrapperStyle for the 2-column FlatList */
columnWrapper: {
justifyContent: 'space-between'
},
/** Empty-state container — centred vertically */
emptyContainer: {
alignItems: 'center',
Expand All @@ -56,7 +52,7 @@ const styles = (theme: ThemeMode) =>
fontSize: scale(15),
textAlign: 'center'
},
/** FlatList contentContainerStyle */
/** FlashList contentContainerStyle */
grid: {
paddingBottom: scale(24),
paddingHorizontal: scale(8)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"preset": "jest-expo"
},
"dependencies": {
"@shopify/flash-list": "2.3.1",
"@expo/config-plugins": "54.0.1",
"@expo-google-fonts/rubik": "0.4.2",
"@expo/vector-icons": "15.0.2",
Expand Down