Skip to content

Commit

Permalink
feat: Add Switch and TextInput Support to Plugin Filters (#1271)
Browse files Browse the repository at this point in the history
* Add FilterTypes.Switch support to plugin filters

* Add FilterTypes.TextInput support to plugin filters
  • Loading branch information
Soopyboo32 authored Oct 12, 2024
1 parent 9c68260 commit 8245e77
Showing 1 changed file with 96 additions and 1 deletion.
97 changes: 96 additions & 1 deletion src/screens/BrowseSourceScreen/components/FilterBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getValueFor } from './filterUtils';
import { getString } from '@strings/translations';
import { ThemeColors } from '@theme/types';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Switch from '@components/Switch/Switch';

const insertOrRemoveIntoArray = (array: string[], val: string): string[] =>
array.indexOf(val) > -1 ? array.filter(ele => ele !== val) : [...array, val];
Expand Down Expand Up @@ -56,6 +57,43 @@ const FilterItem: React.FC<FilterItemProps> = ({
setFalse: closeCard,
} = useBoolean();
const { width: screenWidth } = useWindowDimensions();
if (filter.type === FilterTypes.TextInput) {
const value = getValueFor<(typeof filter)['type']>(
filter,
selectedFilters[filterKey],
);
return (
<View style={styles.textContainer}>
<TextInput
style={{ flex: 1, width: screenWidth - 48 }}
mode="outlined"
label={
<Text
style={[
styles.label,
{
color: theme.onSurface,
backgroundColor: overlay(2, theme.surface),
},
]}
>
{` ${filter.label} `}
</Text>
}
defaultValue={value}
theme={{ colors: { background: 'transparent' } }}
outlineColor={theme.onSurface}
textColor={theme.onSurface}
onChangeText={text =>
setSelectedFilters(prevState => ({
...prevState,
[filterKey]: { value: text, type: FilterTypes.TextInput },
}))
}
/>
</View>
);
}
if (filter.type === FilterTypes.Picker) {
const value = getValueFor<(typeof filter)['type']>(
filter,
Expand Down Expand Up @@ -83,7 +121,7 @@ const FilterItem: React.FC<FilterItemProps> = ({
styles.label,
{
color: isVisible ? theme.primary : theme.onSurface,
backgroundColor: theme.surface,
backgroundColor: overlay(2, theme.surface),
},
]}
>
Expand Down Expand Up @@ -165,6 +203,42 @@ const FilterItem: React.FC<FilterItemProps> = ({
</View>
);
}
if (filter.type === FilterTypes.Switch) {
const value = getValueFor<(typeof filter)['type']>(
filter,
selectedFilters[filterKey],
);
return (
<Pressable
android_ripple={{ color: theme.rippleColor }}
style={[styles.container]}
onPress={() => {
setSelectedFilters(prevState => ({
...prevState,
[filterKey]: { value: !value, type: FilterTypes.Switch },
}));
}}
>
<View style={styles.switchContainer}>
<View style={styles.switchLabelContainer}>
<Text style={[{ color: theme.onSurface }, styles.switchLabel]}>
{filter.label}
</Text>
</View>
<Switch
value={value}
onValueChange={() => {
setSelectedFilters(prevState => ({
...prevState,
[filterKey]: { value: !value, type: FilterTypes.Switch },
}));
}}
theme={theme}
/>
</View>
</Pressable>
);
}
if (filter.type === FilterTypes.ExcludableCheckboxGroup) {
const value = getValueFor<(typeof filter)['type']>(
filter,
Expand Down Expand Up @@ -344,6 +418,27 @@ const styles = StyleSheet.create({
paddingBottom: 8,
paddingTop: 8,
},
switchLabelContainer: {
flex: 1,
justifyContent: 'center',
},
switchLabel: {
fontSize: 16,
},
switchContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginVertical: 8,
paddingHorizontal: 24,
},
textContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginVertical: 8,
paddingHorizontal: 24,
},
pickerContainer: {
flex: 1,
flexDirection: 'row',
Expand Down

0 comments on commit 8245e77

Please sign in to comment.