mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 09:38:43 +03:00
chore(mobile): simplify drag logic (#26291)
We were manually tracking whether gestures should be blocked, which was a remnant of how the old code worked. This is no longer needed as we have better heuristics for knowing whether we should skip drag updates now. Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
@@ -45,7 +45,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
|
|
||||||
late PhotoViewControllerValue _initialPhotoViewState;
|
late PhotoViewControllerValue _initialPhotoViewState;
|
||||||
|
|
||||||
bool _blockGestures = false;
|
|
||||||
bool _showingDetails = false;
|
bool _showingDetails = false;
|
||||||
bool _isZoomed = false;
|
bool _isZoomed = false;
|
||||||
|
|
||||||
@@ -58,7 +57,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
DragStartDetails? _dragStart;
|
DragStartDetails? _dragStart;
|
||||||
_DragIntent _dragIntent = _DragIntent.none;
|
_DragIntent _dragIntent = _DragIntent.none;
|
||||||
Drag? _drag;
|
Drag? _drag;
|
||||||
bool _dragInProgress = false;
|
|
||||||
bool _shouldPopOnDrag = false;
|
bool _shouldPopOnDrag = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -137,9 +135,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _updateDrag(DragUpdateDetails details) {
|
void _updateDrag(DragUpdateDetails details) {
|
||||||
if (_blockGestures) return;
|
if (_dragStart == null) return;
|
||||||
|
|
||||||
_dragInProgress = true;
|
|
||||||
|
|
||||||
if (_dragIntent == _DragIntent.none) {
|
if (_dragIntent == _DragIntent.none) {
|
||||||
_dragIntent = switch ((details.globalPosition - _dragStart!.globalPosition).dy) {
|
_dragIntent = switch ((details.globalPosition - _dragStart!.globalPosition).dy) {
|
||||||
@@ -160,16 +156,12 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _endDrag(DragEndDetails details) {
|
void _endDrag(DragEndDetails details) {
|
||||||
_dragInProgress = false;
|
if (_dragStart == null) return;
|
||||||
|
|
||||||
if (_blockGestures) {
|
_dragStart = null;
|
||||||
_blockGestures = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final intent = _dragIntent;
|
final intent = _dragIntent;
|
||||||
_dragIntent = _DragIntent.none;
|
_dragIntent = _DragIntent.none;
|
||||||
_dragStart = null;
|
|
||||||
|
|
||||||
switch (intent) {
|
switch (intent) {
|
||||||
case _DragIntent.none:
|
case _DragIntent.none:
|
||||||
@@ -201,10 +193,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
PhotoViewScaleStateController scaleStateController,
|
PhotoViewScaleStateController scaleStateController,
|
||||||
) {
|
) {
|
||||||
_viewController = controller;
|
_viewController = controller;
|
||||||
if (!_showingDetails && _isZoomed) {
|
if (!_showingDetails && _isZoomed) return;
|
||||||
_blockGestures = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_beginDrag(details);
|
_beginDrag(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +224,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onTapUp(BuildContext context, TapUpDetails details, PhotoViewControllerValue controllerValue) {
|
void _onTapUp(BuildContext context, TapUpDetails details, PhotoViewControllerValue controllerValue) {
|
||||||
if (!_showingDetails && !_dragInProgress) _viewer.toggleControls();
|
if (!_showingDetails && _dragStart == null) _viewer.toggleControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onLongPress(BuildContext context, LongPressStartDetails details, PhotoViewControllerValue controllerValue) =>
|
void _onLongPress(BuildContext context, LongPressStartDetails details, PhotoViewControllerValue controllerValue) =>
|
||||||
@@ -249,7 +238,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
|||||||
_viewer.setZoomed(_isZoomed);
|
_viewer.setZoomed(_isZoomed);
|
||||||
|
|
||||||
if (scaleState != PhotoViewScaleState.initial) {
|
if (scaleState != PhotoViewScaleState.initial) {
|
||||||
if (!_dragInProgress) _viewer.setControls(false);
|
if (_dragStart == null) _viewer.setControls(false);
|
||||||
|
|
||||||
ref.read(videoPlayerControlsProvider.notifier).pause();
|
ref.read(videoPlayerControlsProvider.notifier).pause();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user