Skip to content

Commit f8be14d

Browse files
committed
chore(mobile): simplify pop logic
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.
1 parent 82c6302 commit f8be14d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

mobile/lib/presentation/widgets/asset_viewer/asset_page.widget.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
5757
DragStartDetails? _dragStart;
5858
_DragIntent _dragIntent = _DragIntent.none;
5959
Drag? _drag;
60-
bool _shouldPopOnDrag = false;
6160

6261
@override
6362
void initState() {
@@ -115,7 +114,6 @@ class _AssetPageState extends ConsumerState<AssetPage> {
115114

116115
void _beginDrag(DragStartDetails details) {
117116
_dragStart = details;
118-
_shouldPopOnDrag = false;
119117
_lastScrollOffset = _proxyScrollController.hasClients ? _proxyScrollController.offset : 0.0;
120118

121119
if (_viewController != null) {
@@ -158,6 +156,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
158156
void _endDrag(DragEndDetails details) {
159157
if (_dragStart == null) return;
160158

159+
final dragStart = _dragStart;
161160
_dragStart = null;
162161

163162
final intent = _dragIntent;
@@ -173,7 +172,8 @@ class _AssetPageState extends ConsumerState<AssetPage> {
173172
_drag?.end(details);
174173
_drag = null;
175174
case _DragIntent.dismiss:
176-
if (_shouldPopOnDrag) {
175+
const popThreshold = 75.0;
176+
if (details.localPosition.dy - dragStart!.localPosition.dy > popThreshold) {
177177
context.maybePop();
178178
return;
179179
}
@@ -206,12 +206,8 @@ class _AssetPageState extends ConsumerState<AssetPage> {
206206

207207
void _handleDragDown(BuildContext context, Offset delta) {
208208
const dragRatio = 0.2;
209-
const popThreshold = 75.0;
210-
211-
_shouldPopOnDrag = delta.dy > popThreshold;
212209

213210
final distance = delta.dy.abs();
214-
215211
final maxScaleDistance = context.height * 0.5;
216212
final scaleReduction = (distance / maxScaleDistance).clamp(0.0, dragRatio);
217213
final initialScale = _viewController?.initialScale ?? _initialPhotoViewState.scale;

0 commit comments

Comments
 (0)