mirror of
https://github.com/block/buzz.git
synced 2026-11-25 18:52:52 +00:00
Rebuilding an unchanged message footer currently schedules another layout even when its overlap value is identical. Only invalidate footer layout when that value changes, preserving layout updates for actual geometry changes. ### Stable release recommendation Exclude from `mobile-release/conference-2026-10`; defer to the following release. The regression test demonstrates eliminated redundant layout, but the effect on navigation latency has not been quantified. ### Validation The added widget regression checks that unchanged footer rebuilds do not repeat layout and changed overlap still updates geometry. The independent footer build passes the full mobile suite, analysis, and native iOS Simulator build. Channel scrolling, opening an existing reaction list, and thread navigation were exercised on iOS 26.5 Simulator. The full local repository gate previously encountered an unrelated, unchanged desktop subprocess timing test failure; that test passed in isolation. All PR CI checks pass, including the native iOS suite. <!-- buzz-review-completed --> Signed-off-by: Tom Brow <tomb@block.xyz>
133 lines
3.7 KiB
Dart
133 lines
3.7 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Places reactions at the bottom edge of a message.
|
|
/// Both children remain inside the hit-test bounds, including overlapping badges.
|
|
class MessageFooterLayout extends StatelessWidget {
|
|
/// Creates a message with overlapping reaction controls.
|
|
const MessageFooterLayout({
|
|
super.key,
|
|
required this.child,
|
|
required this.footer,
|
|
this.overlap = 0,
|
|
this.animateSize = false,
|
|
});
|
|
|
|
/// Main message content.
|
|
final Widget child;
|
|
|
|
/// Controls attached to the bottom of the message.
|
|
final Widget footer;
|
|
|
|
/// Vertical distance shared by the message and its controls.
|
|
final double overlap;
|
|
|
|
/// Smoothly adjusts the space occupied by added or removed reactions.
|
|
final bool animateSize;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final layout = _FooterLayout(overlap: overlap, children: [child, footer]);
|
|
if (!animateSize || MediaQuery.disableAnimationsOf(context)) return layout;
|
|
return AnimatedSize(
|
|
duration: const Duration(milliseconds: 200),
|
|
curve: Curves.easeInOutCubic,
|
|
alignment: Alignment.topLeft,
|
|
clipBehavior: Clip.none,
|
|
child: layout,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _FooterLayout extends MultiChildRenderObjectWidget {
|
|
const _FooterLayout({required this.overlap, required super.children});
|
|
final double overlap;
|
|
|
|
@override
|
|
RenderObject createRenderObject(BuildContext context) =>
|
|
_RenderMessageFooter(overlap);
|
|
|
|
@override
|
|
void updateRenderObject(
|
|
BuildContext context,
|
|
covariant RenderBox renderObject,
|
|
) {
|
|
(renderObject as _RenderMessageFooter).overlap = overlap;
|
|
}
|
|
}
|
|
|
|
class _RenderMessageFooter extends RenderBox
|
|
with
|
|
ContainerRenderObjectMixin<
|
|
RenderBox,
|
|
ContainerBoxParentData<RenderBox>
|
|
>,
|
|
RenderBoxContainerDefaultsMixin<
|
|
RenderBox,
|
|
ContainerBoxParentData<RenderBox>
|
|
> {
|
|
_RenderMessageFooter(this._overlap);
|
|
|
|
double _overlap;
|
|
double get overlap => _overlap;
|
|
set overlap(double value) {
|
|
if (_overlap == value) return;
|
|
_overlap = value;
|
|
markNeedsLayout();
|
|
}
|
|
|
|
@override
|
|
void setupParentData(RenderBox child) {
|
|
if (child.parentData is! ContainerBoxParentData<RenderBox>) {
|
|
child.parentData = _FooterParentData();
|
|
}
|
|
}
|
|
|
|
Size _layout(BoxConstraints constraints, {required bool dry}) {
|
|
final content = firstChild!;
|
|
final footer = lastChild!;
|
|
final loose = constraints.loosen();
|
|
Size measure(RenderBox child) {
|
|
if (dry) return child.getDryLayout(loose);
|
|
child.layout(loose, parentUsesSize: true);
|
|
return child.size;
|
|
}
|
|
|
|
final contentSize = measure(content);
|
|
final footerSize = measure(footer);
|
|
final width = math.max(contentSize.width, footerSize.width);
|
|
final footerOffset = Offset(0, math.max(0, contentSize.height - overlap));
|
|
if (!dry) {
|
|
(content.parentData! as ContainerBoxParentData<RenderBox>).offset =
|
|
Offset.zero;
|
|
(footer.parentData! as ContainerBoxParentData<RenderBox>).offset =
|
|
footerOffset;
|
|
}
|
|
return constraints.constrain(
|
|
Size(
|
|
width,
|
|
math.max(contentSize.height, footerOffset.dy + footerSize.height),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Size computeDryLayout(BoxConstraints constraints) =>
|
|
_layout(constraints, dry: true);
|
|
|
|
@override
|
|
void performLayout() => size = _layout(constraints, dry: false);
|
|
|
|
@override
|
|
void paint(PaintingContext context, Offset offset) =>
|
|
defaultPaint(context, offset);
|
|
|
|
@override
|
|
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) =>
|
|
defaultHitTestChildren(result, position: position);
|
|
}
|
|
|
|
class _FooterParentData extends ContainerBoxParentData<RenderBox> {}
|