2023-09-08 13:47:42 +00:00
|
|
|
import { Text, ViewProps } from 'react-native';
|
2022-05-19 16:53:45 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { BottomSheetView, BottomSheetFlatList } from '@gorhom/bottom-sheet';
|
2023-09-08 13:47:42 +00:00
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
2022-05-19 16:53:45 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import { IActionSheetItem, Item } from './Item';
|
|
|
|
import { TActionSheetOptionsItem } from './Provider';
|
|
|
|
import styles from './styles';
|
|
|
|
import * as List from '../List';
|
2022-08-17 13:32:21 +00:00
|
|
|
import Touch from '../Touch';
|
2022-05-19 16:53:45 +00:00
|
|
|
|
|
|
|
interface IBottomSheetContentProps {
|
|
|
|
hasCancel?: boolean;
|
|
|
|
options?: TActionSheetOptionsItem[];
|
|
|
|
hide: () => void;
|
|
|
|
children?: React.ReactElement | null;
|
2023-09-08 13:47:42 +00:00
|
|
|
onLayout: ViewProps['onLayout'];
|
2022-05-19 16:53:45 +00:00
|
|
|
}
|
|
|
|
|
2023-09-08 13:47:42 +00:00
|
|
|
const BottomSheetContent = React.memo(({ options, hasCancel, hide, children, onLayout }: IBottomSheetContentProps) => {
|
2022-08-17 13:32:21 +00:00
|
|
|
const { colors } = useTheme();
|
2023-09-08 13:47:42 +00:00
|
|
|
const { bottom } = useSafeAreaInsets();
|
2022-05-19 16:53:45 +00:00
|
|
|
|
|
|
|
const renderFooter = () =>
|
|
|
|
hasCancel ? (
|
2022-08-17 13:32:21 +00:00
|
|
|
<Touch
|
2022-05-19 16:53:45 +00:00
|
|
|
onPress={hide}
|
|
|
|
style={[styles.button, { backgroundColor: colors.auxiliaryBackground }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
accessibilityLabel={I18n.t('Cancel')}
|
|
|
|
>
|
2022-05-19 16:53:45 +00:00
|
|
|
<Text style={[styles.text, { color: colors.bodyText }]}>{I18n.t('Cancel')}</Text>
|
2022-08-17 13:32:21 +00:00
|
|
|
</Touch>
|
2022-05-19 16:53:45 +00:00
|
|
|
) : null;
|
|
|
|
|
|
|
|
const renderItem = ({ item }: { item: IActionSheetItem['item'] }) => <Item item={item} hide={hide} />;
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
return (
|
|
|
|
<BottomSheetFlatList
|
2022-05-26 17:10:24 +00:00
|
|
|
testID='action-sheet'
|
2022-05-19 16:53:45 +00:00
|
|
|
data={options}
|
|
|
|
refreshing={false}
|
|
|
|
keyExtractor={item => item.title}
|
|
|
|
bounces={true}
|
|
|
|
renderItem={renderItem}
|
2023-09-08 13:47:42 +00:00
|
|
|
style={{ backgroundColor: colors.focusedBackground, paddingBottom: bottom }}
|
2022-05-19 16:53:45 +00:00
|
|
|
keyboardDismissMode='interactive'
|
|
|
|
indicatorStyle='black'
|
|
|
|
contentContainerStyle={styles.content}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
|
|
|
ListHeaderComponent={List.Separator}
|
|
|
|
ListFooterComponent={renderFooter}
|
2023-09-08 13:47:42 +00:00
|
|
|
onLayout={onLayout}
|
2022-05-19 16:53:45 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-10-21 18:27:55 +00:00
|
|
|
return (
|
2023-09-08 13:47:42 +00:00
|
|
|
<BottomSheetView testID='action-sheet' style={[styles.contentContainer, { paddingBottom: bottom }]} onLayout={onLayout}>
|
2022-10-21 18:27:55 +00:00
|
|
|
{children}
|
|
|
|
</BottomSheetView>
|
|
|
|
);
|
2022-05-19 16:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default BottomSheetContent;
|