Phone chat peek: transcript-only peek, tap-or-scroll, animated switch
The inactive (peek) pane no longer shows the chat's bar: ChatPanePresentation tells the conversation its role and ChatPaneBarReveal keeps a resting peek's bar offstage (zero height, not painted), so the peek reads its transcript from the top. A drag on the peek scrolls that transcript; a tap anywhere on it, even over a button or link, activates the chat (ChatPeekTapRecognizer accepts on release ahead of the arena sweep and yields to drags past the slop). The 'chat-peek-<id>' semantics stay a labelled button. Switching animates (260 ms, Cubic(.2,.8,.2,1)): the tapped chat rises over the active one with its bottom edge pinned, then the covered chat slides up into the slot from the bottom edge; each bar fades and slides in or out over the rise. Content boxes keep their fixed size, so ticks move and clip retained pictures without laying a transcript out again. Reduced motion jumps. The old focus stripe is gone.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Taps on the peek open that chat; drags still reach its transcript.
|
||||
///
|
||||
/// Placed above the peek's content, the recognizer joins every pointer's arena
|
||||
/// along with the transcript's own recognizers. A move past the touch slop
|
||||
/// rejects it, so the scrollable takes the drag as usual. A release without
|
||||
/// one accepts it at once, ahead of the sweep that would otherwise hand the
|
||||
/// tap to a button or link under the finger: a tap anywhere on the peek
|
||||
/// activates the chat and nothing inside it is pressed.
|
||||
class ChatPeekTapRecognizer extends OneSequenceGestureRecognizer {
|
||||
ChatPeekTapRecognizer({super.debugOwner, super.supportedDevices});
|
||||
|
||||
VoidCallback? onTap;
|
||||
Offset? _origin;
|
||||
bool _won = false;
|
||||
bool _released = false;
|
||||
|
||||
@override
|
||||
void addAllowedPointer(PointerDownEvent event) {
|
||||
startTrackingPointer(event.pointer, event.transform);
|
||||
_origin = event.position;
|
||||
_won = false;
|
||||
_released = false;
|
||||
}
|
||||
|
||||
@override
|
||||
void handleEvent(PointerEvent event) {
|
||||
if (event is PointerMoveEvent) {
|
||||
final slop = computeHitSlop(event.kind, gestureSettings);
|
||||
if ((event.position - _origin!).distance > slop) {
|
||||
resolve(GestureDisposition.rejected);
|
||||
stopTrackingPointer(event.pointer);
|
||||
}
|
||||
} else if (event is PointerUpEvent) {
|
||||
_released = true;
|
||||
if (_won) {
|
||||
_tap();
|
||||
} else {
|
||||
// Alone or not, the win must come before the arena's sweep.
|
||||
resolve(GestureDisposition.accepted);
|
||||
}
|
||||
stopTrackingPointer(event.pointer);
|
||||
} else if (event is PointerCancelEvent) {
|
||||
resolve(GestureDisposition.rejected);
|
||||
stopTrackingPointer(event.pointer);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void acceptGesture(int pointer) {
|
||||
// As the arena's only member the win arrives on the press; the tap still
|
||||
// waits for the release, and a drag past the slop cancels it.
|
||||
if (_released) {
|
||||
_tap();
|
||||
} else {
|
||||
_won = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void rejectGesture(int pointer) => stopTrackingPointer(pointer);
|
||||
|
||||
@override
|
||||
void didStopTrackingLastPointer(int pointer) {
|
||||
_origin = null;
|
||||
_won = false;
|
||||
_released = false;
|
||||
}
|
||||
|
||||
void _tap() {
|
||||
if (onTap case final tap?) invokeCallback<void>('onTap', tap);
|
||||
}
|
||||
|
||||
@override
|
||||
String get debugDescription => 'chat peek tap';
|
||||
}
|
||||
|
||||
/// Lets [child] (the peek's content) scroll under a drag while a tap calls
|
||||
/// [onTap]; with no [onTap] it only passes pointers through.
|
||||
class ChatPeekGesture extends StatelessWidget {
|
||||
const ChatPeekGesture({super.key, required this.onTap, required this.child});
|
||||
|
||||
final VoidCallback? onTap;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RawGestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
gestures: onTap == null
|
||||
? const <Type, GestureRecognizerFactory>{}
|
||||
: <Type, GestureRecognizerFactory>{
|
||||
ChatPeekTapRecognizer:
|
||||
GestureRecognizerFactoryWithHandlers<ChatPeekTapRecognizer>(
|
||||
() => ChatPeekTapRecognizer(debugOwner: this),
|
||||
(recognizer) => recognizer.onTap = onTap,
|
||||
),
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user