mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: hide danmaku (#1654)
This commit is contained in:
committed by
GitHub
parent
340a933e70
commit
7524b3d168
@@ -6,13 +6,13 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
super.debugOwner,
|
||||
super.supportedDevices,
|
||||
super.allowedButtonsFilter,
|
||||
required this.onTapDown,
|
||||
this.onTapDown,
|
||||
required this.onTapUp,
|
||||
required this.onTapCancel,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
final GestureTapDownCallback onTapDown;
|
||||
GestureTapDownCallback? onTapDown;
|
||||
|
||||
final GestureTapUpCallback onTapUp;
|
||||
|
||||
@@ -35,10 +35,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
@override
|
||||
void addAllowedPointer(PointerDownEvent event) {
|
||||
super.addAllowedPointer(event);
|
||||
|
||||
_activePointer = event.pointer;
|
||||
_sentTapDown = false;
|
||||
_wonArena = false;
|
||||
_reset(event.pointer);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -63,13 +60,15 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
void _handleTapDown(PointerDownEvent event) {
|
||||
if (_sentTapDown) return;
|
||||
|
||||
if (onTapDown != null) {
|
||||
_sentTapDown = true;
|
||||
final details = TapDownDetails(
|
||||
globalPosition: event.position,
|
||||
localPosition: event.localPosition,
|
||||
kind: event.kind,
|
||||
);
|
||||
invokeCallback<void>('onTapDown', () => onTapDown(details));
|
||||
invokeCallback<void>('onTapDown', () => onTapDown!(details));
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerMove(PointerMoveEvent event) {
|
||||
@@ -80,13 +79,12 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
}
|
||||
|
||||
void _handlePointerUp(PointerUpEvent event) {
|
||||
if (_wonArena && _sentTapDown) {
|
||||
if (_wonArena) {
|
||||
_handleTapUp(event);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleTapUp(PointerUpEvent event) {
|
||||
if (_sentTapDown) {
|
||||
final details = TapUpDetails(
|
||||
globalPosition: event.position,
|
||||
localPosition: event.localPosition,
|
||||
@@ -97,7 +95,6 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
if (onTap != null) {
|
||||
invokeCallback<void>('onTap', onTap!);
|
||||
}
|
||||
}
|
||||
|
||||
_reset();
|
||||
}
|
||||
@@ -109,8 +106,8 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
_reset();
|
||||
}
|
||||
|
||||
void _reset() {
|
||||
_activePointer = 0;
|
||||
void _reset([int pointer = 0]) {
|
||||
_activePointer = pointer;
|
||||
_up = null;
|
||||
_sentTapDown = false;
|
||||
_wonArena = false;
|
||||
@@ -123,7 +120,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
if (pointer == _activePointer) {
|
||||
_wonArena = true;
|
||||
|
||||
if (_up != null && _sentTapDown) {
|
||||
if (_up != null) {
|
||||
_handleTapUp(_up!);
|
||||
}
|
||||
}
|
||||
@@ -146,10 +143,7 @@ class ImmediateTapGestureRecognizer extends OneSequenceGestureRecognizer {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_sentTapDown) {
|
||||
_cancelGesture('disposed');
|
||||
}
|
||||
_reset();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -221,14 +221,25 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
});
|
||||
}
|
||||
|
||||
_tapGestureRecognizer = plPlayerController.enableTapDm
|
||||
? ImmediateTapGestureRecognizer(
|
||||
onTapDown: _onTapDown,
|
||||
if (plPlayerController.enableTapDm) {
|
||||
_tapGestureRecognizer = ImmediateTapGestureRecognizer(
|
||||
onTapDown: plPlayerController.enableShowDanmaku.value
|
||||
? _onTapDown
|
||||
: null,
|
||||
onTapUp: _onTapUp,
|
||||
onTapCancel: _removeDmAction,
|
||||
allowedButtonsFilter: (buttons) => buttons == kPrimaryButton,
|
||||
)
|
||||
: (TapGestureRecognizer()..onTapUp = _onTapUp);
|
||||
);
|
||||
|
||||
_danmakuListener = plPlayerController.enableShowDanmaku.listen((value) {
|
||||
if (!value) _removeDmAction();
|
||||
(_tapGestureRecognizer as ImmediateTapGestureRecognizer).onTapDown =
|
||||
value ? _onTapDown : null;
|
||||
});
|
||||
} else {
|
||||
_tapGestureRecognizer = TapGestureRecognizer()..onTapUp = _onTapUp;
|
||||
}
|
||||
|
||||
_doubleTapGestureRecognizer = DoubleTapGestureRecognizer()
|
||||
..onDoubleTapDown = _onDoubleTapDown;
|
||||
}
|
||||
@@ -277,6 +288,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
WakelockPlus.enabled.then((i) {
|
||||
if (i) WakelockPlus.disable();
|
||||
});
|
||||
_danmakuListener?.cancel();
|
||||
_tapGestureRecognizer.dispose();
|
||||
_longPressRecognizer?.dispose();
|
||||
_doubleTapGestureRecognizer.dispose();
|
||||
@@ -1136,10 +1148,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
|
||||
void _onTapDown(TapDownDetails details) {
|
||||
if (!plPlayerController.enableShowDanmaku.value) {
|
||||
_removeDmAction();
|
||||
return;
|
||||
}
|
||||
final ctr = plPlayerController.danmakuController;
|
||||
if (ctr != null) {
|
||||
final pos = details.localPosition;
|
||||
@@ -1148,6 +1156,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
_removeDmAction();
|
||||
} else if (item != _suspendedDm) {
|
||||
if (item.content.extra == null) {
|
||||
assert(false, 'empty extra: $item');
|
||||
_removeDmAction();
|
||||
return;
|
||||
}
|
||||
@@ -1180,6 +1189,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false);
|
||||
late final OneSequenceGestureRecognizer _tapGestureRecognizer;
|
||||
late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer;
|
||||
StreamSubscription<bool>? _danmakuListener;
|
||||
|
||||
void _onPointerDown(PointerDownEvent event) {
|
||||
if (Utils.isDesktop) {
|
||||
@@ -1338,7 +1348,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
Obx(
|
||||
() {
|
||||
if (!plPlayerController.enableShowDanmaku.value) {
|
||||
_removeDmAction();
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final dmOffset = _dmOffset.value;
|
||||
|
||||
Reference in New Issue
Block a user