Skip to content

Commit

Permalink
fix: pull to refresh in tracks page
Browse files Browse the repository at this point in the history
when no many tracks (no scroll notification)
  • Loading branch information
MSOB7YY committed Feb 16, 2024
1 parent 88ba1f9 commit 7a8135a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 87 deletions.
10 changes: 0 additions & 10 deletions lib/base/pull_to_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ mixin PullToRefreshMixin<T extends StatefulWidget> on State<T> implements Ticker

num get pullNormalizer => 20;

bool onScrollNotification(ScrollMetricsNotification notification) {
final pixels = notification.metrics.pixels;
if (pixels < -_minTrigger) {
animation.animateTo(((pixels + _minTrigger).abs() / pullNormalizer).clamp(0, 1));
} else if (animation.value > 0) {
animation.animateTo(0);
}
return true;
}

double _distanceDragged = 0;
bool onVerticalDragUpdate(double dy) {
_distanceDragged -= dy;
Expand Down
160 changes: 83 additions & 77 deletions lib/ui/pages/tracks_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,94 +49,100 @@ class _TracksPageState extends State<TracksPage> with TickerProviderStateMixin,

@override
Widget build(BuildContext context) {
final scrollController = LibraryTab.tracks.scrollController;
return BackgroundWrapper(
child: Listener(
onPointerMove: (event) {
final c = scrollController;
if (!c.hasClients) return;
final p = c.position.pixels;
if (p <= 0 && event.delta.dx < 0.1) onVerticalDragUpdate(event.delta.dy);
},
onPointerUp: (event) {
if (animation.value == 1) {
showRefreshPromptDialog(false);
}
onVerticalDragFinish();
},
child: NotificationListener<ScrollMetricsNotification>(
onNotification: onScrollNotification,
child: Obx(
() {
settings.trackListTileHeight.value;
return Column(
children: [
ExpandableBox(
enableHero: false,
isBarVisible: LibraryTab.tracks.isBarVisible,
showSearchBox: LibraryTab.tracks.isSearchBoxVisible,
displayloadingIndicator: Indexer.inst.isIndexing.value,
leftWidgets: [
NamidaIconButton(
icon: Broken.shuffle,
onPressed: () => Player.inst.playOrPause(0, SearchSortController.inst.trackSearchList, QueueSource.allTracks, shuffle: true),
iconSize: 18.0,
horizontalPadding: 0,
),
const SizedBox(width: 12.0),
NamidaIconButton(
icon: Broken.play,
onPressed: () => Player.inst.playOrPause(0, SearchSortController.inst.trackSearchList, QueueSource.allTracks),
iconSize: 18.0,
horizontalPadding: 0,
),
const SizedBox(width: 12.0),
],
leftText: SearchSortController.inst.trackSearchList.displayTrackKeyword,
onFilterIconTap: () => ScrollSearchController.inst.switchSearchBoxVisibilty(LibraryTab.tracks),
onCloseButtonPressed: () {
ScrollSearchController.inst.clearSearchTextField(LibraryTab.tracks);
},
sortByMenuWidget: SortByMenu(
title: settings.tracksSort.value.toText(),
popupMenuChild: const SortByMenuTracks(),
isCurrentlyReversed: settings.tracksSortReversed.value,
onReverseIconTap: () {
SearchSortController.inst.sortMedia(MediaType.track, reverse: !settings.tracksSortReversed.value);
},
onPointerCancel: (event) => onVerticalDragFinish(),
child: Obx(
() {
settings.trackListTileHeight.value;
return Column(
children: [
ExpandableBox(
enableHero: false,
isBarVisible: LibraryTab.tracks.isBarVisible,
showSearchBox: LibraryTab.tracks.isSearchBoxVisible,
displayloadingIndicator: Indexer.inst.isIndexing.value,
leftWidgets: [
NamidaIconButton(
icon: Broken.shuffle,
onPressed: () => Player.inst.playOrPause(0, SearchSortController.inst.trackSearchList, QueueSource.allTracks, shuffle: true),
iconSize: 18.0,
horizontalPadding: 0,
),
textField: CustomTextFiled(
textFieldController: LibraryTab.tracks.textSearchController,
textFieldHintText: lang.FILTER_TRACKS,
onTextFieldValueChanged: (value) => SearchSortController.inst.searchMedia(value, MediaType.track),
const SizedBox(width: 12.0),
NamidaIconButton(
icon: Broken.play,
onPressed: () => Player.inst.playOrPause(0, SearchSortController.inst.trackSearchList, QueueSource.allTracks),
iconSize: 18.0,
horizontalPadding: 0,
),
const SizedBox(width: 12.0),
],
leftText: SearchSortController.inst.trackSearchList.displayTrackKeyword,
onFilterIconTap: () => ScrollSearchController.inst.switchSearchBoxVisibilty(LibraryTab.tracks),
onCloseButtonPressed: () {
ScrollSearchController.inst.clearSearchTextField(LibraryTab.tracks);
},
sortByMenuWidget: SortByMenu(
title: settings.tracksSort.value.toText(),
popupMenuChild: const SortByMenuTracks(),
isCurrentlyReversed: settings.tracksSortReversed.value,
onReverseIconTap: () {
SearchSortController.inst.sortMedia(MediaType.track, reverse: !settings.tracksSortReversed.value);
},
),
Expanded(
child: NamidaListViewRaw(
itemExtents: List.filled(SearchSortController.inst.trackSearchList.length, Dimensions.inst.trackTileItemExtent),
itemCount: SearchSortController.inst.trackSearchList.length,
scrollController: LibraryTab.tracks.scrollController,
scrollStep: Dimensions.inst.trackTileItemExtent,
itemBuilder: (context, i) {
final track = SearchSortController.inst.trackSearchList[i];
return AnimatingTile(
key: Key("$i${track.path}"),
position: i,
shouldAnimate: _shouldAnimate,
child: TrackTile(
index: i,
trackOrTwd: track,
draggableThumbnail: false,
queueSource: QueueSource.allTracks,
),
);
},
listBuilder: (list) {
return Stack(
children: [
list,
pullToRefreshWidget,
],
);
},
),
textField: CustomTextFiled(
textFieldController: LibraryTab.tracks.textSearchController,
textFieldHintText: lang.FILTER_TRACKS,
onTextFieldValueChanged: (value) => SearchSortController.inst.searchMedia(value, MediaType.track),
),
),
Expanded(
child: NamidaListViewRaw(
itemExtents: List.filled(SearchSortController.inst.trackSearchList.length, Dimensions.inst.trackTileItemExtent),
itemCount: SearchSortController.inst.trackSearchList.length,
scrollController: LibraryTab.tracks.scrollController,
scrollStep: Dimensions.inst.trackTileItemExtent,
itemBuilder: (context, i) {
final track = SearchSortController.inst.trackSearchList[i];
return AnimatingTile(
key: Key("$i${track.path}"),
position: i,
shouldAnimate: _shouldAnimate,
child: TrackTile(
index: i,
trackOrTwd: track,
draggableThumbnail: false,
queueSource: QueueSource.allTracks,
),
);
},
listBuilder: (list) {
return Stack(
children: [
list,
pullToRefreshWidget,
],
);
},
),
],
);
},
),
),
],
);
},
),
),
);
Expand Down

0 comments on commit 7a8135a

Please sign in to comment.