Skip to content

Commit

Permalink
added disable reader scroll animation (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
DattatreyaReddy authored Mar 16, 2023
1 parent 3951ab5 commit 8d0d2c3
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/src/constants/db_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum DBKeys {
readerMagnifierSize(1.0),
readerNavigationLayout(ReaderNavigationLayout.disabled),
invertTap(false),
scrollAnimation(true),
showNSFW(true),
downloadedBadge(true),
unreadBadge(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -25,6 +26,7 @@ class ReaderSettingsScreen extends StatelessWidget {
ReaderModeTile(),
ReaderNavigationLayoutTile(),
ReaderInvertTapTile(),
ReaderScrollAnimationTile(),
ReaderPaddingSlider(),
ReaderMagnifierSizeSlider(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<bool> {
@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(),
);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -723,6 +726,7 @@
"readerNavigationLayoutDisabled": "Disabled",
"readerNavigationLayoutEdge": "Edge",
"readerNavigationLayoutInvert": "Invert tapping",
"readerScrollAnimation": "Scroll animation",
"readerNavigationLayoutKindlish": "Kindle-ish",
"readerNavigationLayoutLShaped": "L Shaped",
"readerNavigationLayoutRightAndLeft": "Right And Left",
Expand Down

0 comments on commit 8d0d2c3

Please sign in to comment.