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,75 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// How a retained chat presents itself where several share the screen.
|
||||
///
|
||||
/// The active chat shows its bar. A peek (the other chat glimpsed below it on
|
||||
/// a phone) shows transcript only, from its top edge, so the glimpse reads as
|
||||
/// conversation rather than as a second set of controls. [barReveal] runs
|
||||
/// once when the roles swap: 0 is a hidden bar and 1 a shown one, so the
|
||||
/// newly active chat's bar fades and slides in while the peek's fades out.
|
||||
class ChatPanePresentation extends InheritedWidget {
|
||||
const ChatPanePresentation({
|
||||
super.key,
|
||||
required this.peek,
|
||||
required this.barReveal,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
final bool peek;
|
||||
final Animation<double> barReveal;
|
||||
|
||||
static ChatPanePresentation? maybeOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<ChatPanePresentation>();
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ChatPanePresentation oldWidget) =>
|
||||
peek != oldWidget.peek || barReveal != oldWidget.barReveal;
|
||||
}
|
||||
|
||||
/// The conversation's bar under a [ChatPanePresentation].
|
||||
///
|
||||
/// Without one the bar is itself. As its chat becomes active the bar fades
|
||||
/// and slides down into place over the transcript, which already keeps clear
|
||||
/// of it. As its chat becomes the peek the bar fades out in place, keeping
|
||||
/// its height until it has gone (by then the arriving chat covers it). A
|
||||
/// resting peek keeps the bar offstage: not painted, taking no height, no
|
||||
/// pointers and no semantics, so its transcript starts at the top, yet still
|
||||
/// mounted, so the next switch fades the same bar rather than building a new
|
||||
/// one (whose pieces would replay their entrances).
|
||||
class ChatPaneBarReveal extends StatelessWidget {
|
||||
const ChatPaneBarReveal({super.key, required this.bar});
|
||||
|
||||
final Widget bar;
|
||||
|
||||
/// How far above its place the bar starts, as a share of its height.
|
||||
static const double slide = .12;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final presentation = ChatPanePresentation.maybeOf(context);
|
||||
if (presentation == null) return bar;
|
||||
final reveal = presentation.barReveal;
|
||||
final peek = presentation.peek;
|
||||
// One tree in both roles, so the bar's element outlives a switch.
|
||||
return AnimatedBuilder(
|
||||
animation: reveal,
|
||||
child: IgnorePointer(
|
||||
ignoring: peek,
|
||||
child: FadeTransition(
|
||||
opacity: reveal,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0, -slide),
|
||||
end: Offset.zero,
|
||||
).animate(reveal),
|
||||
// The bar's own picture holds while it slides; only its offset
|
||||
// and alpha change per tick.
|
||||
child: RepaintBoundary(child: bar),
|
||||
),
|
||||
),
|
||||
),
|
||||
builder: (context, child) =>
|
||||
Offstage(offstage: peek && reveal.value <= 0, child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
||||
import '../../../ui/layout/app_sheet_header.dart';
|
||||
import '../../../ui/layout/wheel_scroll_forwarding.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import 'chat_pane_presentation.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_anchor.dart';
|
||||
import 'chat_transcript_cache.dart';
|
||||
@@ -967,7 +968,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
final page = FloatingBarOverlay(
|
||||
bar: composerBar,
|
||||
child: SegmentedBarOverlay(
|
||||
bar: _header(context, inShellBar),
|
||||
bar: ChatPaneBarReveal(bar: _header(context, inShellBar)),
|
||||
child: NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: _onScrollMetrics,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import '../conversation/chat_pane_presentation.dart';
|
||||
import 'chat_peek_gesture.dart';
|
||||
import 'chat_workspace_controller.dart';
|
||||
|
||||
/// A phone presentation only: saved split axes and ratios are left untouched.
|
||||
@@ -14,6 +14,7 @@ class ChatMobilePanes {
|
||||
required Size size,
|
||||
}) {
|
||||
final active = panes.firstWhere((pane) => pane.id == activeId);
|
||||
this.activeId = active.id;
|
||||
final peek =
|
||||
panes
|
||||
.where((pane) => pane.id == peekId && pane.id != activeId)
|
||||
@@ -25,6 +26,7 @@ class ChatMobilePanes {
|
||||
return;
|
||||
}
|
||||
this.peekId = peek.id;
|
||||
this.activeId = active.id;
|
||||
const gap = 6.0;
|
||||
final available = math.max(0.0, size.height - gap);
|
||||
final peekHeight = available * .2;
|
||||
@@ -41,147 +43,85 @@ class ChatMobilePanes {
|
||||
late final double contentHeight;
|
||||
final rects = <String, Rect>{};
|
||||
String? peekId;
|
||||
String? activeId;
|
||||
|
||||
/// [panes] with the active one last: it is drawn over the other during a
|
||||
/// switch and takes pointers first.
|
||||
List<ChatWorkspacePane> paintOrder(List<ChatWorkspacePane> panes) => [
|
||||
for (final pane in panes)
|
||||
if (pane.id != activeId) pane,
|
||||
for (final pane in panes)
|
||||
if (pane.id == activeId) pane,
|
||||
];
|
||||
}
|
||||
|
||||
/// Both mobile threads retain the same full content layout. Selection changes
|
||||
/// positions once; only a tiny focus cue animates, so transcript layout, scroll
|
||||
/// anchoring and backdrop painting do not repeat on every animation tick.
|
||||
class ChatMobilePaneViewport extends StatefulWidget {
|
||||
/// One retained chat in the phone presentation.
|
||||
///
|
||||
/// Both chats keep the same full content box ([contentHeight]), aligned to
|
||||
/// the pane's top and clipped to it, so a switch moves and clips retained
|
||||
/// pictures without laying a transcript out again. The peek shows its
|
||||
/// transcript from the top (its bar steps aside through
|
||||
/// [ChatPanePresentation]); a drag on it scrolls that transcript and a tap
|
||||
/// activates the chat. The tree keeps one shape in both roles, so a chat
|
||||
/// changing role keeps its state.
|
||||
class ChatMobilePaneViewport extends StatelessWidget {
|
||||
const ChatMobilePaneViewport({
|
||||
super.key,
|
||||
required this.peek,
|
||||
required this.active,
|
||||
required this.animate,
|
||||
required this.barReveal,
|
||||
required this.child,
|
||||
required this.onActivate,
|
||||
required this.label,
|
||||
required this.paneId,
|
||||
this.contentHeight,
|
||||
});
|
||||
|
||||
final bool peek;
|
||||
final bool active;
|
||||
final bool animate;
|
||||
|
||||
/// The bar's reveal for this pane's role (see [ChatPanePresentation]).
|
||||
final Animation<double> barReveal;
|
||||
final Widget child;
|
||||
final VoidCallback onActivate;
|
||||
final String label;
|
||||
final String paneId;
|
||||
final double? contentHeight;
|
||||
@override
|
||||
State<ChatMobilePaneViewport> createState() => _ChatMobilePaneViewportState();
|
||||
}
|
||||
|
||||
class _ChatMobilePaneViewportState extends State<ChatMobilePaneViewport>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _reveal;
|
||||
late final CurvedAnimation _accent;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_reveal = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 120),
|
||||
value: 1,
|
||||
);
|
||||
_accent = CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatMobilePaneViewport oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!widget.animate || !widget.active) {
|
||||
_reveal.value = 1;
|
||||
} else if (!oldWidget.active) {
|
||||
_reveal.forward(from: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_accent.dispose();
|
||||
_reveal.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ClipRect(
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
OverflowBox(
|
||||
child: Semantics(
|
||||
key: ValueKey('chat-peek-$paneId'),
|
||||
identifier: peek ? 'chat-peek-$paneId' : null,
|
||||
container: peek,
|
||||
sortKey: peek ? const OrdinalSortKey(1) : null,
|
||||
label: peek ? 'Expand $label' : null,
|
||||
button: peek ? true : null,
|
||||
onTap: peek ? onActivate : null,
|
||||
child: ChatPeekGesture(
|
||||
onTap: peek ? onActivate : null,
|
||||
child: OverflowBox(
|
||||
alignment: Alignment.topCenter,
|
||||
minHeight: widget.contentHeight,
|
||||
maxHeight: widget.contentHeight,
|
||||
minHeight: contentHeight,
|
||||
maxHeight: contentHeight,
|
||||
child: SizedBox(
|
||||
height: widget.contentHeight,
|
||||
height: contentHeight,
|
||||
child: ExcludeFocus(
|
||||
excluding: widget.peek,
|
||||
excluding: peek,
|
||||
child: ExcludeSemantics(
|
||||
excluding: widget.peek,
|
||||
child: IgnorePointer(
|
||||
ignoring: widget.peek,
|
||||
child: RepaintBoundary(child: widget.child),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.peek)
|
||||
Semantics(
|
||||
key: ValueKey('chat-peek-${widget.paneId}'),
|
||||
identifier: 'chat-peek-${widget.paneId}',
|
||||
container: true,
|
||||
sortKey: const OrdinalSortKey(1),
|
||||
label: 'Expand ${widget.label}',
|
||||
button: true,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: widget.onActivate,
|
||||
),
|
||||
),
|
||||
if (widget.active && widget.animate)
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
height: 2,
|
||||
child: IgnorePointer(
|
||||
child: RepaintBoundary(
|
||||
child: CustomPaint(
|
||||
key: ValueKey('chat-focus-accent-${widget.paneId}'),
|
||||
painter: ChatPaneFocusAccent(
|
||||
progress: _accent,
|
||||
color:
|
||||
chatControlsStyleOf(context) ==
|
||||
ChatControlsStyle.cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
excluding: peek,
|
||||
child: RepaintBoundary(
|
||||
child: ChatPanePresentation(
|
||||
peek: peek,
|
||||
barReveal: barReveal,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Only this tiny focus stripe repaints during the transition; the rich chat
|
||||
/// body remains opaque and stationary, avoiding a full-pane alpha/saveLayer.
|
||||
class ChatPaneFocusAccent extends CustomPainter {
|
||||
ChatPaneFocusAccent({required this.progress, required this.color})
|
||||
: super(repaint: progress);
|
||||
final Animation<double> progress;
|
||||
final Color color;
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
if (progress.value >= 1) return;
|
||||
canvas.drawRect(
|
||||
Offset.zero & size,
|
||||
Paint()..color = color.withValues(alpha: (1 - progress.value) * .7),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant ChatPaneFocusAccent oldDelegate) =>
|
||||
oldDelegate.color != color || oldDelegate.progress != progress;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' show lerpDouble;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// The phone presentation's switch: a cover, then a settle.
|
||||
///
|
||||
/// The chat coming forward rises from the peek slot over the active chat,
|
||||
/// which stays where it is until covered; the rising pane keeps its bottom
|
||||
/// edge at the screen's bottom so nothing shows between them. Once it has
|
||||
/// arrived ([riseShare] of [duration]), the covered chat moves to the slot
|
||||
/// unseen and slides up into it from the bottom edge. Each bar follows the
|
||||
/// rise: [rise] for the chat coming forward, [recede] for the one going back.
|
||||
///
|
||||
/// The content boxes keep their fixed size throughout, so a tick moves and
|
||||
/// clips retained pictures; nothing inside a transcript is laid out again.
|
||||
class ChatPaneSwitchMotion {
|
||||
ChatPaneSwitchMotion({required TickerProvider vsync})
|
||||
: _controller = AnimationController(
|
||||
vsync: vsync,
|
||||
duration: duration,
|
||||
value: 1,
|
||||
) {
|
||||
rise = CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0, riseShare, curve: curve),
|
||||
);
|
||||
settle = CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(riseShare, 1, curve: curve),
|
||||
);
|
||||
recede = ReverseAnimation(rise);
|
||||
}
|
||||
|
||||
/// A touch quicker than a stock iOS transition, with its kind of ease.
|
||||
static const Duration duration = Duration(milliseconds: 260);
|
||||
static const Curve curve = Cubic(.2, .8, .2, 1);
|
||||
|
||||
/// The share of [duration] in which the chat coming forward rises; the rest
|
||||
/// settles the peek beneath it.
|
||||
static const double riseShare = .7;
|
||||
|
||||
final AnimationController _controller;
|
||||
|
||||
/// 0 as a switch starts, 1 once the chat coming forward has arrived.
|
||||
late final CurvedAnimation rise;
|
||||
|
||||
/// 0 until the chat coming forward has arrived, 1 once the peek has settled.
|
||||
late final CurvedAnimation settle;
|
||||
|
||||
/// 1 as a switch starts, 0 once the chat coming forward has arrived.
|
||||
late final Animation<double> recede;
|
||||
|
||||
/// Ticks through both phases, for rebuilding positions.
|
||||
Animation<double> get animation => _controller.view;
|
||||
|
||||
Map<String, Rect> _from = const {};
|
||||
Map<String, Rect> _to = const {};
|
||||
String? _activeId;
|
||||
Size? _size;
|
||||
|
||||
bool get isAnimating => _controller.isAnimating;
|
||||
|
||||
/// Records this layout's [rects] for a phone presentation of [size] with
|
||||
/// [activeId] in front.
|
||||
///
|
||||
/// A switch (the active pane changed) in an unchanged size travels from
|
||||
/// where the panes are now, so one that interrupts another continues
|
||||
/// smoothly. Any other change of rects, and every change when [animate] is
|
||||
/// off, takes effect at once.
|
||||
void layout({
|
||||
required Map<String, Rect> rects,
|
||||
required Size size,
|
||||
required String activeId,
|
||||
required bool switching,
|
||||
required bool animate,
|
||||
}) {
|
||||
final travel = switching && animate && _size == size && _to.isNotEmpty;
|
||||
_size = size;
|
||||
if (travel) {
|
||||
_from = {
|
||||
for (final id in {..._to.keys, ...rects.keys})
|
||||
id: rectFor(id) ?? rects[id]!,
|
||||
};
|
||||
_to = rects;
|
||||
_activeId = activeId;
|
||||
_controller.forward(from: 0);
|
||||
return;
|
||||
}
|
||||
_activeId = activeId;
|
||||
if (mapEquals(rects, _to)) return;
|
||||
_from = rects;
|
||||
_to = rects;
|
||||
_settle();
|
||||
}
|
||||
|
||||
/// Leaves the phone presentation: panes take their rects directly and every
|
||||
/// bar shows.
|
||||
void rest() {
|
||||
if (_to.isEmpty && _size == null) return;
|
||||
_from = const {};
|
||||
_to = const {};
|
||||
_activeId = null;
|
||||
_size = null;
|
||||
_settle();
|
||||
}
|
||||
|
||||
void _settle() {
|
||||
if (_controller.isAnimating || _controller.value != 1) {
|
||||
_controller.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the chat coming forward has somewhere to rise from.
|
||||
bool get _forwardRises {
|
||||
final id = _activeId;
|
||||
if (id == null) return false;
|
||||
final from = _from[id];
|
||||
return from != null && from != _to[id];
|
||||
}
|
||||
|
||||
/// Where [id]'s pane is now; null outside the phone presentation or for a
|
||||
/// pane it does not place.
|
||||
Rect? rectFor(String id) {
|
||||
final to = _to[id];
|
||||
if (to == null) return null;
|
||||
final from = _from[id] ?? to;
|
||||
if (from == to) return to;
|
||||
final time = _controller.value;
|
||||
if (id == _activeId) {
|
||||
if (time >= riseShare) return to;
|
||||
final t = rise.value;
|
||||
return Rect.fromLTRB(
|
||||
lerpDouble(from.left, to.left, t)!,
|
||||
lerpDouble(from.top, to.top, t)!,
|
||||
lerpDouble(from.right, to.right, t)!,
|
||||
// The bottom edge waits: the gap that would open below the content
|
||||
// box is the slot, filled only once this pane has covered the other.
|
||||
math.max(from.bottom, lerpDouble(from.bottom, to.bottom, t)!),
|
||||
);
|
||||
}
|
||||
if (!_forwardRises) return Rect.lerp(from, to, curve.transform(time))!;
|
||||
if (time < riseShare) return from;
|
||||
final top = lerpDouble(_size?.height ?? to.bottom, to.top, settle.value)!;
|
||||
return Rect.fromLTWH(to.left, top, to.width, to.height);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
rise.dispose();
|
||||
settle.dispose();
|
||||
_controller.dispose();
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'chat_workspace_controller.dart';
|
||||
import 'chat_workspace_divider.dart';
|
||||
import 'chat_workspace_geometry.dart';
|
||||
import 'chat_mobile_panes.dart';
|
||||
import 'chat_pane_switch_motion.dart';
|
||||
|
||||
export 'chat_workspace_controller.dart';
|
||||
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
|
||||
@@ -44,9 +45,11 @@ class ChatWorkspace extends StatefulWidget {
|
||||
State<ChatWorkspace> createState() => _ChatWorkspaceState();
|
||||
}
|
||||
|
||||
class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final _focus = FocusNode(debugLabel: 'Chat workspace');
|
||||
final Map<String, FocusScopeNode> _panes = {};
|
||||
late final ChatPaneSwitchMotion _motion;
|
||||
ChatWorkspaceGeometry? _geometry;
|
||||
String? _lastActiveId;
|
||||
String? _peekId;
|
||||
@@ -54,6 +57,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_motion = ChatPaneSwitchMotion(vsync: this);
|
||||
HardwareKeyboard.instance.addHandler(_key);
|
||||
}
|
||||
|
||||
@@ -103,6 +107,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
@override
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_key);
|
||||
_motion.dispose();
|
||||
_focus.dispose();
|
||||
for (final node in _panes.values) {
|
||||
node.dispose();
|
||||
@@ -124,7 +129,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
final collapsed = widget.singlePane || geometry.collapsed;
|
||||
final panes = widget.controller.panes;
|
||||
final activeId = widget.controller.activePaneId;
|
||||
if (_lastActiveId != activeId) {
|
||||
final switching = _lastActiveId != activeId;
|
||||
if (switching) {
|
||||
_peekId = _lastActiveId;
|
||||
_lastActiveId = activeId;
|
||||
}
|
||||
@@ -136,76 +142,42 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
size: constraints.biggest,
|
||||
)
|
||||
: null;
|
||||
if (mobile == null) {
|
||||
_motion.rest();
|
||||
} else {
|
||||
_motion.layout(
|
||||
rects: mobile.rects,
|
||||
size: constraints.biggest,
|
||||
activeId: activeId!,
|
||||
switching: switching,
|
||||
animate: !MediaQuery.disableAnimationsOf(context),
|
||||
);
|
||||
}
|
||||
final existing = panes.map((p) => p.id).toSet();
|
||||
for (final id
|
||||
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
|
||||
final node = _panes.remove(id)!;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => node.dispose());
|
||||
}
|
||||
final ordered = mobile?.paintOrder(panes) ?? panes;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
for (final pane in panes)
|
||||
Positioned.fromRect(
|
||||
for (final pane in ordered)
|
||||
// A switch moves the retained pane view; the view itself is
|
||||
// built once per layout and only repositioned per tick.
|
||||
AnimatedBuilder(
|
||||
key: ValueKey('chat-workspace-${pane.id}'),
|
||||
rect:
|
||||
mobile?.rects[pane.id] ??
|
||||
(collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!),
|
||||
child: Offstage(
|
||||
offstage: mobile != null
|
||||
? !mobile.rects.containsKey(pane.id)
|
||||
: collapsed &&
|
||||
pane.id != widget.controller.activePaneId,
|
||||
child: ExcludeFocus(
|
||||
excluding:
|
||||
collapsed &&
|
||||
pane.id != widget.controller.activePaneId,
|
||||
child: ChatMobilePaneViewport(
|
||||
peek: mobile?.peekId == pane.id,
|
||||
active: pane.id == activeId,
|
||||
animate:
|
||||
mobile != null &&
|
||||
!MediaQuery.disableAnimationsOf(context),
|
||||
contentHeight: mobile?.contentHeight,
|
||||
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||
paneId: pane.id,
|
||||
onActivate: () {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
widget.controller.activate(pane.id);
|
||||
},
|
||||
child: FocusScope(
|
||||
node: _panes.putIfAbsent(
|
||||
pane.id,
|
||||
() => FocusScopeNode(debugLabel: pane.id),
|
||||
),
|
||||
onFocusChange: (focused) {
|
||||
if (focused && !widget.mobilePeeks) {
|
||||
widget.controller.activate(pane.id);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (_) =>
|
||||
widget.controller.activate(pane.id),
|
||||
child: Semantics(
|
||||
identifier: 'chat-pane-${pane.id}',
|
||||
container: true,
|
||||
sortKey: mobile == null
|
||||
? null
|
||||
: const OrdinalSortKey(0),
|
||||
child: widget.paneBuilder(
|
||||
context,
|
||||
pane,
|
||||
pane.id == widget.controller.activePaneId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
animation: _motion.animation,
|
||||
child: _paneView(pane, mobile, collapsed, activeId),
|
||||
builder: (context, child) => Positioned.fromRect(
|
||||
rect:
|
||||
_motion.rectFor(pane.id) ??
|
||||
(collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
if (!collapsed && mobile == null)
|
||||
@@ -225,4 +197,58 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _paneView(
|
||||
ChatWorkspacePane pane,
|
||||
ChatMobilePanes? mobile,
|
||||
bool collapsed,
|
||||
String? activeId,
|
||||
) {
|
||||
final peek = mobile?.peekId == pane.id;
|
||||
final active = pane.id == activeId;
|
||||
return Offstage(
|
||||
offstage: mobile != null
|
||||
? !mobile.rects.containsKey(pane.id)
|
||||
: collapsed && !active,
|
||||
child: ExcludeFocus(
|
||||
excluding: collapsed && !active,
|
||||
child: ChatMobilePaneViewport(
|
||||
peek: peek,
|
||||
active: active,
|
||||
barReveal: peek ? _motion.recede : _motion.rise,
|
||||
contentHeight: mobile?.contentHeight,
|
||||
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||
paneId: pane.id,
|
||||
onActivate: () {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
widget.controller.activate(pane.id);
|
||||
},
|
||||
child: FocusScope(
|
||||
node: _panes.putIfAbsent(
|
||||
pane.id,
|
||||
() => FocusScopeNode(debugLabel: pane.id),
|
||||
),
|
||||
onFocusChange: (focused) {
|
||||
if (focused && !widget.mobilePeeks) {
|
||||
widget.controller.activate(pane.id);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
// A press in the peek scrolls or taps; the tap alone activates.
|
||||
onPointerDown: peek
|
||||
? null
|
||||
: (_) => widget.controller.activate(pane.id),
|
||||
child: Semantics(
|
||||
identifier: 'chat-pane-${pane.id}',
|
||||
container: true,
|
||||
sortKey: mobile == null ? null : const OrdinalSortKey(0),
|
||||
child: widget.paneBuilder(context, pane, active),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user