Files
buzz/mobile/lib/shared/widgets/duo_toolbar.dart
Stephen Barnes 7681371b94 fix(mobile): clear the Duo top edge in the Activity header (#9807)
## Summary

On iPhone Duo, the Activity page's custom header put Close and the
"Activity" title 8 points below the window's top edge. The Duo panes
report no top safe area beside the strip, so the 8-point row padding was
the only clearance. This happened on the cover display and in the inner
display's wide layout.

Other Duo pane headers already reserve 24 points above their 44-point
controls (`FrostedAppBar` and the native bar in
`IosNavigationBar.swift`). Activity now does the same:

- `activity_page.dart`: on iOS with a Duo strip, the header row's top
padding is `duoHeaderTopClearance` (24). Otherwise it stays `Grid.xxs`
(8). The bottom padding stays 8.
- `duo_toolbar.dart`: adds `duoHeaderTopClearance = 24`.
- `frosted_app_bar.dart`: uses the constant in place of its literal `+
24`. No value change.

**Pareto:** better on the Duo cover and in the wide layout. No change on
regular iPhones (no strip), Android, or the Duo inner display in
portrait (no side strip; it already has an 82-point top inset). No new
rebuild dependencies: `strip` was already read through
`DuoToolbarScope.maybeStripOf`.

### Related issue

None found.

### Testing

- New widget test `Activity header clears the top edge on …` checks the
header row's top edge on the Duo cover (466×678, right strip), the Duo
wide layout (951×669), an iPhone (62-point top inset), and Android. It
fails on `main` for both Duo cases (8, expected 24) and passes with this
change.
- `dart format --set-exit-if-changed .` and `flutter analyze`: clean.
- `flutter test` (mobile): passes on macOS.
- iOS 27.2 simulators, measured in points from the top edge:

| Device / layout | Before | After |
|---|---|---|
| Duo cover, Close and title row | 8 | 24 |
| Duo wide layout, title row (Close in the rail) | 8 | 24 |
| iPhone 18 Pro | 70 | 70 |

#### Before / after

Captured on iOS 27.2 simulators. Before is `main` at `9c0bcd6239`, after
is this branch at `4400d021b`. In each pair, before is on the left and
after is on the right.

Duo cover display: open Activity from the bell, hold, then Close.


https://github.com/user-attachments/assets/5bda190c-cadf-44a8-9a8e-58bc68838e7b

![Duo cover display, before and after: Close and title move from 8 to 24
points below the top
edge](https://github.com/user-attachments/assets/30b34987-0477-4cae-8a42-3b451fa00d06)

![Duo inner display, wide layout, before and after: the Activity title
row moves from 8 to 24 points; Close stays in the
rail](https://github.com/user-attachments/assets/1f4690cf-9cf5-47e8-afd2-7554c5f27351)

![Duo inner display, portrait (unfolded), before and after: no change;
Close at 19 points under the measured header from
#9795](https://github.com/user-attachments/assets/ac6465a9-0855-4842-b9e7-d790cdb467e5)

![iPhone 18 Pro, before and after: no
change](https://github.com/user-attachments/assets/a9674077-99fe-47a8-b432-ccd07cfe390c)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Stephen Barnes <799470+smbarne@users.noreply.github.com>
Co-authored-by: Stephen Barnes <799470+smbarne@users.noreply.github.com>
2026-11-20 14:20:38 -05:00

203 lines
6.8 KiB
Dart

import 'package:duo_kit/duo_kit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'ios_navigation_bar.dart';
/// Rail top clearance on Duo's inner display until UIKit reports its regions.
/// The package estimate describes the cover display's taller status cluster.
const double duoInnerDisplayEstimatedRailClearance = 110;
/// Space above the 44-point controls of an iOS pane header on Duo.
///
/// Duo panes report no top safe area, so headers reserve this room below the
/// window's top edge. The native bar in `IosNavigationBar.swift` uses the same
/// value.
const double duoHeaderTopClearance = 24;
/// Whether Duo controls should use the compact cover arrangement.
bool isCompactDuoWindow(BuildContext context) {
// Subscribe to resizing even inside a pane whose MediaQuery is narrower.
MediaQuery.sizeOf(context);
final view = View.of(context);
return (view.physicalSize / view.devicePixelRatio).shortestSide < 600;
}
/// Carries window geometry through the independently sized conversation panes.
class DuoToolbarScope extends InheritedModel<Object> {
const DuoToolbarScope({
required this.strip,
required this.active,
this.contentInsets = EdgeInsets.zero,
this.leadingSlots = 0,
required super.child,
super.key,
});
final FoldStrip? strip;
final bool active;
final EdgeInsets contentInsets;
/// Space above detail actions for the workspace's persistent rail controls.
final int leadingSlots;
static const Object _stripAspect = #strip;
static DuoToolbarScope? maybeOf(BuildContext context) =>
InheritedModel.inheritFrom<DuoToolbarScope>(context);
/// The enclosing pane's [strip], depending on nothing else.
///
/// [active] flips whenever a route covers the pane, so geometry readers
/// such as headers and page lists use this to avoid rebuilding with it.
static FoldStrip? maybeStripOf(BuildContext context) =>
InheritedModel.inheritFrom<DuoToolbarScope>(
context,
aspect: _stripAspect,
)?.strip;
@override
bool updateShouldNotify(DuoToolbarScope oldWidget) =>
strip != oldWidget.strip ||
active != oldWidget.active ||
contentInsets != oldWidget.contentInsets ||
leadingSlots != oldWidget.leadingSlots;
@override
bool updateShouldNotifyDependent(
DuoToolbarScope oldWidget,
Set<Object> dependencies,
) => strip != oldWidget.strip;
}
/// Content clearance for a pane, or a full-window route outside a pane.
EdgeInsets duoContentInsetsOf(BuildContext context) {
final pane = DuoToolbarScope.maybeOf(context);
if (pane != null) return pane.contentInsets;
final strip = FoldGeometry.of(context).strip;
return EdgeInsets.only(
left: strip?.side == FoldStripSide.left ? strip!.width : 0,
right: strip?.side == FoldStripSide.right ? strip!.width : 0,
);
}
/// Projects the current route's controls into the window's side strip.
/// The portal retains route ownership and inherited providers for callbacks.
class DuoToolbarPortal extends HookConsumerWidget {
const DuoToolbarPortal({
required this.strip,
required this.active,
required this.actions,
required this.child,
super.key,
});
final FoldStrip? strip;
final bool active;
final List<IosNavigationAction> actions;
final Widget child;
@override
Widget build(BuildContext context, WidgetRef ref) {
final portal = useMemoized(() => OverlayPortalController()..show());
return OverlayPortal(
overlayLocation: OverlayChildLocation.rootOverlay,
controller: portal,
overlayChildBuilder: (context) {
final strip = this.strip;
if (strip == null || actions.isEmpty) {
return const SizedBox.shrink();
}
final windowSize =
View.of(context).physicalSize / View.of(context).devicePixelRatio;
// The package fallback describes the cover display. The inner display's
// status cluster is shorter; keep this estimated until regions arrive.
final metrics = IosNavigationMetrics.of(context);
final measuredTop = metrics.windowSize == windowSize
? metrics.railTopClearance
: null;
final actionOffset =
(DuoToolbarScope.maybeOf(context)?.leadingSlots ?? 0) * 60.0;
final topClearance =
(measuredTop != null
? measuredTop + 12
: strip.isClearanceEstimated && windowSize.shortestSide >= 600
? duoInnerDisplayEstimatedRailClearance
: strip.topClearance) +
actionOffset;
return Positioned(
left:
IosNavigationMetrics.of(context).railCenter(
View.of(context).physicalSize /
View.of(context).devicePixelRatio,
strip.rect.center.dx,
) -
strip.width / 2,
top: strip.rect.top + topClearance,
width: strip.width,
child: Offstage(
offstage: !active,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
removeLeft: true,
removeRight: true,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight:
(strip.rect.height -
topClearance -
strip.bottomClearance -
220)
.clamp(0.0, double.infinity),
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final action in actions)
SizedBox(
key: ValueKey('duo-toolbar-${action.label}'),
height: 60,
child: IosNavigationBar(
title: '',
standaloneControl: true,
leading: action,
),
),
],
),
),
),
),
),
);
},
child: child,
);
}
}
/// Marks sheets whose default Close action is supplied by the Duo rail.
class DuoSheetCloseScope extends InheritedWidget {
const DuoSheetCloseScope({
required this.inRail,
required super.child,
super.key,
});
final bool inRail;
static bool of(BuildContext context) =>
context
.dependOnInheritedWidgetOfExactType<DuoSheetCloseScope>()
?.inRail ??
false;
@override
bool updateShouldNotify(DuoSheetCloseScope oldWidget) =>
inRail != oldWidget.inRail;
}