Skip to content

Commit

Permalink
Merge pull request #641 from ErBWs/mod-player-panel
Browse files Browse the repository at this point in the history
optimize panel hide logic
  • Loading branch information
Predidit authored Jan 21, 2025
2 parents 7924043 + efddaa9 commit 0edfa81
Show file tree
Hide file tree
Showing 9 changed files with 582 additions and 439 deletions.
13 changes: 11 additions & 2 deletions lib/bean/widget/collect_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import 'package:kazumi/pages/collect/collect_controller.dart';
import 'package:flutter_modular/flutter_modular.dart';

class CollectButton extends StatefulWidget {
const CollectButton(
{super.key, required this.bangumiItem, this.color = Colors.white});
const CollectButton({
super.key,
required this.bangumiItem,
this.color = Colors.white,
this.onOpen,
this.onClose,
});

final BangumiItem bangumiItem;
final Color color;
final void Function()? onOpen;
final void Function()? onClose;

@override
State<CollectButton> createState() => _CollectButtonState();
Expand Down Expand Up @@ -67,6 +74,8 @@ class _CollectButtonState extends State<CollectButton> {
collectType = collectController.getCollectType(widget.bangumiItem);
return MenuAnchor(
consumeOutsideTap: true,
onClose: widget.onClose,
onOpen: widget.onOpen,
builder:
(BuildContext context, MenuController controller, Widget? child) {
return IconButton(
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/player/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ abstract class _PlayerController with Store {
bool brightnessSeeking = false;
@observable
bool volumeSeeking = false;
@observable
bool canHidePlayerPanel = true;

// 视频地址
String videoUrl = '';
Expand Down
17 changes: 17 additions & 0 deletions lib/pages/player/player_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 23 additions & 6 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _PlayerItemState extends State<PlayerItem>
}
}

void handleHove() {
void _handleHove() {
if (!playerController.showVideoController) {
displayVideoController();
}
Expand Down Expand Up @@ -264,14 +264,19 @@ class _PlayerItemState extends State<PlayerItem>

void startHideTimer() {
hideTimer = Timer(const Duration(seconds: 4), () {
if (mounted) {
if (mounted && playerController.canHidePlayerPanel) {
playerController.showVideoController = false;
animationController?.reverse();
}
hideTimer = null;
});
}

// Used to pass hideTimer operation to panel layer
void cancelHideTimer() {
hideTimer?.cancel();
}

Timer getPlayerTimer() {
return Timer.periodic(const Duration(seconds: 1), (timer) {
playerController.playing = playerController.playerPlaying;
Expand Down Expand Up @@ -580,11 +585,20 @@ class _PlayerItemState extends State<PlayerItem>
!playerController.showVideoController)
? SystemMouseCursors.none
: SystemMouseCursors.basic,
onHover: (_) {
onHover: (PointerEvent pointerEvent) {
// workaround for android.
// I don't know why, but android tap event will trigger onHover event.
if (Utils.isDesktop()) {
handleHove();
if (pointerEvent.position.dy > 50 &&
pointerEvent.position.dy <
MediaQuery.of(context).size.height - 70) {
_handleHove();
} else {
if (!playerController.showVideoController) {
animationController?.forward();
playerController.showVideoController = true;
}
}
}
},
child: Listener(
Expand Down Expand Up @@ -803,8 +817,9 @@ class _PlayerItemState extends State<PlayerItem>
handleProgressBarDragEnd: handleProgressBarDragEnd,
animationController: animationController!,
keyboardFocus: widget.keyboardFocus,
handleHove: handleHove,
sendDanmaku: widget.sendDanmaku,
startHideTimer: startHideTimer,
cancelHideTimer: cancelHideTimer,
)
: SmallestPlayerItemPanel(
onBackPressed: widget.onBackPressed,
Expand All @@ -816,7 +831,9 @@ class _PlayerItemState extends State<PlayerItem>
handleProgressBarDragEnd: handleProgressBarDragEnd,
animationController: animationController!,
keyboardFocus: widget.keyboardFocus,
handleHove: handleHove,
handleHove: _handleHove,
startHideTimer: startHideTimer,
cancelHideTimer: cancelHideTimer,
),
// 播放器手势控制
Positioned.fill(
Expand Down
Loading

0 comments on commit 0edfa81

Please sign in to comment.