react-native-elements#BottomSheet TypeScript Examples
The following examples show how to use
react-native-elements#BottomSheet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductListScreen.tsx From magento_react_native_graphql with MIT License | 4 votes |
ProductListScreen = ({
navigation,
route: {
params: { categoryId },
},
}: Props): React.ReactElement => {
const { data, networkStatus, error, refresh, loadMore } = useCategoryProducts(
{
categoryId,
},
);
const { isVisible, selectedIndex, setVisible, sortOptions } = useSort({
onPress: refresh,
});
const { theme } = useContext(ThemeContext);
useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<CustomHeaderButtons>
<CustomHeaderItem
title={translate('common.sort')}
iconName="sort"
onPress={() => setVisible(true)}
/>
</CustomHeaderButtons>
),
});
}, [navigation]);
const onProductItemClicked = (index: number) => {
if (data?.products?.items) {
navigation.navigate(Routes.NAVIGATION_TO_PRODUCT_DETAILS_SCREEN, {
name: data.products.items[index].name,
sku: data.products.items[index].sku,
});
}
};
const renderItem = ({
item,
index,
}: {
item: ProductInListType;
index: number;
}) => {
return (
<ProductListItem
item={item}
index={index}
onPress={onProductItemClicked}
/>
);
};
const renderFooterComponent = () =>
(networkStatus === NetworkStatus.fetchMore && (
<View style={styles.footerContainer}>
<Spinner />
</View>
)) || <></>;
return (
<GenericTemplate errorMessage={error?.message}>
<FlatList
numColumns={2}
data={data?.products?.items ?? []}
renderItem={renderItem}
keyExtractor={item => `productListItem${item.sku}`}
refreshControl={
<RefreshControl
refreshing={
networkStatus === NetworkStatus.refetch ||
networkStatus === NetworkStatus.loading
}
onRefresh={refresh}
/>
}
onEndReached={loadMore}
ListFooterComponent={renderFooterComponent}
/>
<BottomSheet isVisible={isVisible} containerStyle={styles.sortContainer}>
{sortOptions.map((option, index) => (
<ListItem
key={option.title}
containerStyle={[
option.containerStyle,
selectedIndex === index && {
backgroundColor: theme.colors?.grey5,
},
]}
onPress={option.onPress}
>
<ListItem.Content>
<ListItem.Title style={option.titleStyle}>
{option.title}
</ListItem.Title>
</ListItem.Content>
</ListItem>
))}
</BottomSheet>
</GenericTemplate>
);
}