fix: 修正双击点赞与心形联动
This commit is contained in:
1 parent
78d0166eb7
commit
68ccfa21c0
8 files changed
+200
-64
No files matched your search
@@ -107,9 +107,12 @@ class HomeFeedOverlay extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
static const Duration _singleTapDelay = Duration(milliseconds: 280);
|
||||
|
||||
bool _scrubbing = false;
|
||||
bool _wasVisibleBeforeScrub = true;
|
||||
Offset? _doubleTapPosition;
|
||||
Timer? _singleTapTimer;
|
||||
DateTime? _lastTapAt;
|
||||
int _nextHeartBurstId = 0;
|
||||
final List<({int id, Offset position})> _heartBursts = [];
|
||||
|
||||
@@ -121,6 +124,12 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_singleTapTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
@@ -135,10 +144,7 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
child: GestureDetector(
|
||||
key: const Key('home-feed-gesture'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: _handleSurfaceTap,
|
||||
onDoubleTapDown: (details) =>
|
||||
_doubleTapPosition = details.localPosition,
|
||||
onDoubleTap: _handleDoubleTap,
|
||||
onTapUp: _handleTapUp,
|
||||
onLongPressStart: (details) =>
|
||||
_handleLongPressStart(details, constraints.maxWidth),
|
||||
onLongPressEnd: (_) => widget.onBoostEnd(),
|
||||
@@ -242,13 +248,28 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
widget.onScrubEnd?.call(wasVisible);
|
||||
}
|
||||
|
||||
void _handleSurfaceTap() {
|
||||
widget.onTogglePlay();
|
||||
void _handleTapUp(TapUpDetails details) {
|
||||
final now = DateTime.now();
|
||||
final lastTap = _lastTapAt;
|
||||
if (_singleTapTimer != null &&
|
||||
lastTap != null &&
|
||||
now.difference(lastTap) <= _singleTapDelay) {
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = null;
|
||||
_lastTapAt = null;
|
||||
_showHearts(details.localPosition);
|
||||
return;
|
||||
}
|
||||
_lastTapAt = now;
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = Timer(_singleTapDelay, () {
|
||||
_singleTapTimer = null;
|
||||
_lastTapAt = null;
|
||||
if (mounted) widget.onTogglePlay();
|
||||
});
|
||||
}
|
||||
|
||||
void _handleDoubleTap() {
|
||||
final position = _doubleTapPosition;
|
||||
if (position == null) return;
|
||||
void _showHearts(Offset position) {
|
||||
final id = _nextHeartBurstId++;
|
||||
setState(() => _heartBursts.add((id: id, position: position)));
|
||||
widget.onDoubleTapLike?.call(position);
|
||||
@@ -260,6 +281,9 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||
}
|
||||
|
||||
void _handleLongPressStart(LongPressStartDetails details, double width) {
|
||||
_singleTapTimer?.cancel();
|
||||
_singleTapTimer = null;
|
||||
_lastTapAt = null;
|
||||
final third = width / 3;
|
||||
final dx = details.localPosition.dx;
|
||||
if (dx < third || dx > width - third) {
|
||||
|
||||
Reference in new issue
Block a user