|
@@ -9,10 +9,13 @@ import {
|
|
|
FlatList,
|
|
FlatList,
|
|
|
TextInput,
|
|
TextInput,
|
|
|
Dimensions,
|
|
Dimensions,
|
|
|
|
|
+ Platform
|
|
|
} from 'react-native';
|
|
} from 'react-native';
|
|
|
import ActionSheet, { ActionSheetRef } from 'react-native-actions-sheet';
|
|
import ActionSheet, { ActionSheetRef } from 'react-native-actions-sheet';
|
|
|
import ChevronIcon from 'assets/icons/travels-screens/down-arrow.svg';
|
|
import ChevronIcon from 'assets/icons/travels-screens/down-arrow.svg';
|
|
|
import { Colors } from 'src/theme';
|
|
import { Colors } from 'src/theme';
|
|
|
|
|
+import CloseSvg from 'assets/icons/close.svg';
|
|
|
|
|
+import CheckSvg from 'assets/icons/mark.svg';
|
|
|
|
|
|
|
|
export interface SelectSheetProps<T extends Record<string, any>> {
|
|
export interface SelectSheetProps<T extends Record<string, any>> {
|
|
|
data: T[];
|
|
data: T[];
|
|
@@ -50,14 +53,11 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
const sheetRef = useRef<ActionSheetRef>(null);
|
|
const sheetRef = useRef<ActionSheetRef>(null);
|
|
|
const [query, setQuery] = useState('');
|
|
const [query, setQuery] = useState('');
|
|
|
|
|
|
|
|
- const selectedItem =
|
|
|
|
|
- value != null ? data.find((item) => item[valueField] === value) : null;
|
|
|
|
|
|
|
+ const selectedItem = value != null ? data.find((item) => item[valueField] === value) : null;
|
|
|
|
|
|
|
|
const filteredData =
|
|
const filteredData =
|
|
|
searchable && query.trim()
|
|
searchable && query.trim()
|
|
|
- ? data.filter((item) =>
|
|
|
|
|
- String(item[labelField]).toLowerCase().includes(query.toLowerCase())
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ ? data.filter((item) => String(item[labelField]).toLowerCase().includes(query.toLowerCase()))
|
|
|
: data;
|
|
: data;
|
|
|
|
|
|
|
|
const handleSelect = useCallback(
|
|
const handleSelect = useCallback(
|
|
@@ -82,10 +82,7 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
style={[styles.trigger, disabled && styles.triggerDisabled, style]}
|
|
style={[styles.trigger, disabled && styles.triggerDisabled, style]}
|
|
|
>
|
|
>
|
|
|
<Text
|
|
<Text
|
|
|
- style={[
|
|
|
|
|
- styles.triggerText,
|
|
|
|
|
- !selectedItem && styles.placeholderText,
|
|
|
|
|
- ]}
|
|
|
|
|
|
|
+ style={[styles.triggerText, !selectedItem && styles.placeholderText]}
|
|
|
numberOfLines={1}
|
|
numberOfLines={1}
|
|
|
>
|
|
>
|
|
|
{selectedItem ? String(selectedItem[labelField]) : placeholder}
|
|
{selectedItem ? String(selectedItem[labelField]) : placeholder}
|
|
@@ -95,7 +92,7 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
|
|
|
|
|
<ActionSheet
|
|
<ActionSheet
|
|
|
ref={sheetRef}
|
|
ref={sheetRef}
|
|
|
- gestureEnabled
|
|
|
|
|
|
|
+ gestureEnabled={Platform.OS !== 'android'}
|
|
|
closeOnTouchBackdrop
|
|
closeOnTouchBackdrop
|
|
|
snapPoints={[initialSnapPoint, 100]}
|
|
snapPoints={[initialSnapPoint, 100]}
|
|
|
initialSnapIndex={0}
|
|
initialSnapIndex={0}
|
|
@@ -104,7 +101,22 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
onClose={() => setQuery('')}
|
|
onClose={() => setQuery('')}
|
|
|
>
|
|
>
|
|
|
<View style={styles.sheetContent}>
|
|
<View style={styles.sheetContent}>
|
|
|
- {!hideTitle && <Text style={styles.sheetTitle}>{placeholder}</Text>}
|
|
|
|
|
|
|
+ {Platform.OS === 'android' && (
|
|
|
|
|
+ <TouchableOpacity
|
|
|
|
|
+ onPress={() => sheetRef.current?.hide()}
|
|
|
|
|
+ style={styles.closeBtnAlone}
|
|
|
|
|
+ hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <CloseSvg />
|
|
|
|
|
+ </TouchableOpacity>
|
|
|
|
|
+ )}
|
|
|
|
|
+ {!hideTitle && (
|
|
|
|
|
+ <View style={styles.titleRow}>
|
|
|
|
|
+ <Text style={[styles.sheetTitle, Platform.OS === 'android' ? { paddingTop: 0 } : {}]}>
|
|
|
|
|
+ {placeholder}
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ )}
|
|
|
|
|
|
|
|
{searchable && (
|
|
{searchable && (
|
|
|
<View style={styles.searchWrapper}>
|
|
<View style={styles.searchWrapper}>
|
|
@@ -150,7 +162,7 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
</Text>
|
|
</Text>
|
|
|
{isSelected && (
|
|
{isSelected && (
|
|
|
<View style={styles.checkmark}>
|
|
<View style={styles.checkmark}>
|
|
|
- <Text style={styles.checkmarkText}>✓</Text>
|
|
|
|
|
|
|
+ <CheckSvg fill={Colors.DARK_BLUE} height={12} width={15} />
|
|
|
</View>
|
|
</View>
|
|
|
)}
|
|
)}
|
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
@@ -161,7 +173,7 @@ export const SelectSheet = <T extends Record<string, any>>({
|
|
|
</ActionSheet>
|
|
</ActionSheet>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
const styles = StyleSheet.create({
|
|
|
trigger: {
|
|
trigger: {
|
|
@@ -171,53 +183,43 @@ const styles = StyleSheet.create({
|
|
|
paddingHorizontal: 12,
|
|
paddingHorizontal: 12,
|
|
|
flexDirection: 'row',
|
|
flexDirection: 'row',
|
|
|
alignItems: 'center',
|
|
alignItems: 'center',
|
|
|
- justifyContent: 'space-between',
|
|
|
|
|
|
|
+ justifyContent: 'space-between'
|
|
|
},
|
|
},
|
|
|
triggerDisabled: {
|
|
triggerDisabled: {
|
|
|
- opacity: 0.5,
|
|
|
|
|
|
|
+ opacity: 0.5
|
|
|
},
|
|
},
|
|
|
triggerText: {
|
|
triggerText: {
|
|
|
flex: 1,
|
|
flex: 1,
|
|
|
fontSize: 15,
|
|
fontSize: 15,
|
|
|
color: Colors.DARK_BLUE,
|
|
color: Colors.DARK_BLUE,
|
|
|
- marginRight: 6,
|
|
|
|
|
|
|
+ marginRight: 6
|
|
|
},
|
|
},
|
|
|
placeholderText: {
|
|
placeholderText: {
|
|
|
- color: Colors.TEXT_GRAY,
|
|
|
|
|
|
|
+ color: Colors.TEXT_GRAY
|
|
|
},
|
|
},
|
|
|
sheetContent: {
|
|
sheetContent: {
|
|
|
height: Dimensions.get('window').height * 0.9,
|
|
height: Dimensions.get('window').height * 0.9,
|
|
|
backgroundColor: Colors.WHITE,
|
|
backgroundColor: Colors.WHITE,
|
|
|
borderTopLeftRadius: 20,
|
|
borderTopLeftRadius: 20,
|
|
|
borderTopRightRadius: 20,
|
|
borderTopRightRadius: 20,
|
|
|
- overflow: 'hidden',
|
|
|
|
|
|
|
+ overflow: 'hidden'
|
|
|
},
|
|
},
|
|
|
sheetContainer: {
|
|
sheetContainer: {
|
|
|
height: '90%',
|
|
height: '90%',
|
|
|
backgroundColor: Colors.WHITE,
|
|
backgroundColor: Colors.WHITE,
|
|
|
borderTopLeftRadius: 20,
|
|
borderTopLeftRadius: 20,
|
|
|
- borderTopRightRadius: 20,
|
|
|
|
|
|
|
+ borderTopRightRadius: 20
|
|
|
},
|
|
},
|
|
|
indicator: {
|
|
indicator: {
|
|
|
width: 44,
|
|
width: 44,
|
|
|
height: 5,
|
|
height: 5,
|
|
|
borderRadius: 3,
|
|
borderRadius: 3,
|
|
|
backgroundColor: Colors.LIGHT_GRAY,
|
|
backgroundColor: Colors.LIGHT_GRAY,
|
|
|
- marginTop: 8,
|
|
|
|
|
- },
|
|
|
|
|
- sheetTitle: {
|
|
|
|
|
- fontSize: 18,
|
|
|
|
|
- fontWeight: '700',
|
|
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
|
|
- paddingVertical: 12,
|
|
|
|
|
- paddingHorizontal: 24,
|
|
|
|
|
- textAlign: 'center',
|
|
|
|
|
- borderBottomWidth: StyleSheet.hairlineWidth,
|
|
|
|
|
- borderBottomColor: Colors.DARK_LIGHT,
|
|
|
|
|
|
|
+ marginTop: 8
|
|
|
},
|
|
},
|
|
|
searchWrapper: {
|
|
searchWrapper: {
|
|
|
paddingHorizontal: 16,
|
|
paddingHorizontal: 16,
|
|
|
- paddingVertical: 12,
|
|
|
|
|
|
|
+ paddingVertical: 12
|
|
|
},
|
|
},
|
|
|
searchInput: {
|
|
searchInput: {
|
|
|
height: 44,
|
|
height: 44,
|
|
@@ -225,38 +227,62 @@ const styles = StyleSheet.create({
|
|
|
borderRadius: 6,
|
|
borderRadius: 6,
|
|
|
paddingHorizontal: 16,
|
|
paddingHorizontal: 16,
|
|
|
fontSize: 16,
|
|
fontSize: 16,
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
|
|
|
|
+ color: Colors.DARK_BLUE
|
|
|
},
|
|
},
|
|
|
list: {
|
|
list: {
|
|
|
- flex: 1,
|
|
|
|
|
|
|
+ flex: 1
|
|
|
},
|
|
},
|
|
|
listContent: {
|
|
listContent: {
|
|
|
paddingBottom: 40,
|
|
paddingBottom: 40,
|
|
|
- paddingTop: 8,
|
|
|
|
|
|
|
+ paddingTop: 8
|
|
|
},
|
|
},
|
|
|
option: {
|
|
option: {
|
|
|
flexDirection: 'row',
|
|
flexDirection: 'row',
|
|
|
alignItems: 'center',
|
|
alignItems: 'center',
|
|
|
paddingHorizontal: 24,
|
|
paddingHorizontal: 24,
|
|
|
- paddingVertical: 16,
|
|
|
|
|
|
|
+ paddingVertical: 16
|
|
|
},
|
|
},
|
|
|
optionText: {
|
|
optionText: {
|
|
|
flex: 1,
|
|
flex: 1,
|
|
|
fontSize: 16,
|
|
fontSize: 16,
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
|
|
|
|
+ color: Colors.DARK_BLUE
|
|
|
},
|
|
},
|
|
|
optionTextSelectedWeight: {
|
|
optionTextSelectedWeight: {
|
|
|
- fontWeight: '700',
|
|
|
|
|
|
|
+ fontWeight: '700'
|
|
|
},
|
|
},
|
|
|
checkmark: {
|
|
checkmark: {
|
|
|
- marginLeft: 12,
|
|
|
|
|
|
|
+ marginLeft: 12
|
|
|
},
|
|
},
|
|
|
checkmarkText: {
|
|
checkmarkText: {
|
|
|
fontSize: 18,
|
|
fontSize: 18,
|
|
|
color: Colors.DARK_BLUE,
|
|
color: Colors.DARK_BLUE,
|
|
|
- fontWeight: '700',
|
|
|
|
|
|
|
+ fontWeight: '700'
|
|
|
},
|
|
},
|
|
|
chevron: {
|
|
chevron: {
|
|
|
- marginLeft: 2,
|
|
|
|
|
|
|
+ marginLeft: 2
|
|
|
},
|
|
},
|
|
|
|
|
+ titleRow: {
|
|
|
|
|
+ flexDirection: 'row',
|
|
|
|
|
+ alignItems: 'center',
|
|
|
|
|
+ borderBottomWidth: StyleSheet.hairlineWidth,
|
|
|
|
|
+ borderBottomColor: Colors.DARK_LIGHT
|
|
|
|
|
+ },
|
|
|
|
|
+ sheetTitle: {
|
|
|
|
|
+ flex: 1,
|
|
|
|
|
+ fontSize: 16,
|
|
|
|
|
+ fontWeight: '700',
|
|
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
|
|
+ paddingVertical: 12,
|
|
|
|
|
+ paddingHorizontal: 24,
|
|
|
|
|
+ textAlign: 'center'
|
|
|
|
|
+ },
|
|
|
|
|
+ closeBtn: {
|
|
|
|
|
+ paddingHorizontal: 16,
|
|
|
|
|
+ paddingVertical: 12
|
|
|
|
|
+ },
|
|
|
|
|
+ closeBtnAlone: {
|
|
|
|
|
+ alignSelf: 'flex-end',
|
|
|
|
|
+ paddingHorizontal: 16,
|
|
|
|
|
+ paddingTop: 16
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|