Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
feat: zoom manga on double tap in manga page reader
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKun committed Oct 25, 2021
1 parent 6541e60 commit dd835f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/pages/manga_page/page_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _PageReaderState extends State<PageReader>
late TransformationController interactiveController;
bool interactionOnProgress = false;
LastTapDetail? lastTapDetail;
TapDownDetails? doubleTapDetails;
int lastKbEvent = DateTime.now().millisecondsSinceEpoch;

late PageController pageController;
Expand Down Expand Up @@ -175,6 +176,26 @@ class _PageReaderState extends State<PageReader>
lastKbEvent = currentKbEvent;
}

// ignore: use_setters_to_change_properties
void handleDoubleTapDown(final TapDownDetails details) {
doubleTapDetails = details;
}

void handleDoubleTap() {
if (interactiveController.value != Matrix4.identity()) {
interactiveController.value = Matrix4.identity();
} else {
final Offset position = doubleTapDetails!.localPosition;

interactiveController.value = Matrix4.identity()
..translate(-position.dx, -position.dy)
..scale(2.0);
}
setState(() {
interactionOnProgress = !interactionOnProgress;
});
}

Future<void> goToPage(final int page) async {
if (pageController.hasClients) {
await pageController.animateToPage(
Expand Down Expand Up @@ -381,6 +402,8 @@ class _PageReaderState extends State<PageReader>
focusNode: focusNode,
onKey: handleKeyEvent,
child: GestureDetector(
onDoubleTapDown: handleDoubleTapDown,
onDoubleTap: handleDoubleTap,
onTapUp: (final TapUpDetails details) {
focusNode.requestFocus();
final LastTapDetail currentTap = LastTapDetail(
Expand Down

0 comments on commit dd835f1

Please sign in to comment.