Skip to content

Commit

Permalink
Add swiping to change player view on Android (#397)
Browse files Browse the repository at this point in the history
* Feat: add swipe on Android to change player size

* Refactor: return GestureDetector only on mobile

* Refactor: move VeryNarrowBottomPlayer to variable

This avoids code duplication in the return statement below.
  • Loading branch information
Timo-Schroeder authored Dec 28, 2023
1 parent aad58ee commit 4f3781d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
14 changes: 13 additions & 1 deletion lib/src/player/bottom_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:popover/popover.dart';
import '../../build_context_x.dart';
import '../../common.dart';
import '../../data.dart';
import '../../globals.dart';
import '../../player.dart';
import 'bottom_player_image.dart';
import 'bottom_player_title_artist.dart';
Expand Down Expand Up @@ -88,14 +89,25 @@ class BottomPlayer extends StatelessWidget {
);

if (veryNarrow) {
return VeryNarrowBottomPlayer(
final veryNarrowBottomPlayer = VeryNarrowBottomPlayer(
setFullScreen: setFullScreen,
bottomPlayerImage: bottomPlayerImage,
titleAndArtist: titleAndArtist,
active: active,
isOnline: isOnline,
track: track,
);
return isMobile
? GestureDetector(
onVerticalDragEnd: (details) {
if (details.primaryVelocity != null &&
details.primaryVelocity! < 150) {
setFullScreen(true);
}
},
child: veryNarrowBottomPlayer,
)
: veryNarrowBottomPlayer;
}

return SizedBox(
Expand Down
30 changes: 23 additions & 7 deletions lib/src/player/full_height_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,29 @@ class FullHeightPlayer extends StatelessWidget {
backgroundColor:
isVideo == true ? Colors.black : Colors.transparent,
),
Expanded(
child: Padding(
padding:
isMobile ? const EdgeInsets.only(top: 40) : EdgeInsets.zero,
child: stack,
),
),
isMobile
? GestureDetector(
onVerticalDragEnd: (details) {
if (isMobile) {
if (details.primaryVelocity != null &&
details.primaryVelocity! > 150) {
setFullScreen(false);
}
}
},
child: Expanded(
child: Padding(
padding: const EdgeInsets.only(top: 40),
child: stack,
),
),
)
: Expanded(
child: Padding(
padding: EdgeInsets.zero,
child: stack,
),
),
],
);
}
Expand Down

0 comments on commit 4f3781d

Please sign in to comment.