fix: 使用点击序号防止双击误暂停
This commit is contained in:
1 parent
9ddd7fc833
commit
bbc759473c
7 files changed
+113
-61
No files matched your search
@@ -56,6 +56,7 @@ class HomeFeedOverlay extends StatefulWidget {
|
||||
required this.onBoostEnd,
|
||||
required this.onMore,
|
||||
this.onDoubleTapLike,
|
||||
this.now,
|
||||
this.likeCount,
|
||||
this.favoriteCount,
|
||||
this.commentCount,
|
||||
@@ -94,6 +95,7 @@ class HomeFeedOverlay extends StatefulWidget {
|
||||
final VoidCallback onBoostEnd;
|
||||
final VoidCallback onMore;
|
||||
final ValueChanged<Offset>? onDoubleTapLike;
|
||||
final DateTime Function()? now;
|
||||
final VoidCallback? onScrubStart;
|
||||
final ValueChanged<bool>? onScrubEnd;
|
||||
final ValueChanged<bool>? onScrubVisibilityChanged;
|
||||
@@ -107,12 +109,13 @@ class HomeFeedOverlay extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
static const Duration _singleTapDelay = Duration(milliseconds: 280);
|
||||
static const Duration _singleTapDelay = Duration(milliseconds: 320);
|
||||
|
||||
bool _scrubbing = false;
|
||||
bool _wasVisibleBeforeScrub = true;
|
||||
Timer? _singleTapTimer;
|
||||
DateTime? _lastTapAt;
|
||||
int _tapSeq = 0;
|
||||
int _nextHeartBurstId = 0;
|
||||
final List<({int id, Offset position})> _heartBursts = [];
|
||||
|
||||
@@ -126,6 +129,7 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tapSeq++;
|
||||
_singleTapTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -249,11 +253,11 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
}
|
||||
|
||||
void _handleTapUp(TapUpDetails details) {
|
||||
final now = DateTime.now();
|
||||
final tapSeq = ++_tapSeq;
|
||||
final now = widget.now?.call() ?? DateTime.now();
|
||||
final lastTap = _lastTapAt;
|
||||
if (_singleTapTimer != null &&
|
||||
lastTap != null &&
|
||||
now.difference(lastTap) <= _singleTapDelay) {
|
||||
if (lastTap != null && now.difference(lastTap) <= _singleTapDelay) {
|
||||
_tapSeq++;
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = null;
|
||||
_lastTapAt = null;
|
||||
@@ -262,11 +266,22 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
}
|
||||
_lastTapAt = now;
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = Timer(_singleTapDelay, () {
|
||||
_singleTapTimer = null;
|
||||
late final Timer pending;
|
||||
pending = Timer(_singleTapDelay, () {
|
||||
if (identical(_singleTapTimer, pending)) {
|
||||
_singleTapTimer = null;
|
||||
}
|
||||
if (tapSeq != _tapSeq) return;
|
||||
final latestTap = _lastTapAt;
|
||||
if (latestTap != null &&
|
||||
(widget.now?.call() ?? DateTime.now()).difference(latestTap) <
|
||||
_singleTapDelay) {
|
||||
return;
|
||||
}
|
||||
_lastTapAt = null;
|
||||
if (mounted) widget.onTogglePlay();
|
||||
});
|
||||
_singleTapTimer = pending;
|
||||
}
|
||||
|
||||
void _showHearts(Offset position) {
|
||||
@@ -281,6 +296,7 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
}
|
||||
|
||||
void _handleLongPressStart(LongPressStartDetails details, double width) {
|
||||
_tapSeq++;
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = null;
|
||||
_lastTapAt = null;
|
||||
|
||||
Reference in new issue
Block a user