Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FilterTypes.Switch and FilterTypes.TextInput support to plugin filters #1271

Merged
merged 2 commits into from
Oct 12, 2024
Merged
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
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
Loading