Skip to content

Commit

Permalink
Fix two page pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Feb 3, 2024
1 parent 8a07b84 commit 33facc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:violet/pages/viewer/image/file_image.dart' as f;
import 'package:violet/pages/viewer/image/provider_image.dart' as p;
import 'package:violet/pages/viewer/others/photo_view_gallery.dart';
import 'package:violet/pages/viewer/viewer_controller.dart';
import 'package:violet/settings/settings.dart';
import 'package:violet/settings/settings_wrapper.dart';

class HorizontalViewerPage extends StatefulWidget {
Expand Down Expand Up @@ -43,7 +42,8 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
}

bool onTwoPageMode() {
return MediaQuery.of(context).orientation == Orientation.landscape;
return c.onTwoPage =
MediaQuery.of(context).orientation == Orientation.landscape;
}

@override
Expand Down Expand Up @@ -161,7 +161,7 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
);
})),
),
if (landscapeMaxPage() > index * 2 + 1)
if (c.maxPage > index * 2 + 1)
Image(
image: FileImage(File(c.provider.uris[index * 2 + 1]))
..resolve(ImageConfiguration.empty)
Expand Down Expand Up @@ -205,7 +205,7 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
timeRetry: const Duration(milliseconds: 300),
),
),
if (landscapeMaxPage() > index * 2 + 1)
if (c.maxPage > index * 2 + 1)
Image(
image: ExtendedNetworkImageProvider(
c.urlCache[index * 2 + 1]!.value,
Expand Down
9 changes: 5 additions & 4 deletions lib/pages/viewer/viewer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ViewerController extends GetxController {
final ViewerPageProvider provider;
late final int articleId;
late final int maxPage;
bool onTwoPage = false;

/// viewer callbacks
late AsyncCallback close;
Expand Down Expand Up @@ -138,7 +139,7 @@ class ViewerController extends GetxController {
alignment: 0.12,
);
} else {
horizontalPageController.jumpToPage(page);
horizontalPageController.jumpToPage(onTwoPage ? page ~/ 2 : page);
}
}

Expand Down Expand Up @@ -171,15 +172,15 @@ class ViewerController extends GetxController {
);
} else {
horizontalPageController.animateToPage(
page,
onTwoPage ? page ~/ 2 : page,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
}
}

prev() => move(page.value - 1);
next() => move(page.value + 1);
prev() => move(page.value - (onTwoPage ? 2 : 1));
next() => move(page.value + (onTwoPage ? 2 : 1));

load(int index) async {
if (provider.useProvider) {
Expand Down

0 comments on commit 33facc8

Please sign in to comment.