Skip to content

Commit

Permalink
scrollable_positioned_list
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtian616 committed Nov 3, 2024
1 parent 117095b commit 7944298
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 699 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/pages/read/layout/horizontal_list/horizontal_list_layout_state.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

import '../../../../model/read_page_info.dart';
import '../../../../setting/read_setting.dart';
import '../../../../utils/screen_size_util.dart';
import '../../../../widget/eh_wheel_speed_controller_for_read_page.dart';
import '../../widget/eh_scrollable_positioned_list.dart';
import '../base/base_layout.dart';
import 'horizontal_list_layout_logic.dart';

Expand All @@ -32,8 +32,8 @@ class HorizontalListLayout extends BaseLayout {
scaleStateCycle: readSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: readSetting.enableTapDragToScaleUp.isTrue,
child: EHWheelSpeedControllerForReadPage(
scrollController: state.itemScrollController,
child: EHScrollablePositionedList.separated(
scrollOffsetController: state.scrollOffsetController,
child: ScrollablePositionedList.separated(
scrollDirection: Axis.horizontal,
reverse: readSetting.isInRight2LeftDirection,
physics: const ClampingScrollPhysics(),
Expand All @@ -44,6 +44,7 @@ class HorizontalListLayout extends BaseLayout {
itemCount: readPageState.readPageInfo.pageCount,
itemScrollController: state.itemScrollController,
itemPositionsListener: state.itemPositionsListener,
scrollOffsetController: state.scrollOffsetController,
itemBuilder: (context, index) =>
readPageState.readPageInfo.mode == ReadMode.online ? buildItemInOnlineMode(context, index) : buildItemInLocalMode(context, index),
separatorBuilder: (_, __) => Obx(() => SizedBox(width: readSetting.imageSpace.value.toDouble())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ class HorizontalListLayoutLogic extends BaseLayoutLogic {

void _toPrevScreen() {
if (readSetting.enablePageTurnAnime.isFalse) {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: -fullScreenWidth,
duration: const Duration(milliseconds: 1),
);
} else {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: -fullScreenWidth,
duration: const Duration(milliseconds: 200),
);
Expand All @@ -130,12 +130,12 @@ class HorizontalListLayoutLogic extends BaseLayoutLogic {

void _toNextScreen() {
if (readSetting.enablePageTurnAnime.isFalse) {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: fullScreenWidth,
duration: const Duration(milliseconds: 1),
);
} else {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: fullScreenWidth,
duration: const Duration(milliseconds: 200),
);
Expand All @@ -157,7 +157,7 @@ class HorizontalListLayoutLogic extends BaseLayoutLogic {

readPageLogic.toggleMenu();

state.itemScrollController
state.scrollOffsetController
.scrollToEnd(
duration: Duration(milliseconds: (totalTime * 1000).toInt()),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:photo_view/photo_view.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

import '../../widget/eh_scrollable_positioned_list.dart';

class HorizontalListLayoutState {
final PhotoViewController photoViewController = PhotoViewController();

final EHItemScrollController itemScrollController = EHItemScrollController();
final ItemPositionsListener itemPositionsListener = ItemPositionsListener.create();
final ItemScrollController itemScrollController = ItemScrollController();
final ScrollOffsetController scrollOffsetController = ScrollOffsetController();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:get/get.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/pages/read/layout/vertical_list/vertical_list_layout_state.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

import '../../../../setting/read_setting.dart';
import '../../../../utils/screen_size_util.dart';
import '../../../../widget/eh_wheel_speed_controller_for_read_page.dart';
import '../../widget/eh_scrollable_positioned_list.dart';
import '../base/base_layout.dart';
import 'vertical_list_layout_logic.dart';

Expand All @@ -33,8 +33,8 @@ class VerticalListLayout extends BaseLayout {
scaleStateCycle: readSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: readSetting.enableTapDragToScaleUp.isTrue,
child: EHWheelSpeedControllerForReadPage(
scrollController: state.itemScrollController,
child: EHScrollablePositionedList.separated(
scrollOffsetController: state.scrollOffsetController,
child: ScrollablePositionedList.separated(
physics: const ClampingScrollPhysics(),
minCacheExtent: readPageState.readPageInfo.mode == ReadMode.online
? readSetting.preloadDistance * screenHeight * 1
Expand All @@ -43,6 +43,7 @@ class VerticalListLayout extends BaseLayout {
itemCount: readPageState.readPageInfo.pageCount,
itemScrollController: state.itemScrollController,
itemPositionsListener: state.itemPositionsListener,
scrollOffsetController: state.scrollOffsetController,
itemBuilder: _imageBuilder,
separatorBuilder: (_, __) => Obx(() => SizedBox(height: readSetting.imageSpace.value.toDouble())),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ class VerticalListLayoutLogic extends BaseLayoutLogic {

void _toPrevScreen() {
if (readSetting.enablePageTurnAnime.isFalse) {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: -_getVisibleHeight(),
duration: const Duration(milliseconds: 1),
);
} else {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: -_getVisibleHeight(),
duration: const Duration(milliseconds: 200),
);
Expand All @@ -144,12 +144,12 @@ class VerticalListLayoutLogic extends BaseLayoutLogic {

void _toNextScreen() {
if (readSetting.enablePageTurnAnime.isFalse) {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: _getVisibleHeight(),
duration: const Duration(milliseconds: 1),
);
} else {
state.itemScrollController.scrollOffset(
state.scrollOffsetController.animateScroll(
offset: _getVisibleHeight(),
duration: const Duration(milliseconds: 200),
);
Expand All @@ -171,7 +171,7 @@ class VerticalListLayoutLogic extends BaseLayoutLogic {

readPageLogic.toggleMenu();

state.itemScrollController
state.scrollOffsetController
.scrollToEnd(
duration: Duration(milliseconds: (totalTime * 1000).toInt()),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:jhentai/src/pages/read/widget/eh_scrollable_positioned_list.dart';
import 'package:photo_view/photo_view.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

class VerticalListLayoutState {
final PhotoViewController photoViewController = PhotoViewController();

final EHItemScrollController itemScrollController = EHItemScrollController();
final ItemPositionsListener itemPositionsListener = ItemPositionsListener.create();
final ItemScrollController itemScrollController = ItemScrollController();
final ScrollOffsetController scrollOffsetController = ScrollOffsetController();
}
7 changes: 4 additions & 3 deletions lib/src/pages/read/read_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import 'package:jhentai/src/pages/read/layout/horizontal_list/horizontal_list_la
import 'package:jhentai/src/pages/read/layout/horizontal_page/horizontal_page_layout.dart';
import 'package:jhentai/src/pages/read/read_page_logic.dart';
import 'package:jhentai/src/pages/read/read_page_state.dart';
import 'package:jhentai/src/pages/read/widget/eh_scrollable_positioned_list.dart';
import 'package:jhentai/src/service/super_resolution_service.dart';
import 'package:jhentai/src/widget/eh_mouse_button_listener.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:window_manager/window_manager.dart';

import '../../config/ui_config.dart';
Expand Down Expand Up @@ -407,8 +407,8 @@ class _ReadPageState extends State<ReadPage> with ScrollStatusListener, WindowLi
height: UIConfig.readPageBottomThumbnailsRegionHeight,
child: Obx(
() => EHWheelSpeedControllerForReadPage(
scrollController: state.thumbnailsScrollController,
child: EHScrollablePositionedList.separated(
scrollOffsetController: state.thumbnailsScrollOffsetController,
child: ScrollablePositionedList.separated(
scrollDirection: Axis.horizontal,
reverse: readSetting.isInRight2LeftDirection,
physics: const ClampingScrollPhysics(),
Expand All @@ -417,6 +417,7 @@ class _ReadPageState extends State<ReadPage> with ScrollStatusListener, WindowLi
itemCount: state.readPageInfo.pageCount,
itemScrollController: state.thumbnailsScrollController,
itemPositionsListener: state.thumbnailPositionsListener,
scrollOffsetController: state.thumbnailsScrollOffsetController,
itemBuilder: (_, index) => GetBuilder<ReadPageLogic>(
id: logic.thumbnailNoId,
builder: (_) => Column(
Expand Down
6 changes: 0 additions & 6 deletions lib/src/pages/read/read_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,6 @@ class ReadPageLogic extends GetxController {
});
}

void jumpThumbnailsToIndex(int index) {
state.thumbnailsScrollController.jumpTo(
index: max(0, index - 2),
);
}

void scrollThumbnailsToIndex(int index) {
if (!isClosed) {
state.thumbnailsScrollController.scrollTo(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/pages/read/read_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/mixin/scroll_status_listener_state.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/pages/read/widget/eh_scrollable_positioned_list.dart';
import 'package:jhentai/src/setting/site_setting.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

Expand Down Expand Up @@ -40,8 +39,9 @@ class ReadPageState with ScrollStatusListerState {

late Size displayRegionSize;

final EHItemScrollController thumbnailsScrollController = EHItemScrollController();
final ItemPositionsListener thumbnailPositionsListener = ItemPositionsListener.create();
final ItemScrollController thumbnailsScrollController = ItemScrollController();
final ScrollOffsetController thumbnailsScrollOffsetController = ScrollOffsetController();

ReadPageState() {
thumbnails = List.generate(readPageInfo.pageCount, (_) => null, growable: true);
Expand Down
Loading

0 comments on commit 7944298

Please sign in to comment.