Skip to content

Commit

Permalink
Merge pull request #383 from project-violet/fix-two-page-viewer
Browse files Browse the repository at this point in the history
Two page viewer pagination
  • Loading branch information
violet-dev authored Feb 3, 2024
2 parents 56570be + 33facc8 commit 2418696
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 3 additions & 7 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,7 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
}

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

Expand Down Expand Up @@ -162,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 @@ -206,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 Expand Up @@ -293,9 +292,6 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
minScale: PhotoViewComputedScale.contained * 1.0,
maxScale: PhotoViewComputedScale.contained * 5.0,
gestureDetectorBehavior: HitTestBehavior.opaque,
filterQuality: c.provider.useFileSystem
? SettingsWrapper.imageQuality
: SettingsWrapper.getImageQuality(c.imgQuality.value),
child: gestureDetector,
);
} else {
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 2418696

Please sign in to comment.