Skip to content

Commit

Permalink
Dynamic full screen behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
CTalvio committed Dec 19, 2024
1 parent db67fe0 commit 2aadeaa
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions lib/shared/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:flutter/material.dart';

import 'package:extended_image/extended_image.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gal/gal.dart';
import 'package:share_plus/share_plus.dart';
Expand Down Expand Up @@ -86,6 +85,24 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
});
}

void enterFullScreen() {
setState(() {
fullscreen = true;
});
Timer(const Duration(milliseconds: 400), () {
if (fullscreen) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}
});
}

void exitFullScreen() {
setState(() {
fullscreen = false;
});
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: SystemUiOverlay.values);
}

Future<bool> _requestPermission() async {
bool androidVersionBelow33 = false;

Expand Down Expand Up @@ -178,18 +195,18 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
child: GestureDetector(
onLongPress: () {
HapticFeedback.lightImpact();
setState(() {
fullscreen = !fullscreen;
});
if (fullscreen) {
exitFullScreen();
} else {
enterFullScreen();
}
},
onTap: () {
if (!fullscreen) {
slidePagekey.currentState!.popPage();
Navigator.pop(context);
} else {
setState(() {
fullscreen = false;
});
exitFullScreen();
}
},
// Start doubletap zoom if conditions are met
Expand Down Expand Up @@ -229,6 +246,13 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
_maybeSlide(context);
}
},
onPointerMove: (details) {
if (gestureKey.currentState!.gestureDetails!.totalScale! > 1.2) {
enterFullScreen();
} else {
exitFullScreen();
}
},
child: ExtendedImageSlidePage(
key: slidePagekey,
slideAxis: SlideAxis.both,
Expand Down Expand Up @@ -300,10 +324,12 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin

if (begin == 1) {
end = 2;
enterFullScreen();
} else if (begin > 1.99 && begin < 2.01) {
end = 4;
} else {
end = 1;
exitFullScreen();
}
animationListener = () {
state.handleDoubleTap(scale: animation!.value, doubleTapPosition: pointerDownPosition);
Expand Down Expand Up @@ -359,10 +385,12 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin

if (begin == 1) {
end = 2;
enterFullScreen();
} else if (begin > 1.99 && begin < 2.01) {
end = 4;
} else {
end = 1;
exitFullScreen();
}
animationListener = () {
state.handleDoubleTap(scale: animation!.value, doubleTapPosition: pointerDownPosition);
Expand Down

0 comments on commit 2aadeaa

Please sign in to comment.