fix: hide danmaku (#1654)

This commit is contained in:
My-Responsitories
2025-10-20 12:17:59 +08:00
committed by GitHub
parent 340a933e70
commit 7524b3d168
2 changed files with 47 additions and 44 deletions

View File

@@ -6,13 +6,13 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
super.debugOwner, super.debugOwner,
super.supportedDevices, super.supportedDevices,
super.allowedButtonsFilter, super.allowedButtonsFilter,
required this.onTapDown, this.onTapDown,
required this.onTapUp, required this.onTapUp,
required this.onTapCancel, required this.onTapCancel,
this.onTap, this.onTap,
}); });
final GestureTapDownCallback onTapDown; GestureTapDownCallback? onTapDown;
final GestureTapUpCallback onTapUp; final GestureTapUpCallback onTapUp;
@@ -35,10 +35,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
@override @override
void addAllowedPointer(PointerDownEvent event) { void addAllowedPointer(PointerDownEvent event) {
super.addAllowedPointer(event); super.addAllowedPointer(event);
_reset(event.pointer);
_activePointer = event.pointer;
_sentTapDown = false;
_wonArena = false;
} }
@override @override
@@ -63,13 +60,15 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
void _handleTapDown(PointerDownEvent event) { void _handleTapDown(PointerDownEvent event) {
if (_sentTapDown) return; if (_sentTapDown) return;
_sentTapDown = true; if (onTapDown != null) {
final details = TapDownDetails( _sentTapDown = true;
globalPosition: event.position, final details = TapDownDetails(
localPosition: event.localPosition, globalPosition: event.position,
kind: event.kind, localPosition: event.localPosition,
); kind: event.kind,
invokeCallback<void>('onTapDown', () => onTapDown(details)); );
invokeCallback<void>('onTapDown', () => onTapDown!(details));
}
} }
void _handlePointerMove(PointerMoveEvent event) { void _handlePointerMove(PointerMoveEvent event) {
@@ -80,23 +79,21 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
} }
void _handlePointerUp(PointerUpEvent event) { void _handlePointerUp(PointerUpEvent event) {
if (_wonArena && _sentTapDown) { if (_wonArena) {
_handleTapUp(event); _handleTapUp(event);
} }
} }
void _handleTapUp(PointerUpEvent event) { void _handleTapUp(PointerUpEvent event) {
if (_sentTapDown) { final details = TapUpDetails(
final details = TapUpDetails( globalPosition: event.position,
globalPosition: event.position, localPosition: event.localPosition,
localPosition: event.localPosition, kind: event.kind,
kind: event.kind, );
); invokeCallback<void>('onTapUp', () => onTapUp(details));
invokeCallback<void>('onTapUp', () => onTapUp(details));
if (onTap != null) { if (onTap != null) {
invokeCallback<void>('onTap', onTap!); invokeCallback<void>('onTap', onTap!);
}
} }
_reset(); _reset();
@@ -109,8 +106,8 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
_reset(); _reset();
} }
void _reset() { void _reset([int pointer = 0]) {
_activePointer = 0; _activePointer = pointer;
_up = null; _up = null;
_sentTapDown = false; _sentTapDown = false;
_wonArena = false; _wonArena = false;
@@ -123,7 +120,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
if (pointer == _activePointer) { if (pointer == _activePointer) {
_wonArena = true; _wonArena = true;
if (_up != null && _sentTapDown) { if (_up != null) {
_handleTapUp(_up!); _handleTapUp(_up!);
} }
} }
@@ -146,10 +143,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
@override @override
void dispose() { void dispose() {
if (_sentTapDown) { _cancelGesture('disposed');
_cancelGesture('disposed');
}
_reset();
super.dispose(); super.dispose();
} }

View File

@@ -221,14 +221,25 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}); });
} }
_tapGestureRecognizer = plPlayerController.enableTapDm if (plPlayerController.enableTapDm) {
? ImmediateTapGestureRecognizer( _tapGestureRecognizer = ImmediateTapGestureRecognizer(
onTapDown: _onTapDown, onTapDown: plPlayerController.enableShowDanmaku.value
onTapUp: _onTapUp, ? _onTapDown
onTapCancel: _removeDmAction, : null,
allowedButtonsFilter: (buttons) => buttons == kPrimaryButton, onTapUp: _onTapUp,
) onTapCancel: _removeDmAction,
: (TapGestureRecognizer()..onTapUp = _onTapUp); allowedButtonsFilter: (buttons) => buttons == kPrimaryButton,
);
_danmakuListener = plPlayerController.enableShowDanmaku.listen((value) {
if (!value) _removeDmAction();
(_tapGestureRecognizer as ImmediateTapGestureRecognizer).onTapDown =
value ? _onTapDown : null;
});
} else {
_tapGestureRecognizer = TapGestureRecognizer()..onTapUp = _onTapUp;
}
_doubleTapGestureRecognizer = DoubleTapGestureRecognizer() _doubleTapGestureRecognizer = DoubleTapGestureRecognizer()
..onDoubleTapDown = _onDoubleTapDown; ..onDoubleTapDown = _onDoubleTapDown;
} }
@@ -277,6 +288,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
WakelockPlus.enabled.then((i) { WakelockPlus.enabled.then((i) {
if (i) WakelockPlus.disable(); if (i) WakelockPlus.disable();
}); });
_danmakuListener?.cancel();
_tapGestureRecognizer.dispose(); _tapGestureRecognizer.dispose();
_longPressRecognizer?.dispose(); _longPressRecognizer?.dispose();
_doubleTapGestureRecognizer.dispose(); _doubleTapGestureRecognizer.dispose();
@@ -1136,10 +1148,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
void _onTapDown(TapDownDetails details) { void _onTapDown(TapDownDetails details) {
if (!plPlayerController.enableShowDanmaku.value) {
_removeDmAction();
return;
}
final ctr = plPlayerController.danmakuController; final ctr = plPlayerController.danmakuController;
if (ctr != null) { if (ctr != null) {
final pos = details.localPosition; final pos = details.localPosition;
@@ -1148,6 +1156,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_removeDmAction(); _removeDmAction();
} else if (item != _suspendedDm) { } else if (item != _suspendedDm) {
if (item.content.extra == null) { if (item.content.extra == null) {
assert(false, 'empty extra: $item');
_removeDmAction(); _removeDmAction();
return; return;
} }
@@ -1180,6 +1189,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false); ..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false);
late final OneSequenceGestureRecognizer _tapGestureRecognizer; late final OneSequenceGestureRecognizer _tapGestureRecognizer;
late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer; late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer;
StreamSubscription<bool>? _danmakuListener;
void _onPointerDown(PointerDownEvent event) { void _onPointerDown(PointerDownEvent event) {
if (Utils.isDesktop) { if (Utils.isDesktop) {
@@ -1338,7 +1348,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Obx( Obx(
() { () {
if (!plPlayerController.enableShowDanmaku.value) { if (!plPlayerController.enableShowDanmaku.value) {
_removeDmAction();
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
final dmOffset = _dmOffset.value; final dmOffset = _dmOffset.value;