mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## Why I find myself putting my finger down before scrolling and end up triggering the long press. Each time I think "but i wasnt touching anything?" ## Summary On mobile, the long-press recognizer covered the whole message row, so holding the empty space beside a bubble in a channel, DM or thread opened that message's actions. A hold now opens the actions only when it lands on a part of the message. - **Bubble and media:** a hold on the painted bubble or media opens the actions, as before. - **Other message parts:** the avatar, author line, edited marker, photo count label, reply footer and add-reaction button are marked as long-press targets around their own extent, so they still open the actions while the unused row width beside them stays inert. - **Empty space beside a message:** a hold there opens nothing and gives no haptic, and releasing it does not open the thread. A quick tap there still opens the thread. - **Unchanged:** swipe-to-reply still starts only on the bubble and media, and the screen-reader long press, the reaction tray's long press and the system rows' full-row hold behave as before. https://github.com/user-attachments/assets/2ede96b0-b9dd-49f3-926f-5cad32f7242e ### Related issue N/A. I searched issues and PRs for "long press" and found none for this; the closest is #8500 (action sheet opening while scrolling), which is a different problem. ### Testing Widget tests in `swipe_reply_tests.dart` cover a hold beside the bubble (no actions, no thread, no haptic, and a quick tap still opens the thread), a hold on each message part in channels and threads for own and other messages, attachment and gallery holds, the semantics long press, and that a swipe from the non-bubble parts starts no reply. Side-by-side recording on an iPhone 17 Pro simulator (iOS 27.2), `main` on the left and this branch on the right, running the same four 1.0 s holds at the same coordinates. The red ring marks the press point and was overlaid afterwards. Holding the empty space beside a message opens the action sheet on the left and nothing on the right; holding the bubble opens it on both sides. The recording was made at the first commit on this branch (`378dde654`), before the two follow-up commits, and uses a local relay with seeded throwaway data. It covers short messages from another author in a channel and a thread; own messages, DMs and media are covered by the tests only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Matt Toohey <contact@matttoohey.com> Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Jitter <2b2e6415e748c35180847a37aadae06a11e30dddc76b784e7fd9354c4eb42e7a@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
89 lines
2.9 KiB
Dart
89 lines
2.9 KiB
Dart
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Marks a painted part of a message that opens its long-press actions but
|
|
/// cannot start a reply drag: the author line, footer and similar.
|
|
///
|
|
/// Wrap the part's shrink-wrapped extent, not a full-width row, so the empty
|
|
/// space beside it stays inert.
|
|
class MessageLongPressTarget extends SingleChildRenderObjectWidget {
|
|
const MessageLongPressTarget({super.key, required super.child});
|
|
|
|
@override
|
|
RenderObject createRenderObject(BuildContext context) =>
|
|
_RenderMessageLongPressTarget();
|
|
}
|
|
|
|
class _RenderMessageLongPressTarget extends RenderProxyBox {
|
|
@override
|
|
bool hitTestSelf(Offset position) => true;
|
|
}
|
|
|
|
/// Marks visible message content that can start a reply drag and, unless
|
|
/// [opensActions] is false, open the message's long-press actions.
|
|
class MessageReplyDragTarget extends SingleChildRenderObjectWidget {
|
|
const MessageReplyDragTarget({
|
|
super.key,
|
|
this.opensActions = true,
|
|
required super.child,
|
|
});
|
|
|
|
/// Whether a long press anywhere on this target opens the message's actions.
|
|
///
|
|
/// Pass false when the target is wider than what it paints, and mark the
|
|
/// painted part with a [MessageLongPressTarget] instead.
|
|
final bool opensActions;
|
|
|
|
@override
|
|
RenderObject createRenderObject(BuildContext context) =>
|
|
_RenderMessageReplyDragTarget(opensActions);
|
|
|
|
@override
|
|
void updateRenderObject(
|
|
BuildContext context,
|
|
covariant RenderObject renderObject,
|
|
) {
|
|
(renderObject as _RenderMessageReplyDragTarget).opensActions = opensActions;
|
|
}
|
|
}
|
|
|
|
class _RenderMessageReplyDragTarget extends RenderProxyBox {
|
|
_RenderMessageReplyDragTarget(this.opensActions);
|
|
|
|
bool opensActions;
|
|
|
|
@override
|
|
bool hitTestSelf(Offset position) => true;
|
|
}
|
|
|
|
/// Whether [globalPosition] lands on a painted part of the message under
|
|
/// [region], rather than on the empty row space around those parts.
|
|
bool messageLongPressTargetAt(RenderObject? region, Offset globalPosition) {
|
|
if (region is! RenderBox || !region.hasSize) return false;
|
|
final result = BoxHitTestResult();
|
|
region.hitTest(result, position: region.globalToLocal(globalPosition));
|
|
return result.path.any((entry) {
|
|
final target = entry.target;
|
|
return target is _RenderMessageLongPressTarget ||
|
|
target is _RenderMessageReplyDragTarget && target.opensActions;
|
|
});
|
|
}
|
|
|
|
/// Tests painted message regions rather than the full-width content layout.
|
|
Rect? messageReplyDragTargetBounds(
|
|
GlobalKey contentKey,
|
|
Offset globalPosition,
|
|
) {
|
|
final box = contentKey.currentContext?.findRenderObject();
|
|
if (box is! RenderBox || !box.hasSize) return null;
|
|
final result = BoxHitTestResult();
|
|
box.hitTest(result, position: box.globalToLocal(globalPosition));
|
|
for (final entry in result.path) {
|
|
final target = entry.target;
|
|
if (target is _RenderMessageReplyDragTarget) {
|
|
return target.localToGlobal(Offset.zero) & target.size;
|
|
}
|
|
}
|
|
return null;
|
|
}
|