Skip to content

Commit

Permalink
fix(mobile): scroll thumb is hidden behind the tab navigation bar (#1…
Browse files Browse the repository at this point in the history
…2512)

* fix(mobile): scroll thumb is hidden behind the tab navigation bar

* better variable names

* fix rounding error
  • Loading branch information
alextran1502 committed Sep 9, 2024
1 parent b3ef5fe commit 9323b69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
39 changes: 23 additions & 16 deletions mobile/lib/widgets/asset_grid/draggable_scrollbar_custom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class DraggableScrollbar extends StatefulWidget {

final Function(bool scrolling) scrollStateListener;

final double viewPortHeight;

DraggableScrollbar.semicircle({
super.key,
Key? scrollThumbKey,
Expand All @@ -69,7 +67,6 @@ class DraggableScrollbar extends StatefulWidget {
required this.controller,
required this.itemPositionsListener,
required this.scrollStateListener,
required this.viewPortHeight,
this.heightScrollThumb = 48.0,
this.backgroundColor = Colors.white,
this.padding,
Expand Down Expand Up @@ -254,7 +251,7 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
}

double get barMaxScrollExtent =>
widget.viewPortHeight -
(context.size?.height ?? 0) -
widget.heightScrollThumb -
(widget.heightOffset ?? 0);

Expand Down Expand Up @@ -340,8 +337,8 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
_thumbAnimationController.forward();
}

if (itemPos < maxItemCount) {
_currentItem = itemPos;
if (itemPosition < maxItemCount) {
_currentItem = itemPosition;
}

_fadeoutTimer?.cancel();
Expand All @@ -365,25 +362,35 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
widget.scrollStateListener(true);
}

int get itemPos {
int get itemPosition {
int numberOfItems = widget.child.itemCount;
return ((_barOffset / barMaxScrollExtent) * numberOfItems).toInt();
}

void _jumpToBarPos() {
if (itemPos > maxItemCount - 1) {
void _jumpToBarPosition() {
if (itemPosition > maxItemCount - 1) {
return;
}

_currentItem = itemPos;
_currentItem = itemPosition;

/// If the bar is at the bottom but the item position is still smaller than the max item count (due to rounding error)
/// jump to the end of the list
if (barMaxScrollExtent - _barOffset < 10 && itemPosition < maxItemCount) {
widget.controller.jumpTo(
index: maxItemCount,
);

return;
}

widget.controller.jumpTo(
index: itemPos,
index: itemPosition,
);
}

Timer? dragHaltTimer;
int lastTimerPos = 0;
int lastTimerPosition = 0;

void _onVerticalDragUpdate(DragUpdateDetails details) {
setState(() {
Expand All @@ -400,8 +407,8 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
_barOffset = barMaxScrollExtent;
}

if (itemPos != lastTimerPos) {
lastTimerPos = itemPos;
if (itemPosition != lastTimerPosition) {
lastTimerPosition = itemPosition;
dragHaltTimer?.cancel();
widget.scrollStateListener(true);

Expand All @@ -413,7 +420,7 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
);
}

_jumpToBarPos();
_jumpToBarPosition();
}
});
}
Expand All @@ -426,7 +433,7 @@ class DraggableScrollbarState extends State<DraggableScrollbar>
});

setState(() {
_jumpToBarPos();
_jumpToBarPosition();
_isDragInProcess = false;
});

Expand Down
1 change: 0 additions & 1 deletion mobile/lib/widgets/asset_grid/immich_asset_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ class ImmichAssetGridViewState extends ConsumerState<ImmichAssetGridView> {

final child = (useDragScrolling && ModalRoute.of(context) != null)
? DraggableScrollbar.semicircle(
viewPortHeight: context.height,
scrollStateListener: dragScrolling,
itemPositionsListener: _itemPositionsListener,
controller: _itemScrollController,
Expand Down

0 comments on commit 9323b69

Please sign in to comment.