Promote active mobile chats immediately and composite a short reveal
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'chat_workspace_controller.dart';
|
||||
@@ -17,6 +18,7 @@ class ChatMobilePanes {
|
||||
.firstOrNull ??
|
||||
panes.where((pane) => pane.id != activeId).firstOrNull;
|
||||
if (peek == null) {
|
||||
contentHeight = size.height;
|
||||
rects[active.id] = Offset.zero & size;
|
||||
return;
|
||||
}
|
||||
@@ -24,80 +26,123 @@ class ChatMobilePanes {
|
||||
const gap = 6.0;
|
||||
final available = math.max(0.0, size.height - gap);
|
||||
final peekHeight = available * .2;
|
||||
final activeHeight = available - peekHeight;
|
||||
final activeFirst = panes.indexOf(active) < panes.indexOf(peek);
|
||||
rects[activeFirst ? active.id : peek.id] = Rect.fromLTWH(
|
||||
0,
|
||||
contentHeight = available - peekHeight;
|
||||
// Selection always promotes the active conversation to the top.
|
||||
rects[active.id] = Rect.fromLTWH(0, 0, size.width, contentHeight);
|
||||
rects[peek.id] = Rect.fromLTWH(
|
||||
0,
|
||||
contentHeight + gap,
|
||||
size.width,
|
||||
activeFirst ? activeHeight : peekHeight,
|
||||
);
|
||||
final topHeight = activeFirst ? activeHeight : peekHeight;
|
||||
rects[activeFirst ? peek.id : active.id] = Rect.fromLTWH(
|
||||
0,
|
||||
topHeight + gap,
|
||||
size.width,
|
||||
activeFirst ? peekHeight : activeHeight,
|
||||
peekHeight,
|
||||
);
|
||||
}
|
||||
late final double contentHeight;
|
||||
final rects = <String, Rect>{};
|
||||
String? peekId;
|
||||
}
|
||||
|
||||
/// Keep a peek's full header/transcript layout available without squeezing its
|
||||
/// composer into a tiny viewport. The clipped preview cannot take input focus.
|
||||
class ChatMobilePaneViewport extends StatelessWidget {
|
||||
/// Both mobile threads retain the same full content layout. Only the cheap
|
||||
/// viewport clip and position change during a switch; transcript layout, scroll
|
||||
/// anchoring and backdrop painting do not repeat on every animation tick.
|
||||
class ChatMobilePaneViewport extends StatefulWidget {
|
||||
const ChatMobilePaneViewport({
|
||||
super.key,
|
||||
required this.peek,
|
||||
required this.active,
|
||||
required this.animate,
|
||||
required this.child,
|
||||
required this.onActivate,
|
||||
required this.label,
|
||||
required this.paneId,
|
||||
this.contentHeight,
|
||||
});
|
||||
final bool peek;
|
||||
final bool active;
|
||||
final bool animate;
|
||||
final Widget child;
|
||||
final VoidCallback onActivate;
|
||||
final String label;
|
||||
final String paneId;
|
||||
final double? contentHeight;
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final height = constraints.maxHeight;
|
||||
return ClipRect(
|
||||
State<ChatMobilePaneViewport> createState() => _ChatMobilePaneViewportState();
|
||||
}
|
||||
|
||||
class _ChatMobilePaneViewportState extends State<ChatMobilePaneViewport>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _reveal = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 120),
|
||||
value: 1,
|
||||
);
|
||||
late final Animation<double> _opacity = Tween(
|
||||
begin: .75,
|
||||
end: 1.0,
|
||||
).animate(CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic));
|
||||
late final Animation<Offset> _slide = Tween(
|
||||
begin: const Offset(0, .005),
|
||||
end: Offset.zero,
|
||||
).animate(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() {
|
||||
_reveal.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ClipRect(
|
||||
child: FadeTransition(
|
||||
key: ValueKey('chat-reveal-${widget.paneId}'),
|
||||
opacity: _opacity,
|
||||
child: SlideTransition(
|
||||
position: _slide,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
OverflowBox(
|
||||
alignment: Alignment.topCenter,
|
||||
minHeight: height,
|
||||
maxHeight: peek ? math.max(height, 300) : height,
|
||||
minHeight: widget.contentHeight,
|
||||
maxHeight: widget.contentHeight,
|
||||
child: SizedBox(
|
||||
height: peek ? math.max(height, 300) : height,
|
||||
height: widget.contentHeight,
|
||||
child: ExcludeFocus(
|
||||
excluding: peek,
|
||||
excluding: widget.peek,
|
||||
child: ExcludeSemantics(
|
||||
excluding: peek,
|
||||
child: IgnorePointer(ignoring: peek, child: child),
|
||||
excluding: widget.peek,
|
||||
child: IgnorePointer(
|
||||
ignoring: widget.peek,
|
||||
child: RepaintBoundary(child: widget.child),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (peek)
|
||||
if (widget.peek)
|
||||
Semantics(
|
||||
key: ValueKey('chat-peek-$paneId'),
|
||||
identifier: 'chat-peek-$paneId',
|
||||
key: ValueKey('chat-peek-${widget.paneId}'),
|
||||
identifier: 'chat-peek-${widget.paneId}',
|
||||
container: true,
|
||||
label: 'Expand $label',
|
||||
sortKey: const OrdinalSortKey(1),
|
||||
label: 'Expand ${widget.label}',
|
||||
button: true,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onActivate,
|
||||
onTap: widget.onActivate,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -135,10 +136,6 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
size: constraints.biggest,
|
||||
)
|
||||
: null;
|
||||
final duration =
|
||||
mobile != null && !MediaQuery.disableAnimationsOf(context)
|
||||
? const Duration(milliseconds: 220)
|
||||
: Duration.zero;
|
||||
final existing = panes.map((p) => p.id).toSet();
|
||||
for (final id
|
||||
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
|
||||
@@ -150,9 +147,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
for (final pane in panes)
|
||||
AnimatedPositioned.fromRect(
|
||||
duration: duration,
|
||||
curve: Curves.easeInOutCubic,
|
||||
Positioned.fromRect(
|
||||
key: ValueKey('chat-workspace-${pane.id}'),
|
||||
rect:
|
||||
mobile?.rects[pane.id] ??
|
||||
@@ -170,6 +165,11 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
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: () {
|
||||
@@ -193,6 +193,9 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
child: Semantics(
|
||||
identifier: 'chat-pane-${pane.id}',
|
||||
container: true,
|
||||
sortKey: mobile == null
|
||||
? null
|
||||
: const OrdinalSortKey(0),
|
||||
child: widget.paneBuilder(
|
||||
context,
|
||||
pane,
|
||||
|
||||
Reference in New Issue
Block a user