From e55982471819e3e42da57f01f2cd518e032d24ca Mon Sep 17 00:00:00 2001 From: Patrick Loser <69157453+CD-Z@users.noreply.github.com> Date: Tue, 20 Dec 2022 17:09:30 +0100 Subject: [PATCH] feat: FAB for Last Read Chapter in Library (#500) * chapter drawer themed textcolor * added FAB to Library screen + some insets * Added Settings butten Co-authored-by: Patrick --- src/components/SearchbarV2/SearchbarV2.tsx | 6 ++- src/redux/settings/settings.reducer.js | 1 + src/screens/library/LibraryScreen.tsx | 41 ++++++++++++++++++- src/screens/novel/NovelScreen.js | 7 +++- src/screens/settings/SettingsGeneralScreen.js | 9 ++++ src/utils/constants/settings.ts | 1 + 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/components/SearchbarV2/SearchbarV2.tsx b/src/components/SearchbarV2/SearchbarV2.tsx index 50035f06..e096c2f2 100644 --- a/src/components/SearchbarV2/SearchbarV2.tsx +++ b/src/components/SearchbarV2/SearchbarV2.tsx @@ -40,8 +40,10 @@ const Searchbar: React.FC = ({ const searchbarRef = useRef(null); const focusSearchbar = () => searchbarRef.current.focus(); - const { top } = useSafeAreaInsets(); + const { top, right, left } = useSafeAreaInsets(); const marginTop = top + 8; + const marginRight = right + 16; + const marginLeft = left + 16; return ( = ({ styles.searchbarContainer, { marginTop, + marginRight, + marginLeft, backgroundColor: color(theme.primary).alpha(0.08).string(), }, ]} diff --git a/src/redux/settings/settings.reducer.js b/src/redux/settings/settings.reducer.js index b778a5d2..75496a27 100644 --- a/src/redux/settings/settings.reducer.js +++ b/src/redux/settings/settings.reducer.js @@ -31,6 +31,7 @@ export const initialState = { */ downloadedOnlyMode: false, + useLibraryFAB: false, /** * Browse settings diff --git a/src/screens/library/LibraryScreen.tsx b/src/screens/library/LibraryScreen.tsx index 90207a6b..97724df9 100644 --- a/src/screens/library/LibraryScreen.tsx +++ b/src/screens/library/LibraryScreen.tsx @@ -20,7 +20,7 @@ import { useLibrary } from './hooks/useLibrary'; import { useTheme } from '@hooks/useTheme'; import useSearch from '@hooks/useSearch'; import { getString } from '@strings/translations'; -import { Portal } from 'react-native-paper'; +import { FAB, Portal } from 'react-native-paper'; import { useLibrarySettings } from '@hooks/useSettings'; import { markAllChaptersRead, @@ -32,6 +32,10 @@ import useBoolean from '@hooks/useBoolean'; import { debounce, intersection } from 'lodash'; import { ButtonVariation } from '@components/Button/Button'; import { useBackHandler } from '@hooks/useBackHandler'; +import { openChapter } from '@utils/handleNavigateParams'; +import useHistory from '@hooks/useHistory'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { useSettings } from '@hooks/reduxHooks'; type State = NavigationState<{ key: string; @@ -48,6 +52,12 @@ const LibraryScreen = () => { incognitoMode = false, } = useLibrarySettings(); + const { useLibraryFAB = false } = useSettings(); + + const { isLoading: isHistoryLoading, history, error } = useHistory(); + + const { right: rightInset } = useSafeAreaInsets(); + const onChangeText = debounce((text: string) => { setSearchText(text); }, 100); @@ -222,6 +232,29 @@ const LibraryScreen = () => { onIndexChange={setIndex} initialLayout={{ width: layout.width }} /> + {useLibraryFAB && + !isHistoryLoading && + history && + history.length !== 0 && + !error && ( + { + navigate( + 'Chapter' as never, + openChapter(history[0], history[0]) as never, + ); + }} + /> + )} { const theme = useTheme(); const dispatch = useDispatch(); - const { top: topInset } = useSafeAreaInsets(); + const { top: topInset, bottom: bottomInset } = useSafeAreaInsets(); const progressViewOffset = topInset + 32; const { novel, chapters, loading, updating } = useNovel(); @@ -652,7 +652,10 @@ const Novel = ({ route, navigation }) => { chapters.length > 0 && lastReadChapter && ( { defaultChapterSort = 'ORDER BY chapterId ASC', refreshNovelMetadata = false, disableHapticFeedback = false, + useLibraryFAB = false, } = useSettings(); const { showLastUpdateTime = true } = useSelector( @@ -83,6 +84,14 @@ const GenralSettings = ({ navigation }) => { } theme={theme} /> + + dispatch(setAppSettings('useLibraryFAB', !useLibraryFAB)) + } + theme={theme} + /> Novel