mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
chore(mobile): simplify pop logic (#26410)
We have all the information we need to decide on whether we should pop or not at the end of a drag. There's no need to track that separately, and update the value constantly.
This commit is contained in:
@@ -61,7 +61,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
DragStartDetails? _dragStart;
|
DragStartDetails? _dragStart;
|
||||||
_DragIntent _dragIntent = _DragIntent.none;
|
_DragIntent _dragIntent = _DragIntent.none;
|
||||||
Drag? _drag;
|
Drag? _drag;
|
||||||
bool _shouldPopOnDrag = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -120,7 +119,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
|
|
||||||
void _beginDrag(DragStartDetails details) {
|
void _beginDrag(DragStartDetails details) {
|
||||||
_dragStart = details;
|
_dragStart = details;
|
||||||
_shouldPopOnDrag = false;
|
|
||||||
_lastScrollOffset = _proxyScrollController.hasClients ? _proxyScrollController.offset : 0.0;
|
_lastScrollOffset = _proxyScrollController.hasClients ? _proxyScrollController.offset : 0.0;
|
||||||
|
|
||||||
if (_viewController != null) {
|
if (_viewController != null) {
|
||||||
@@ -163,6 +161,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
void _endDrag(DragEndDetails details) {
|
void _endDrag(DragEndDetails details) {
|
||||||
if (_dragStart == null) return;
|
if (_dragStart == null) return;
|
||||||
|
|
||||||
|
final start = _dragStart;
|
||||||
_dragStart = null;
|
_dragStart = null;
|
||||||
|
|
||||||
final intent = _dragIntent;
|
final intent = _dragIntent;
|
||||||
@@ -178,7 +177,8 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
_drag?.end(details);
|
_drag?.end(details);
|
||||||
_drag = null;
|
_drag = null;
|
||||||
case _DragIntent.dismiss:
|
case _DragIntent.dismiss:
|
||||||
if (_shouldPopOnDrag) {
|
const popThreshold = 75.0;
|
||||||
|
if (details.localPosition.dy - start!.localPosition.dy > popThreshold) {
|
||||||
context.maybePop();
|
context.maybePop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -211,12 +211,8 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
|
|
||||||
void _handleDragDown(BuildContext context, Offset delta) {
|
void _handleDragDown(BuildContext context, Offset delta) {
|
||||||
const dragRatio = 0.2;
|
const dragRatio = 0.2;
|
||||||
const popThreshold = 75.0;
|
|
||||||
|
|
||||||
_shouldPopOnDrag = delta.dy > popThreshold;
|
|
||||||
|
|
||||||
final distance = delta.dy.abs();
|
final distance = delta.dy.abs();
|
||||||
|
|
||||||
final maxScaleDistance = context.height * 0.5;
|
final maxScaleDistance = context.height * 0.5;
|
||||||
final scaleReduction = (distance / maxScaleDistance).clamp(0.0, dragRatio);
|
final scaleReduction = (distance / maxScaleDistance).clamp(0.0, dragRatio);
|
||||||
final initialScale = _viewController?.initialScale ?? _initialPhotoViewState.scale;
|
final initialScale = _viewController?.initialScale ?? _initialPhotoViewState.scale;
|
||||||
|
|||||||
Reference in New Issue
Block a user