104 lines
3.1 KiB
Dart
104 lines
3.1 KiB
Dart
import 'dart:math' as math;
|
|
import 'package:flutter/widgets.dart';
|
|
import 'chat_workspace_controller.dart';
|
|
|
|
/// A phone presentation only: saved split axes and ratios are left untouched.
|
|
class ChatMobilePanes {
|
|
ChatMobilePanes({
|
|
required List<ChatWorkspacePane> panes,
|
|
required String activeId,
|
|
required String? peekId,
|
|
required Size size,
|
|
}) {
|
|
final active = panes.firstWhere((pane) => pane.id == activeId);
|
|
final peek =
|
|
panes
|
|
.where((pane) => pane.id == peekId && pane.id != activeId)
|
|
.firstOrNull ??
|
|
panes.where((pane) => pane.id != activeId).firstOrNull;
|
|
if (peek == null) {
|
|
rects[active.id] = Offset.zero & size;
|
|
return;
|
|
}
|
|
this.peekId = peek.id;
|
|
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,
|
|
0,
|
|
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,
|
|
);
|
|
}
|
|
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 {
|
|
const ChatMobilePaneViewport({
|
|
super.key,
|
|
required this.peek,
|
|
required this.child,
|
|
required this.onActivate,
|
|
required this.label,
|
|
required this.paneId,
|
|
});
|
|
final bool peek;
|
|
final Widget child;
|
|
final VoidCallback onActivate;
|
|
final String label;
|
|
final String paneId;
|
|
@override
|
|
Widget build(BuildContext context) => LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final height = constraints.maxHeight;
|
|
return ClipRect(
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
OverflowBox(
|
|
alignment: Alignment.topCenter,
|
|
minHeight: height,
|
|
maxHeight: peek ? math.max(height, 300) : height,
|
|
child: SizedBox(
|
|
height: peek ? math.max(height, 300) : height,
|
|
child: ExcludeFocus(
|
|
excluding: peek,
|
|
child: ExcludeSemantics(
|
|
excluding: peek,
|
|
child: IgnorePointer(ignoring: peek, child: child),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (peek)
|
|
Semantics(
|
|
key: ValueKey('chat-peek-$paneId'),
|
|
identifier: 'chat-peek-$paneId',
|
|
container: true,
|
|
label: 'Expand $label',
|
|
button: true,
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: onActivate,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|