91 lines
3.4 KiB
Dart
91 lines
3.4 KiB
Dart
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,
|
|
this.fixedChromeLayout = false,
|
|
required super.child,
|
|
});
|
|
|
|
final bool peek;
|
|
final bool fixedChromeLayout;
|
|
final Animation<double> barReveal;
|
|
|
|
static ChatPanePresentation? maybeOf(BuildContext context) =>
|
|
context.dependOnInheritedWidgetOfExactType<ChatPanePresentation>();
|
|
|
|
@override
|
|
bool updateShouldNotify(ChatPanePresentation oldWidget) =>
|
|
peek != oldWidget.peek ||
|
|
barReveal != oldWidget.barReveal ||
|
|
fixedChromeLayout != oldWidget.fixedChromeLayout;
|
|
}
|
|
|
|
/// The conversation's bar under a [ChatPanePresentation].
|
|
///
|
|
/// Both header and composer use the same retained tree. Opacity, slide and
|
|
/// occupied height follow the pane's reveal together, so the peek has no
|
|
/// controls or reserved chrome space. Repaint boundaries retain each bar's
|
|
/// picture; changing the real viewport height still requires transcript layout.
|
|
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.
|
|
// Overlay slots cap chrome at the pane height. A resting peek can be
|
|
// shorter than its retained composer (large text + keyboard). Give only
|
|
// chrome its natural height before SizeTransition consumes that height;
|
|
// the transcript itself always keeps the real pane constraints.
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
AnimatedBuilder(
|
|
animation: reveal,
|
|
child: IgnorePointer(
|
|
ignoring: peek,
|
|
child: SizeTransition(
|
|
alignment: Alignment.topCenter,
|
|
sizeFactor: presentation.fixedChromeLayout
|
|
? const AlwaysStoppedAnimation(1.0)
|
|
: reveal,
|
|
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),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|