Skip to content

Commit

Permalink
read page
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtian616 committed Nov 5, 2024
1 parent 082780f commit 2ab22f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
26 changes: 14 additions & 12 deletions lib/src/pages/read/layout/base/base_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ abstract class BaseLayout extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!readPageState.readyToShow) {
return Center(child: Container(color: UIConfig.readPageBackGroundColor));
}
return FutureBuilder(future: logic.readPageLogic.delayInitCompleter.future, builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return GetBuilder<BaseLayoutLogic>(
id: BaseLayoutLogic.pageId,
global: false,
init: logic,
builder: (_) => ScrollConfiguration(
behavior: readSetting.showScrollBar.isTrue ? UIConfig.scrollBehaviourWithScrollBarWithMouse : UIConfig.scrollBehaviourWithoutScrollBarWithMouse,
child: buildBody(context),
),
);
}

return GetBuilder<BaseLayoutLogic>(
id: BaseLayoutLogic.pageId,
global: false,
init: logic,
builder: (_) => ScrollConfiguration(
behavior: readSetting.showScrollBar.isTrue ? UIConfig.scrollBehaviourWithScrollBarWithMouse : UIConfig.scrollBehaviourWithoutScrollBarWithMouse,
child: buildBody(context),
),
);
return Center(child: Container(color: UIConfig.readPageBackGroundColor));
});
}

Widget buildBody(BuildContext context);
Expand Down
21 changes: 15 additions & 6 deletions lib/src/pages/read/read_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,19 @@ class ReadPageLogic extends GetxController {

final int normalPriority = 10000;

bool inited = false;
Completer<void> delayInitCompleter = Completer<void>();

@override
void onReady() {
super.onReady();

Timer(const Duration(milliseconds: 120), () {
if (inited && !delayInitCompleter.isCompleted) {
delayInitCompleter.complete();
}
});

/// Turn page by volume keys. The reason for not use [KeyboardListener]: https://github.com/flutter/flutter/issues/71144
listen2VolumeKeys();

Expand Down Expand Up @@ -169,10 +178,10 @@ class ReadPageLogic extends GetxController {
(_) => updateSafely([layoutId]),
);

Timer(const Duration(milliseconds: 120), () {
state.readyToShow = true;
updateSafely([layoutId]);
});
inited = true;
if (!delayInitCompleter.isCompleted) {
delayInitCompleter.complete();
}
}

@override
Expand Down Expand Up @@ -441,7 +450,7 @@ class ReadPageLogic extends GetxController {
}

void tapLeftRegion() {
if (!state.readyToShow) {
if (!inited) {
return;
}

Expand All @@ -461,7 +470,7 @@ class ReadPageLogic extends GetxController {
}

void tapRightRegion() {
if (!state.readyToShow) {
if (!inited) {
return;
}
if (readSetting.disablePageTurningOnTap.isTrue) {
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
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:battery_plus/battery_plus.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand All @@ -21,8 +23,6 @@ class ReadPageState with ScrollStatusListerState {
late List<GalleryThumbnail?> thumbnails;
late List<GalleryImage?> images;

bool readyToShow = false;

late List<LoadingState> parseImageHrefsStates;
late List<LoadingState> parseImageUrlStates;
late List<Size?> imageContainerSizes;
Expand Down

0 comments on commit 2ab22f5

Please sign in to comment.