From 8d0d2c38d3c688ec19938a8778e87c2d45709af4 Mon Sep 17 00:00:00 2001 From: DattatreyaReddy Panta <58727124+DattatreyaReddy@users.noreply.github.com> Date: Thu, 16 Mar 2023 20:43:39 +0530 Subject: [PATCH] added disable reader scroll animation (#150) --- lib/src/constants/db_keys.dart | 1 + .../reader_mode/continuous_reader_mode.dart | 40 +++++++++++------- .../reader/reader_settings_screen.dart | 2 + .../reader_invert_tap_tile.dart | 4 +- .../reader_scroll_animation_tile.dart | 41 +++++++++++++++++++ .../reader_scroll_animation_tile.g.dart | 26 ++++++++++++ lib/src/l10n/app_en.arb | 4 ++ 7 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart create mode 100644 lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.g.dart diff --git a/lib/src/constants/db_keys.dart b/lib/src/constants/db_keys.dart index fd71a1bf..c1133531 100644 --- a/lib/src/constants/db_keys.dart +++ b/lib/src/constants/db_keys.dart @@ -21,6 +21,7 @@ enum DBKeys { readerMagnifierSize(1.0), readerNavigationLayout(ReaderNavigationLayout.disabled), invertTap(false), + scrollAnimation(true), showNSFW(true), downloadedBadge(true), unreadBadge(true), diff --git a/lib/src/features/manga_book/presentation/reader/widgets/reader_mode/continuous_reader_mode.dart b/lib/src/features/manga_book/presentation/reader/widgets/reader_mode/continuous_reader_mode.dart index 1ae3cc78..fe6da550 100644 --- a/lib/src/features/manga_book/presentation/reader/widgets/reader_mode/continuous_reader_mode.dart +++ b/lib/src/features/manga_book/presentation/reader/widgets/reader_mode/continuous_reader_mode.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../../../../../../constants/app_constants.dart'; @@ -14,12 +15,13 @@ import '../../../../../../constants/endpoints.dart'; import '../../../../../../utils/extensions/custom_extensions.dart'; import '../../../../../../widgets/server_image.dart'; +import '../../../../../settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart'; import '../../../../domain/chapter/chapter_model.dart'; import '../../../../domain/manga/manga_model.dart'; import '../chapter_separator.dart'; import '../reader_wrapper.dart'; -class ContinuousReaderMode extends HookWidget { +class ContinuousReaderMode extends HookConsumerWidget { const ContinuousReaderMode({ super.key, required this.manga, @@ -36,7 +38,7 @@ class ContinuousReaderMode extends HookWidget { final Axis scrollDirection; final bool reverse; @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final scrollController = useMemoized(() => ItemScrollController()); final positionsListener = useMemoized(() => ItemPositionsListener.create()); final currentIndex = useState( @@ -76,12 +78,17 @@ class ContinuousReaderMode extends HookWidget { onPrevious: () { final ItemPosition itemPosition = positionsListener.itemPositions.value.toList().first; - scrollController.scrollTo( - index: itemPosition.index, - duration: kDuration, - curve: kCurve, - alignment: itemPosition.itemLeadingEdge + .8, - ); + ref.read(readerScrollAnimationProvider).ifNull(true) + ? scrollController.scrollTo( + index: itemPosition.index, + duration: kDuration, + curve: kCurve, + alignment: itemPosition.itemLeadingEdge + .8, + ) + : scrollController.jumpTo( + index: itemPosition.index, + alignment: itemPosition.itemLeadingEdge + .8, + ); }, onNext: () { ItemPosition itemPosition = positionsListener.itemPositions.value.first; @@ -94,12 +101,17 @@ class ContinuousReaderMode extends HookWidget { index = itemPosition.index + 1; alignment = 0; } - scrollController.scrollTo( - index: index, - duration: kDuration, - curve: kCurve, - alignment: alignment, - ); + ref.read(readerScrollAnimationProvider).ifNull(true) + ? scrollController.scrollTo( + index: index, + duration: kDuration, + curve: kCurve, + alignment: alignment, + ) + : scrollController.jumpTo( + index: index, + alignment: alignment, + ); }, child: ScrollablePositionedList.separated( itemScrollController: scrollController, diff --git a/lib/src/features/settings/presentation/reader/reader_settings_screen.dart b/lib/src/features/settings/presentation/reader/reader_settings_screen.dart index f757a609..ada456f3 100644 --- a/lib/src/features/settings/presentation/reader/reader_settings_screen.dart +++ b/lib/src/features/settings/presentation/reader/reader_settings_screen.dart @@ -12,6 +12,7 @@ import 'widgets/reader_magnifier_size_slider/reader_magnifier_size_slider.dart'; import 'widgets/reader_mode_tile/reader_mode_tile.dart'; import 'widgets/reader_navigation_layout_tile/reader_navigation_layout_tile.dart'; import 'widgets/reader_padding_slider/reader_padding_slider.dart'; +import 'widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart'; class ReaderSettingsScreen extends StatelessWidget { const ReaderSettingsScreen({super.key}); @@ -25,6 +26,7 @@ class ReaderSettingsScreen extends StatelessWidget { ReaderModeTile(), ReaderNavigationLayoutTile(), ReaderInvertTapTile(), + ReaderScrollAnimationTile(), ReaderPaddingSlider(), ReaderMagnifierSizeSlider(), ], diff --git a/lib/src/features/settings/presentation/reader/widgets/reader_invert_tap_tile/reader_invert_tap_tile.dart b/lib/src/features/settings/presentation/reader/widgets/reader_invert_tap_tile/reader_invert_tap_tile.dart index f3fb04bd..94596c8b 100644 --- a/lib/src/features/settings/presentation/reader/widgets/reader_invert_tap_tile/reader_invert_tap_tile.dart +++ b/lib/src/features/settings/presentation/reader/widgets/reader_invert_tap_tile/reader_invert_tap_tile.dart @@ -32,9 +32,7 @@ class ReaderInvertTapTile extends HookConsumerWidget { return SwitchListTile( controlAffinity: ListTileControlAffinity.trailing, secondary: const Icon(Icons.switch_left_rounded), - title: Text( - context.l10n!.readerNavigationLayoutInvert, - ), + title: Text(context.l10n!.readerNavigationLayoutInvert), onChanged: ref.read(invertTapProvider.notifier).update, value: ref.watch(invertTapProvider).ifNull(), ); diff --git a/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart b/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart new file mode 100644 index 00000000..36e845d3 --- /dev/null +++ b/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2022 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +import '../../../../../../constants/db_keys.dart'; + +import '../../../../../../utils/extensions/custom_extensions.dart'; +import '../../../../../../utils/mixin/shared_preferences_client_mixin.dart'; + +part 'reader_scroll_animation_tile.g.dart'; + +@riverpod +class ReaderScrollAnimation extends _$ReaderScrollAnimation + with SharedPreferenceClientMixin { + @override + bool? build() => initialize( + ref, + key: DBKeys.scrollAnimation.name, + initial: DBKeys.scrollAnimation.initial, + ); +} + +class ReaderScrollAnimationTile extends HookConsumerWidget { + const ReaderScrollAnimationTile({super.key}); + @override + Widget build(BuildContext context, WidgetRef ref) { + return SwitchListTile( + controlAffinity: ListTileControlAffinity.trailing, + secondary: const Icon(Icons.animation_rounded), + title: Text(context.l10n!.readerScrollAnimation), + onChanged: ref.read(readerScrollAnimationProvider.notifier).update, + value: ref.watch(readerScrollAnimationProvider).ifNull(), + ); + } +} diff --git a/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.g.dart b/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.g.dart new file mode 100644 index 00000000..2eea6804 --- /dev/null +++ b/lib/src/features/settings/presentation/reader/widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'reader_scroll_animation_tile.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$readerScrollAnimationHash() => + r'5795593f5a067596e2bcbd198ae9bf79e584e4e8'; + +/// See also [ReaderScrollAnimation]. +@ProviderFor(ReaderScrollAnimation) +final readerScrollAnimationProvider = + AutoDisposeNotifierProvider.internal( + ReaderScrollAnimation.new, + name: r'readerScrollAnimationProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$readerScrollAnimationHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$ReaderScrollAnimation = AutoDisposeNotifier; +// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions diff --git a/lib/src/l10n/app_en.arb b/lib/src/l10n/app_en.arb index c1d23e27..d3567f50 100644 --- a/lib/src/l10n/app_en.arb +++ b/lib/src/l10n/app_en.arb @@ -436,6 +436,9 @@ "@readerNavigationLayoutInvert": { "description": "Switch title to invert Tap to scroll in reader screen" }, + "@readerScrollAnimation": { + "description": "Switch title to Disable scroll animation in reader screen" + }, "@readerNavigationLayoutKindlish": { "description": "Radio button text for Reader Navigation Layout - Kindle-ish" }, @@ -723,6 +726,7 @@ "readerNavigationLayoutDisabled": "Disabled", "readerNavigationLayoutEdge": "Edge", "readerNavigationLayoutInvert": "Invert tapping", + "readerScrollAnimation": "Scroll animation", "readerNavigationLayoutKindlish": "Kindle-ish", "readerNavigationLayoutLShaped": "L Shaped", "readerNavigationLayoutRightAndLeft": "Right And Left",