From 3f9c662c68f39ffae86bbe21bb47ea1e0d7a3a00 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Mon, 4 Oct 2021 13:26:49 +0530 Subject: [PATCH] Refactor Checkbox and RadioButton --- src/components/Checkbox/Checkbox.js | 96 +++++++------------ src/components/RadioButton/RadioButton.js | 33 +++++++ src/components/Searchbar/Searchbar.js | 1 - .../library/components/LibraryBottomSheet.js | 24 ++++- .../more/components/DisplayModeModal.js | 4 +- src/screens/more/components/GridSizeModal.js | 9 +- .../novel/components/NovelBottomSheet.js | 38 +++----- src/screens/setting/SettingsGeneral.js | 1 - 8 files changed, 107 insertions(+), 99 deletions(-) create mode 100644 src/components/RadioButton/RadioButton.js diff --git a/src/components/Checkbox/Checkbox.js b/src/components/Checkbox/Checkbox.js index a77ade49..35ae1930 100644 --- a/src/components/Checkbox/Checkbox.js +++ b/src/components/Checkbox/Checkbox.js @@ -1,85 +1,59 @@ import React from 'react'; import {Pressable, StyleSheet, Text, View} from 'react-native'; +import {Checkbox as PaperCheckbox} from 'react-native-paper'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; export const Checkbox = ({label, status, onPress, theme}) => ( - - - - {label} - - {status && ( - - )} - - + color={theme.colorAccent} + uncheckedColor={theme.textColorSecondary} + /> + {label} + ); export const SortItem = ({label, status, onPress, theme}) => ( - - - - {label} - - {status && ( - - )} - - + {status && ( + + )} + {label} + ); const styles = StyleSheet.create({ - checkboxContainer: { - borderRadius: 8, - overflow: 'hidden', - marginVertical: 4, - }, pressable: { paddingHorizontal: 16, - paddingVertical: 12, + paddingVertical: 8, flexDirection: 'row', - justifyContent: 'space-between', + alignItems: 'center', }, icon: { position: 'absolute', - right: 16, + left: 24, alignSelf: 'center', }, }); diff --git a/src/components/RadioButton/RadioButton.js b/src/components/RadioButton/RadioButton.js new file mode 100644 index 00000000..34f8f73c --- /dev/null +++ b/src/components/RadioButton/RadioButton.js @@ -0,0 +1,33 @@ +import React from 'react'; +import {Pressable, StyleSheet, Text, View} from 'react-native'; +import {RadioButton as PaperRadioButton} from 'react-native-paper'; + +export const RadioButton = ({label, status, onPress, theme}) => ( + + + {label} + +); + +const styles = StyleSheet.create({ + pressable: { + paddingHorizontal: 16, + paddingVertical: 8, + flexDirection: 'row', + alignItems: 'center', + }, + icon: { + position: 'absolute', + left: 24, + alignSelf: 'center', + }, +}); diff --git a/src/components/Searchbar/Searchbar.js b/src/components/Searchbar/Searchbar.js index 1db8848d..585916cf 100644 --- a/src/components/Searchbar/Searchbar.js +++ b/src/components/Searchbar/Searchbar.js @@ -79,7 +79,6 @@ const styles = StyleSheet.create({ marginHorizontal: 16, borderRadius: 50, overflow: 'hidden', - elevation: 1, }, pressable: { flexDirection: 'row', diff --git a/src/screens/library/components/LibraryBottomSheet.js b/src/screens/library/components/LibraryBottomSheet.js index e330cc42..a815c412 100644 --- a/src/screens/library/components/LibraryBottomSheet.js +++ b/src/screens/library/components/LibraryBottomSheet.js @@ -14,6 +14,7 @@ import {filterLibrary} from '../../../redux/library/library.actions'; import {useSettings} from '../../../hooks/reduxHooks'; import {setAppSettings} from '../../../redux/settings/settings.actions'; import {Checkbox, SortItem} from '../../../components/Checkbox/Checkbox'; +import {RadioButton} from '../../../components/RadioButton/RadioButton'; const LibraryFilterSheet = ({ bottomSheetRef, @@ -26,7 +27,7 @@ const LibraryFilterSheet = ({ const [animatedValue] = useState(new Animated.Value(0)); const FirstRoute = () => ( - + ( - + {sortOrders.map((item, index) => ( { return displayModes.map(mode => ( - ( - + ( + // {route.title} + // )} inactiveColor={theme.textColorSecondary} activeColor={theme.colorAccent} diff --git a/src/screens/more/components/DisplayModeModal.js b/src/screens/more/components/DisplayModeModal.js index 98e23bad..20d1b465 100644 --- a/src/screens/more/components/DisplayModeModal.js +++ b/src/screens/more/components/DisplayModeModal.js @@ -3,7 +3,7 @@ import {StyleSheet} from 'react-native'; import {Portal, Modal} from 'react-native-paper'; -import {Checkbox} from '../../../components/Checkbox/Checkbox'; +import {RadioButton} from '../../../components/RadioButton/RadioButton'; import {setAppSettings} from '../../../redux/settings/settings.actions'; @@ -23,7 +23,7 @@ const DisplayModeModal = ({ const renderCheckboxes = () => { return displayModes.map(mode => ( - diff --git a/src/screens/more/components/GridSizeModal.js b/src/screens/more/components/GridSizeModal.js index cd80c067..88769e04 100644 --- a/src/screens/more/components/GridSizeModal.js +++ b/src/screens/more/components/GridSizeModal.js @@ -1,10 +1,11 @@ import React from 'react'; import {Text, StyleSheet} from 'react-native'; + import {Portal, Modal} from 'react-native-paper'; -import Slider from '@react-native-community/slider'; -import {RadioButton, RadioButtonGroup} from '../../../components/RadioButton'; + +import {RadioButton} from '../../../components/RadioButton/RadioButton'; + import {setNovelsPerRow} from '../../../redux/settings/settings.actions'; -import {Checkbox} from '../../../components/Checkbox/Checkbox'; const GridSizeModal = ({ dispatch, @@ -40,7 +41,7 @@ const GridSizeModal = ({ {`${novelsPerRow} per row`} {Object.keys(gridSizes).map(item => ( - ( - filter.match('AND downloaded=1') ? filterChapters(filter.replace(' AND downloaded=1', '')) : filterChapters(filter + ' AND downloaded=1') } /> - { if (filter.match('AND `read`=0')) { @@ -75,15 +67,11 @@ const ChaptersSettingsSheet = ({ } }} /> - { filter.match('AND bookmark=1') ? filterChapters(filter.replace(' AND bookmark=1', '')) @@ -94,7 +82,7 @@ const ChaptersSettingsSheet = ({ ); const SecondRoute = () => ( - + ( - + ( {route.title} )} diff --git a/src/screens/setting/SettingsGeneral.js b/src/screens/setting/SettingsGeneral.js index 166a5df0..f703ec35 100644 --- a/src/screens/setting/SettingsGeneral.js +++ b/src/screens/setting/SettingsGeneral.js @@ -59,7 +59,6 @@ const GenralSettings = ({navigation}) => { - Display