Skip to content

Commit

Permalink
fix(track_collection_view): keyboard focus on scroll and no space for…
Browse files Browse the repository at this point in the history
… search results in playlist/album
  • Loading branch information
KRTirtho committed Jun 18, 2023
1 parent cca5625 commit 7a8bd92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
15 changes: 2 additions & 13 deletions lib/components/shared/heart_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'package:spotify/spotify.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/hooks/use_palette_color.dart';
import 'package:spotube/provider/authentication_provider.dart';
import 'package:spotube/services/mutations/mutations.dart';
import 'package:spotube/services/queries/queries.dart';

import 'package:spotube/utils/type_conversion_utils.dart';

class HeartButton extends HookConsumerWidget {
final bool isLiked;
final void Function()? onPressed;
Expand Down Expand Up @@ -163,15 +160,6 @@ class PlaylistHeartButton extends HookConsumerWidget {
],
);

final titleImage = useMemoized(
() => TypeConversionUtils.image_X_UrlString(
playlist.images,
placeholder: ImagePlaceholder.collection,
),
[playlist.images]);

final color = usePaletteGenerator(titleImage).dominantColor;

if (me.isLoading || !me.hasData) {
return const CircularProgressIndicator();
}
Expand All @@ -181,7 +169,7 @@ class PlaylistHeartButton extends HookConsumerWidget {
tooltip: isLikedQuery.data ?? false
? context.l10n.remove_from_favorites
: context.l10n.save_as_favorite,
color: color?.titleTextColor,
color: Colors.white,
onPressed: isLikedQuery.hasData
? () {
togglePlaylistLike.mutate(isLikedQuery.data!);
Expand Down Expand Up @@ -224,6 +212,7 @@ class AlbumHeartButton extends HookConsumerWidget {
tooltip: isLiked
? context.l10n.remove_from_favorites
: context.l10n.save_as_favorite,
color: Colors.white,
onPressed: albumIsSaved.hasData
? () {
toggleAlbumLike.mutate(isLiked);
Expand Down
36 changes: 21 additions & 15 deletions lib/components/shared/track_table/track_collection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class TrackCollectionView<T> extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final theme = Theme.of(context);
final mediaQuery = MediaQuery.of(context);
final auth = ref.watch(AuthenticationNotifier.provider);
final color = usePaletteGenerator(titleImage).dominantColor;

Expand Down Expand Up @@ -343,23 +342,30 @@ class TrackCollectionView<T> extends HookConsumerWidget {
}

return TracksTableView(
List.from(
(tracksSnapshot.data ?? []).map(
(track) {
if (track is Track) {
return track;
} else {
return TypeConversionUtils.simpleTrack_X_Track(
track,
album!,
);
}
},
),
),
(tracksSnapshot.data ?? []).map(
(track) {
if (track is Track) {
return track;
} else {
return TypeConversionUtils.simpleTrack_X_Track(
track,
album!,
);
}
},
).toList(),
onTrackPlayButtonPressed: onPlay,
playlistId: id,
userPlaylist: isOwned,
onFiltering: () {
// scroll the flexible space
// to allow more space for search results
controller.animateTo(
390,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
},
);
},
)
Expand Down
14 changes: 12 additions & 2 deletions lib/components/shared/track_table/tracks_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ class TracksTableView extends HookConsumerWidget {
final bool isSliver;

final Widget? heading;

final VoidCallback? onFiltering;

const TracksTableView(
this.tracks, {
Key? key,
this.onTrackPlayButtonPressed,
this.onFiltering,
this.userPlaylist = false,
this.playlistId,
this.heading,
Expand All @@ -46,6 +50,7 @@ class TracksTableView extends HookConsumerWidget {
@override
Widget build(context, ref) {
final theme = Theme.of(context);
final mediaQuery = MediaQuery.of(context);

ref.watch(ProxyPlaylistNotifier.provider);
final playback = ref.watch(ProxyPlaylistNotifier.notifier);
Expand Down Expand Up @@ -178,6 +183,7 @@ class TracksTableView extends HookConsumerWidget {
onPressed: () {
isFiltering.value = !isFiltering.value;
if (isFiltering.value) {
onFiltering?.call();
searchFocus.requestFocus();
} else {
searchController.clear();
Expand Down Expand Up @@ -314,7 +320,6 @@ class TracksTableView extends HookConsumerWidget {
}
},
child: TextField(
autofocus: true,
focusNode: searchFocus,
controller: searchController,
decoration: InputDecoration(
Expand Down Expand Up @@ -375,7 +380,12 @@ class TracksTableView extends HookConsumerWidget {
}
},
);
}).toList(),
}),
// extra space for mobile devices where keyboard takes half of the screen
if (isFiltering.value)
SizedBox(
height: mediaQuery.size.height * .75, //75% of the screen
),
];

if (isSliver) {
Expand Down

0 comments on commit 7a8bd92

Please sign in to comment.