mirror of
https://github.com/block/buzz.git
synced 2026-11-27 19:52:31 +00:00
## Summary - Organize mobile Messages into configurable flat sections. See All keeps the list and its search position when opening a conversation, and supports side-by-side browsing on an unfolded Duo. - Use the same 16-point Messages gutter in booklet and open Duo layouts. The regular iPhone uses 20 points. Align navigation actions and use native inline titles on See All. - Update mobile typography and spacing across chat rows, message bubbles, drafts, and the composer. Render code proportionally to the 17-point message body. ## Device review Compare the leading edges of the section headings and channel icons in Messages on the open Duo and in booklet mode. Open See All and check that its rows follow the same column. --------- Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
935 lines
34 KiB
Dart
935 lines
34 KiB
Dart
import 'adaptive_conversation_pane.dart';
|
|
import 'bottom_up_page_route.dart';
|
|
import 'package:duo_kit/duo_kit.dart';
|
|
|
|
import 'duo_toolbar.dart';
|
|
|
|
import 'dart:math' show max;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart' show CupertinoTheme;
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:buzz/shared/theme/buzz_icons.dart';
|
|
|
|
import '../theme/theme.dart';
|
|
import 'buzz_navigation_metrics.dart';
|
|
import 'directional_transition_scope.dart';
|
|
import 'frosted_scroll_under_scope.dart';
|
|
import 'ios_glass_navigation_button.dart';
|
|
import 'ios_glass_navigation_action.dart';
|
|
import 'ios_navigation_bar.dart';
|
|
import 'navigation_backdrop.dart';
|
|
export 'ios_navigation_bar.dart' show IosNavigationAction;
|
|
|
|
/// Space below the Android conversation toolbar controls.
|
|
double conversationNavigationBottomPadding(BuildContext context) =>
|
|
Theme.of(context).platform == TargetPlatform.android ? Grid.xxs : 0;
|
|
|
|
/// Round Material action containers shared by Android navigation headers.
|
|
ButtonStyle androidNavigationButtonStyle(BuildContext context) =>
|
|
IconButton.styleFrom(
|
|
backgroundColor: context.colors.surfaceContainerHighest,
|
|
foregroundColor: context.colors.onSurface,
|
|
shape: const CircleBorder(),
|
|
minimumSize: const Size.square(48),
|
|
);
|
|
|
|
/// Minimum height of the frosted app bar content area below the safe area.
|
|
const _kBarContentMinHeight = buzzNavigationRowHeight;
|
|
|
|
TextStyle _effectiveTitleStyle(BuildContext context, TextStyle? titleStyle) {
|
|
final baseStyle =
|
|
context.textTheme.titleSmall ??
|
|
const TextStyle(fontSize: 16, height: 1.4);
|
|
return baseStyle.copyWith(fontWeight: FontWeight.w600).merge(titleStyle);
|
|
}
|
|
|
|
double _barContentHeight(
|
|
BuildContext context,
|
|
TextStyle? titleStyle,
|
|
double titleContentHeight,
|
|
) {
|
|
final style = _effectiveTitleStyle(context, titleStyle);
|
|
final scaledFontSize = MediaQuery.textScalerOf(
|
|
context,
|
|
).scale(style.fontSize ?? 16);
|
|
final scaledTitleHeight = scaledFontSize * (style.height ?? 1);
|
|
final effectiveTitleHeight = titleContentHeight > scaledTitleHeight
|
|
? titleContentHeight
|
|
: scaledTitleHeight;
|
|
final accessibleHeight = Grid.xxs + effectiveTitleHeight + Grid.xxs;
|
|
final strip =
|
|
DuoToolbarScope.maybeStripOf(context) ?? FoldGeometry.of(context).strip;
|
|
final minimumHeight =
|
|
defaultTargetPlatform == TargetPlatform.iOS &&
|
|
strip != null &&
|
|
!isCompactDuoWindow(context)
|
|
? _nativeCompactHeight(context)
|
|
: _kBarContentMinHeight;
|
|
return accessibleHeight > minimumHeight ? accessibleHeight : minimumHeight;
|
|
}
|
|
|
|
/// Height for a compact title rail below the app bar's action row.
|
|
///
|
|
/// The rail normally stays at 40dp, but grows with an accessible title rather
|
|
/// than clipping text at larger system text sizes.
|
|
double frostedAppBarLowerTitleHeight(
|
|
BuildContext context, {
|
|
TextStyle? titleStyle,
|
|
}) {
|
|
final style = _effectiveTitleStyle(context, titleStyle);
|
|
final scaledFontSize = MediaQuery.textScalerOf(
|
|
context,
|
|
).scale(style.fontSize ?? 16);
|
|
final titleHeight = scaledFontSize * (style.height ?? 1);
|
|
return titleHeight > 40 ? titleHeight : 40;
|
|
}
|
|
|
|
// Duo has no top status inset in the content panes. Reserve breathing room
|
|
// around the native 44-point controls instead of collapsing the header to them.
|
|
double _nativeCompactHeight(BuildContext context, [double titleHeight = 0]) {
|
|
final strip = context.getInheritedWidgetOfExactType<DuoToolbarScope>() == null
|
|
? FoldGeometry.of(context).strip
|
|
: DuoToolbarScope.maybeStripOf(context);
|
|
final height = IosNavigationMetrics.of(context).compactHeight;
|
|
return strip == null
|
|
? max(height, titleHeight)
|
|
: max(height.clamp(44.0, double.infinity), titleHeight) +
|
|
duoHeaderTopClearance;
|
|
}
|
|
|
|
/// Returns the total height of the [FrostedAppBar] including safe area padding.
|
|
///
|
|
/// Use this to add top spacing to body content so it starts below the bar.
|
|
/// Pass the same [titleStyle] and [titleContentHeight] to the bar and this
|
|
/// helper when customizing them.
|
|
double frostedAppBarHeight(
|
|
BuildContext context, {
|
|
double bottomHeight = 0,
|
|
TextStyle? titleStyle,
|
|
double titleContentHeight = 0,
|
|
bool nativeLargeTitle = false,
|
|
bool useNativeNavigation = true,
|
|
bool alignWithStatusRegion = false,
|
|
}) {
|
|
final portraitHeader =
|
|
alignWithStatusRegion && defaultTargetPlatform == TargetPlatform.iOS
|
|
? IosNavigationMetrics.of(context).portraitHeaderFor(
|
|
View.of(context).physicalSize / View.of(context).devicePixelRatio,
|
|
)
|
|
: null;
|
|
if (portraitHeader != null && useNativeNavigation && !nativeLargeTitle) {
|
|
return max(MediaQuery.paddingOf(context).top, portraitHeader.bottom) +
|
|
bottomHeight;
|
|
}
|
|
if (portraitHeader != null) {
|
|
return portraitHeader.top +
|
|
_barContentHeight(context, titleStyle, titleContentHeight) +
|
|
bottomHeight;
|
|
}
|
|
if (useNativeNavigation && defaultTargetPlatform == TargetPlatform.iOS) {
|
|
return MediaQuery.paddingOf(context).top +
|
|
_nativeCompactHeight(context, titleContentHeight) +
|
|
(nativeLargeTitle
|
|
? IosNavigationMetrics.of(context).largeTitleHeight
|
|
: 0) +
|
|
bottomHeight;
|
|
}
|
|
return MediaQuery.paddingOf(context).top +
|
|
_barContentHeight(context, titleStyle, titleContentHeight) +
|
|
bottomHeight;
|
|
}
|
|
|
|
/// A frosted-glass floating app bar designed to sit inside a [Stack].
|
|
///
|
|
/// Renders as a [Positioned] widget pinned to the top of its parent Stack.
|
|
/// Content scrolls underneath with a translucent backdrop blur effect.
|
|
class FrostedAppBar extends StatelessWidget {
|
|
/// Widget displayed on the leading (left) side. If null and the navigator
|
|
/// can pop, a back button is shown automatically.
|
|
final Widget? leading;
|
|
|
|
/// Whether to infer a back button from the current navigator.
|
|
final bool automaticallyImplyLeading;
|
|
|
|
/// Widget displayed in the center/title area.
|
|
final Widget? title;
|
|
|
|
/// Whether [title] is centered in the full bar rather than flowing after the
|
|
/// leading control. Page titles should keep the default; identity-style
|
|
/// headers can opt out.
|
|
final bool centerTitle;
|
|
|
|
/// Optional style merged over the default title style.
|
|
final TextStyle? titleStyle;
|
|
|
|
/// Scaled height needed by a custom title with multiple text lines.
|
|
///
|
|
/// Pass the same value to [frostedAppBarHeight] when spacing body content.
|
|
final double titleContentHeight;
|
|
|
|
/// Scroll-driven title drawn over the toolbar and its bottom extension.
|
|
final Widget Function(double toolbarHeight)? titleOverlay;
|
|
|
|
/// Optional content displayed below the title row in the same surface.
|
|
final Widget? bottom;
|
|
|
|
/// Height reserved for [bottom].
|
|
final double bottomHeight;
|
|
|
|
/// Widgets displayed on the trailing (right) side.
|
|
final List<Widget> actions;
|
|
|
|
/// Horizontal inset for the app bar's leading, title, and actions.
|
|
final double horizontalInset;
|
|
|
|
/// Color applied to icons in the app bar.
|
|
final Color? iconColor;
|
|
|
|
/// Whether to apply the translucent blur treatment behind the app bar.
|
|
///
|
|
/// The backdrop stays clear at rest. This enables the treatment when the
|
|
/// surrounding scroll scope reports content beneath the controls.
|
|
final bool frosted;
|
|
|
|
/// Keeps the backdrop stable regardless of scroll state on both platforms.
|
|
/// Conversation headers use this while their timeline and composer resize.
|
|
final bool alwaysFrosted;
|
|
|
|
/// Explicit UIKit title for headers whose Flutter title is a custom widget.
|
|
final String? nativeTitle;
|
|
|
|
/// Optional second line and action for a native channel title.
|
|
final String? nativeSubtitle;
|
|
|
|
/// Existing retention disclosure displayed by the native conversation title.
|
|
final String? nativeEphemeralLabel;
|
|
|
|
/// Reactive counterpart avatar and presence badge for a native DM title.
|
|
final IosNavigationAction? nativeTitleAvatar;
|
|
|
|
/// Portraits floating above a DM title; empty for ordinary channel headers.
|
|
final List<IosNavigationAction> nativeTitleAvatars;
|
|
final double? nativeTitleMaxWidth;
|
|
final Color? nativeTitlePresenceColor;
|
|
|
|
/// Shows a refresh bar in the native iOS title capsule.
|
|
final bool nativeTitleRefreshing;
|
|
final VoidCallback? onNativeTitlePressed;
|
|
|
|
/// Whether UIKit should expand the title at the top of the page.
|
|
final bool nativeLargeTitle;
|
|
|
|
/// Keeps custom Home controls beside the system navigation title.
|
|
final bool nativeLargeTitleWithActions;
|
|
final bool alignLargeTitleWithActions;
|
|
final bool centerLargeTitleBelowActions;
|
|
final bool nativePaneSoftEdge;
|
|
final bool leadingInlineTitleOnDuo;
|
|
|
|
/// Aligns a full-width native backdrop title with the inset page content.
|
|
final EdgeInsets nativeTitleInsets;
|
|
|
|
/// Whether UIKit owns the title and actions. Custom Flutter layouts still
|
|
/// use the native soft backdrop on iOS.
|
|
final bool useNativeNavigation;
|
|
|
|
/// Places the header beside the unfolded portrait status cluster.
|
|
final bool alignWithStatusRegion;
|
|
|
|
/// Duration for coordinated native header and overlapping control movement.
|
|
final Duration nativeLayoutDuration;
|
|
|
|
/// Native replacement for a custom leading widget.
|
|
final IosNavigationAction? nativeLeading;
|
|
|
|
/// Native replacements for composite Flutter actions, including menus.
|
|
final List<IosNavigationAction>? nativeActions;
|
|
|
|
/// Reports when native header images and layout are ready to reveal.
|
|
final ValueChanged<bool>? onNativeReadyChanged;
|
|
|
|
/// Uses a composable Flutter header while a backdrop covers the native view.
|
|
final ValueListenable<bool>? nativeViewSuppressed;
|
|
|
|
/// Projects controls into Duo's rail without a header over the content.
|
|
final bool railOnly;
|
|
|
|
const FrostedAppBar({
|
|
super.key,
|
|
this.nativeTitle,
|
|
this.nativeSubtitle,
|
|
this.nativeEphemeralLabel,
|
|
this.nativeTitleAvatar,
|
|
this.nativeTitleAvatars = const [],
|
|
this.nativeTitleMaxWidth,
|
|
this.nativeTitlePresenceColor,
|
|
this.nativeTitleRefreshing = false,
|
|
this.onNativeTitlePressed,
|
|
this.nativeLargeTitle = false,
|
|
this.nativeLargeTitleWithActions = false,
|
|
this.alignLargeTitleWithActions = false,
|
|
this.centerLargeTitleBelowActions = false,
|
|
this.nativePaneSoftEdge = false,
|
|
this.leadingInlineTitleOnDuo = false,
|
|
this.nativeTitleInsets = EdgeInsets.zero,
|
|
this.useNativeNavigation = true,
|
|
this.alignWithStatusRegion = false,
|
|
this.nativeLayoutDuration = Duration.zero,
|
|
this.nativeLeading,
|
|
this.nativeActions,
|
|
this.onNativeReadyChanged,
|
|
this.nativeViewSuppressed,
|
|
this.railOnly = false,
|
|
this.leading,
|
|
this.automaticallyImplyLeading = true,
|
|
this.title,
|
|
this.centerTitle = false,
|
|
this.titleStyle,
|
|
this.titleContentHeight = 0,
|
|
this.titleOverlay,
|
|
this.bottom,
|
|
this.bottomHeight = 0,
|
|
this.actions = const [],
|
|
this.horizontalInset = Grid.xxs,
|
|
this.iconColor,
|
|
this.frosted = true,
|
|
this.alwaysFrosted = false,
|
|
}) : assert(bottom == null || bottomHeight > 0);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final suppression = nativeViewSuppressed;
|
|
if (defaultTargetPlatform == TargetPlatform.iOS && suppression != null) {
|
|
return ValueListenableBuilder<bool>(
|
|
valueListenable: suppression,
|
|
builder: (context, suppressed, _) => _build(context, suppressed),
|
|
);
|
|
}
|
|
return _build(context, false);
|
|
}
|
|
|
|
Widget _build(BuildContext context, bool nativeSuppressed) {
|
|
final railInsets = duoContentInsetsOf(context);
|
|
if (useNativeNavigation &&
|
|
defaultTargetPlatform == TargetPlatform.iOS &&
|
|
!nativeSuppressed) {
|
|
if (ConversationPaneScope.isReplacedBaseRouteOf(context)) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
final toolbarScope = DuoToolbarScope.maybeOf(context);
|
|
final strip = toolbarScope == null
|
|
? FoldGeometry.of(context).strip
|
|
: toolbarScope.strip;
|
|
final leadingAction = nativeLeading ?? _nativeAction(leading);
|
|
final onBack =
|
|
automaticallyImplyLeading &&
|
|
leading == null &&
|
|
Navigator.canPop(context)
|
|
? () {
|
|
Navigator.of(context).maybePop();
|
|
}
|
|
: null;
|
|
final trailingActions =
|
|
nativeActions ??
|
|
actions.map(_nativeAction).whereType<IosNavigationAction>().toList();
|
|
final stripActions = <IosNavigationAction>[
|
|
if (leadingAction != null && !leadingAction.keepInHeaderOnDuo)
|
|
leadingAction
|
|
else if (leadingAction == null && onBack != null)
|
|
IosNavigationAction(
|
|
label: 'Back',
|
|
symbol: 'chevron.backward',
|
|
onPressed: onBack,
|
|
),
|
|
...trailingActions.where((action) => !action.keepInHeaderOnDuo),
|
|
];
|
|
final toolbarActive =
|
|
(toolbarScope?.active ?? true) &&
|
|
((ModalRoute.isCurrentOf(context) ?? true) ||
|
|
BottomUpPageRoute.hasRetainedControls(ModalRoute.of(context)));
|
|
if (railOnly && strip != null) {
|
|
return Positioned(
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
child: DuoToolbarPortal(
|
|
strip: strip,
|
|
active: toolbarActive,
|
|
actions: stripActions,
|
|
child: NavigationBackdrop(
|
|
child: SizedBox(height: MediaQuery.paddingOf(context).top),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
final offset = IosNavigationScrollScope.maybeOf(context);
|
|
// The bar reads the scroll offset itself, so scrolling rebuilds only
|
|
// the frame around it, not its native payload.
|
|
final centerExpandedTitle = centerLargeTitleBelowActions && strip == null;
|
|
var actionsTop =
|
|
MediaQuery.paddingOf(context).top +
|
|
(_barContentHeight(context, titleStyle, titleContentHeight) - 44) / 2;
|
|
final window = View.of(context);
|
|
if (nativeLargeTitleWithActions &&
|
|
strip != null &&
|
|
isCompactDuoWindow(context) &&
|
|
window.physicalSize.height > window.physicalSize.width) {
|
|
// duo_kit's portrait cover camera is 37pt wide, inset 29.3pt.
|
|
// Some OS versions report only the status strip, without its camera.
|
|
final camera = FoldGeometry.of(context).occlusions
|
|
.where(
|
|
(rect) =>
|
|
strip.rect.overlaps(rect) &&
|
|
rect.width > 0 &&
|
|
(rect.width - rect.height).abs() < 1 &&
|
|
rect.center.dy < 100,
|
|
)
|
|
.firstOrNull;
|
|
actionsTop = (camera?.center.dy ?? 47.8) - 22;
|
|
}
|
|
final nativeBar = IosNavigationBar(
|
|
externalExpandedTitle: centerExpandedTitle,
|
|
key: ConversationPaneScope.nativeHeaderKeyOf(context),
|
|
centerTitleInPane: strip != null && !nativeLargeTitle,
|
|
titleInsets: nativeTitleInsets == EdgeInsets.zero
|
|
? railInsets
|
|
: nativeTitleInsets,
|
|
alignCollapsedTitleToLeading:
|
|
strip != null &&
|
|
(leadingInlineTitleOnDuo ||
|
|
(nativeLargeTitle &&
|
|
(!nativeLargeTitleWithActions ||
|
|
alignLargeTitleWithActions))),
|
|
prefersSoftTopEdge:
|
|
nativeLargeTitleWithActions ||
|
|
(nativePaneSoftEdge && strip != null),
|
|
leadingTitleRowTop: nativeLargeTitleWithActions ? actionsTop : null,
|
|
leadingTitleTopPadding: strip == null ? 0 : 24,
|
|
horizontalControls:
|
|
strip != null &&
|
|
((leadingAction?.keepInHeaderOnDuo ?? false) ||
|
|
trailingActions.any((action) => action.keepInHeaderOnDuo)),
|
|
onReadyChanged: onNativeReadyChanged,
|
|
title: nativeTitle ?? (title is Text ? (title as Text).data ?? '' : ''),
|
|
subtitle: nativeSubtitle,
|
|
ephemeralLabel: nativeEphemeralLabel,
|
|
titleAvatar: nativeTitleAvatar,
|
|
titleAvatars: nativeTitleAvatars,
|
|
titleMaxWidth: nativeTitleMaxWidth,
|
|
titlePresenceColor: nativeTitlePresenceColor,
|
|
titleRefreshing: nativeTitleRefreshing,
|
|
onTitlePressed: onNativeTitlePressed,
|
|
largeTitle: nativeLargeTitle,
|
|
alwaysFrosted: alwaysFrosted || strip != null,
|
|
foregroundColor: iconColor,
|
|
leading: strip == null || (leadingAction?.keepInHeaderOnDuo ?? false)
|
|
? leadingAction
|
|
: null,
|
|
onBack: strip == null ? onBack : null,
|
|
actions: strip == null
|
|
? trailingActions
|
|
: trailingActions
|
|
.where((action) => action.keepInHeaderOnDuo)
|
|
.toList(),
|
|
);
|
|
Widget buildNative(double scrollOffset) {
|
|
// Scrolling tracks the finger directly; only the search focus change
|
|
// uses the coordinated layout transition.
|
|
final layoutDuration = nativeLargeTitle && scrollOffset > 0
|
|
? Duration.zero
|
|
: nativeLayoutDuration;
|
|
final largeTitleHeight = IosNavigationMetrics.of(
|
|
context,
|
|
).largeTitleHeight;
|
|
final extra = nativeLargeTitle
|
|
? (largeTitleHeight - scrollOffset).clamp(0.0, largeTitleHeight)
|
|
: 0.0;
|
|
final portraitHeader = alignWithStatusRegion && !nativeLargeTitle
|
|
? IosNavigationMetrics.of(context).portraitHeaderFor(
|
|
View.of(context).physicalSize /
|
|
View.of(context).devicePixelRatio,
|
|
)
|
|
: null;
|
|
final barHeight = portraitHeader == null
|
|
? MediaQuery.paddingOf(context).top +
|
|
_nativeCompactHeight(context, titleContentHeight) +
|
|
extra
|
|
: max(MediaQuery.paddingOf(context).top, portraitHeader.bottom);
|
|
return AnimatedPositioned(
|
|
duration: layoutDuration,
|
|
curve: Curves.easeInOutCubic,
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
height: barHeight + bottomHeight,
|
|
child: DuoToolbarPortal(
|
|
strip: strip,
|
|
active: toolbarActive,
|
|
actions: stripActions,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
Positioned(
|
|
top:
|
|
nativeLargeTitleWithActions &&
|
|
!centerExpandedTitle &&
|
|
extra > 0
|
|
? (centerLargeTitleBelowActions
|
|
? Grid.quarter
|
|
: alignLargeTitleWithActions
|
|
? Grid.xxs - buzzNavigationActionSize
|
|
: Grid.xxs) *
|
|
(extra / largeTitleHeight)
|
|
: 0,
|
|
left: nativeLargeTitleWithActions ? railInsets.left : 0,
|
|
right: nativeLargeTitleWithActions ? railInsets.right : 0,
|
|
height: barHeight,
|
|
child: nativeBar,
|
|
),
|
|
if (centerExpandedTitle && extra > 0)
|
|
PositionedDirectional(
|
|
start: Grid.xs,
|
|
end: Grid.xs,
|
|
top: actionsTop + buzzNavigationActionSize,
|
|
bottom: 0,
|
|
child: IgnorePointer(
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Opacity(
|
|
opacity: (extra / (largeTitleHeight * .65)).clamp(
|
|
0.0,
|
|
1.0,
|
|
),
|
|
child: Semantics(
|
|
header: true,
|
|
child: Text(
|
|
nativeTitle ?? '',
|
|
key: const ValueKey('expanded-navigation-title'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: CupertinoTheme.of(context)
|
|
.textTheme
|
|
.navLargeTitleTextStyle
|
|
.copyWith(
|
|
color:
|
|
iconColor ?? context.colors.onSurface,
|
|
leadingDistribution:
|
|
TextLeadingDistribution.even,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (nativeLargeTitleWithActions && leading != null)
|
|
PositionedDirectional(
|
|
top: actionsTop,
|
|
start: horizontalInset + railInsets.left,
|
|
height: 44,
|
|
child: leading!,
|
|
),
|
|
if (nativeLargeTitleWithActions)
|
|
PositionedDirectional(
|
|
top: actionsTop,
|
|
end: horizontalInset + railInsets.right,
|
|
height: 44,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: actions,
|
|
),
|
|
),
|
|
if (bottom != null)
|
|
AnimatedPositioned(
|
|
duration: layoutDuration,
|
|
curve: Curves.easeInOutCubic,
|
|
top: barHeight,
|
|
left: 0,
|
|
right: 0,
|
|
height: bottomHeight,
|
|
child: Padding(
|
|
padding: railInsets,
|
|
child: bottom is SizedBox
|
|
? bottom!
|
|
: ColoredBox(
|
|
color: context.colors.surface,
|
|
child: bottom!,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return offset == null
|
|
? buildNative(0)
|
|
: ValueListenableBuilder<double>(
|
|
valueListenable: offset,
|
|
builder: (context, value, child) => buildNative(value),
|
|
);
|
|
}
|
|
final portraitHeader =
|
|
alignWithStatusRegion && defaultTargetPlatform == TargetPlatform.iOS
|
|
? IosNavigationMetrics.of(context).portraitHeaderFor(
|
|
View.of(context).physicalSize / View.of(context).devicePixelRatio,
|
|
)
|
|
: null;
|
|
final topPadding = portraitHeader?.top ?? MediaQuery.paddingOf(context).top;
|
|
final scrollUnder = FrostedScrollUnderScope.maybeOf(context);
|
|
final isScrolledUnder =
|
|
alwaysFrosted || (scrollUnder?.isScrolledUnder ?? false);
|
|
final paintsFrost = frosted && isScrolledUnder;
|
|
final canPop = Navigator.canPop(context);
|
|
final effectiveTitleStyle = _effectiveTitleStyle(context, titleStyle);
|
|
final barContentHeight = _barContentHeight(
|
|
context,
|
|
titleStyle,
|
|
titleContentHeight,
|
|
);
|
|
final usesAutomaticIosGlassBackButton =
|
|
!nativeSuppressed &&
|
|
leading == null &&
|
|
automaticallyImplyLeading &&
|
|
canPop &&
|
|
Theme.of(context).platform == TargetPlatform.iOS;
|
|
final effectiveIconColor = iconColor ?? context.colors.primary;
|
|
|
|
final effectiveLeading =
|
|
leading ??
|
|
(automaticallyImplyLeading && canPop
|
|
? usesAutomaticIosGlassBackButton
|
|
? IosGlassNavigationButton(
|
|
icon: IosGlassNavigationIcon.back,
|
|
semanticLabel: 'Back',
|
|
onPressed: () => Navigator.of(context).maybePop(),
|
|
width: iosGlassChannelHeaderLeadingWidth,
|
|
buttonCenterX: iosGlassChannelHeaderButtonCenterX,
|
|
foregroundColor: effectiveIconColor,
|
|
)
|
|
: SizedBox(
|
|
width: 48,
|
|
height: 48,
|
|
child: IconButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
color: defaultTargetPlatform == TargetPlatform.android
|
|
? context.colors.onSurface
|
|
: effectiveIconColor,
|
|
style: defaultTargetPlatform == TargetPlatform.android
|
|
? androidNavigationButtonStyle(context)
|
|
: null,
|
|
icon: const Icon(BuzzIcons.chevronLeft),
|
|
tooltip: 'Back',
|
|
),
|
|
)
|
|
: null);
|
|
|
|
final titleRow = SizedBox(
|
|
height: barContentHeight,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: horizontalInset,
|
|
right:
|
|
horizontalInset +
|
|
(portraitHeader == null
|
|
? 0
|
|
: max(
|
|
0.0,
|
|
MediaQuery.sizeOf(context).width - portraitHeader.right,
|
|
)),
|
|
),
|
|
child: IconTheme.merge(
|
|
data: IconThemeData(color: effectiveIconColor),
|
|
child: _CenteredNavigationLayout(
|
|
leading: effectiveLeading,
|
|
topAlignedActions: nativeTitleAvatars.isNotEmpty,
|
|
title: title == null
|
|
? null
|
|
: DefaultTextStyle.merge(
|
|
style: effectiveTitleStyle,
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 1,
|
|
textAlign: centerTitle ? TextAlign.center : TextAlign.start,
|
|
child: centerTitle
|
|
? title!
|
|
: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: effectiveLeading != null
|
|
? usesAutomaticIosGlassBackButton
|
|
? iosGlassChannelHeaderTitleSpacing
|
|
: defaultTargetPlatform ==
|
|
TargetPlatform.android &&
|
|
nativeTitleAvatars.isNotEmpty
|
|
? 16
|
|
: 0
|
|
: horizontalInset < Grid.gutter
|
|
? Grid.gutter - horizontalInset
|
|
: 0,
|
|
right:
|
|
actions.isEmpty &&
|
|
horizontalInset < Grid.gutter
|
|
? Grid.gutter - horizontalInset
|
|
: 0,
|
|
),
|
|
child: title!,
|
|
),
|
|
),
|
|
actions: actions.isEmpty
|
|
? null
|
|
: Row(mainAxisSize: MainAxisSize.min, children: actions),
|
|
centered: centerTitle,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final contentBody = bottomHeight > 0
|
|
? SizedBox(
|
|
height: barContentHeight + bottomHeight,
|
|
child: Stack(
|
|
children: [
|
|
Positioned(top: 0, left: 0, right: 0, child: titleRow),
|
|
if (bottom != null)
|
|
Positioned(
|
|
top: barContentHeight,
|
|
left: 0,
|
|
right: 0,
|
|
height: bottomHeight,
|
|
child: bottom!,
|
|
),
|
|
if (titleOverlay != null) titleOverlay!(barContentHeight),
|
|
],
|
|
),
|
|
)
|
|
: titleRow;
|
|
|
|
final content = DirectionalTransitionMotion(
|
|
transformKey: const ValueKey(
|
|
'frosted-app-bar-content-transition-transform',
|
|
),
|
|
opacityKey: const ValueKey('frosted-app-bar-content-transition-opacity'),
|
|
child: defaultTargetPlatform == TargetPlatform.android
|
|
? IconButtonTheme(
|
|
data: IconButtonThemeData(
|
|
style: androidNavigationButtonStyle(context),
|
|
),
|
|
child: contentBody,
|
|
)
|
|
: contentBody,
|
|
);
|
|
|
|
final background = Container(
|
|
key: const ValueKey('frosted-app-bar-background'),
|
|
padding: railInsets.copyWith(top: topPadding),
|
|
decoration: const BoxDecoration(),
|
|
child: content,
|
|
);
|
|
|
|
if (defaultTargetPlatform == TargetPlatform.android &&
|
|
nativeTitleAvatars.isNotEmpty) {
|
|
return Positioned(
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
child: Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
height: topPadding + barContentHeight + bottomHeight,
|
|
child: IgnorePointer(
|
|
child: NavigationBackdrop(
|
|
active: paintsFrost,
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
background,
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
final child = NavigationBackdrop(
|
|
active: paintsFrost,
|
|
suppressNativeView: nativeSuppressed,
|
|
child: background,
|
|
);
|
|
|
|
return Positioned(top: 0, left: 0, right: 0, child: child);
|
|
}
|
|
}
|
|
|
|
enum _NavigationSlot { leading, title, actions }
|
|
|
|
class _CenteredNavigationLayout extends StatelessWidget {
|
|
const _CenteredNavigationLayout({
|
|
this.leading,
|
|
this.title,
|
|
this.actions,
|
|
required this.centered,
|
|
this.topAlignedActions = false,
|
|
});
|
|
|
|
final Widget? leading;
|
|
final Widget? title;
|
|
final Widget? actions;
|
|
final bool centered;
|
|
final bool topAlignedActions;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!centered) {
|
|
return Row(
|
|
children: [
|
|
?leading,
|
|
if (title != null) Expanded(child: title!) else const Spacer(),
|
|
?actions,
|
|
],
|
|
);
|
|
}
|
|
return CustomMultiChildLayout(
|
|
delegate: _CenteredNavigationLayoutDelegate(topAlignedActions),
|
|
children: [
|
|
if (leading != null)
|
|
LayoutId(id: _NavigationSlot.leading, child: leading!),
|
|
if (title != null) LayoutId(id: _NavigationSlot.title, child: title!),
|
|
if (actions != null)
|
|
LayoutId(id: _NavigationSlot.actions, child: actions!),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CenteredNavigationLayoutDelegate extends MultiChildLayoutDelegate {
|
|
_CenteredNavigationLayoutDelegate(this.topAlignedActions);
|
|
final bool topAlignedActions;
|
|
@override
|
|
void performLayout(Size size) {
|
|
Size leadingSize = Size.zero;
|
|
if (hasChild(_NavigationSlot.leading)) {
|
|
leadingSize = layoutChild(
|
|
_NavigationSlot.leading,
|
|
BoxConstraints.loose(size),
|
|
);
|
|
positionChild(
|
|
_NavigationSlot.leading,
|
|
Offset(
|
|
0,
|
|
topAlignedActions ? Grid.xxs : (size.height - leadingSize.height) / 2,
|
|
),
|
|
);
|
|
}
|
|
|
|
Size actionsSize = Size.zero;
|
|
if (hasChild(_NavigationSlot.actions)) {
|
|
actionsSize = layoutChild(
|
|
_NavigationSlot.actions,
|
|
BoxConstraints.loose(size),
|
|
);
|
|
positionChild(
|
|
_NavigationSlot.actions,
|
|
Offset(
|
|
size.width - actionsSize.width,
|
|
topAlignedActions ? Grid.xxs : (size.height - actionsSize.height) / 2,
|
|
),
|
|
);
|
|
}
|
|
|
|
if (hasChild(_NavigationSlot.title)) {
|
|
final occupiedSideWidth = leadingSize.width > actionsSize.width
|
|
? leadingSize.width
|
|
: actionsSize.width;
|
|
final sideWidth = occupiedSideWidth == 0
|
|
? 0.0
|
|
: occupiedSideWidth + Grid.xs;
|
|
final titleWidth = (size.width - sideWidth * 2).clamp(0.0, size.width);
|
|
final titleSize = layoutChild(
|
|
_NavigationSlot.title,
|
|
BoxConstraints(maxWidth: titleWidth, maxHeight: size.height),
|
|
);
|
|
positionChild(
|
|
_NavigationSlot.title,
|
|
Offset(
|
|
(size.width - titleSize.width) / 2,
|
|
(size.height - titleSize.height) / 2,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRelayout(
|
|
covariant _CenteredNavigationLayoutDelegate oldDelegate,
|
|
) => topAlignedActions != oldDelegate.topAlignedActions;
|
|
}
|
|
|
|
IosNavigationAction? _nativeAction(Widget? widget) {
|
|
if (widget is Padding) return _nativeAction(widget.child);
|
|
if (widget is SizedBox) return _nativeAction(widget.child);
|
|
if (widget is IosGlassNavigationAction) {
|
|
return IosNavigationAction(
|
|
label: widget.label,
|
|
onPressed: widget.isBusy ? null : widget.onPressed,
|
|
);
|
|
}
|
|
if (widget is IosGlassNavigationButton) {
|
|
final symbol = switch (widget.icon) {
|
|
IosGlassNavigationIcon.plus => 'plus',
|
|
IosGlassNavigationIcon.send => 'arrow.up',
|
|
IosGlassNavigationIcon.microphone => 'mic',
|
|
IosGlassNavigationIcon.more => 'ellipsis',
|
|
IosGlassNavigationIcon.bell => 'bell',
|
|
IosGlassNavigationIcon.trash => 'trash',
|
|
IosGlassNavigationIcon.reply => 'arrowshape.turn.up.left',
|
|
IosGlassNavigationIcon.back => 'chevron.backward',
|
|
IosGlassNavigationIcon.close => 'xmark',
|
|
IosGlassNavigationIcon.check => 'checkmark',
|
|
IosGlassNavigationIcon.camera => 'camera',
|
|
IosGlassNavigationIcon.photoLibrary => 'photo.on.rectangle',
|
|
IosGlassNavigationIcon.palette => 'paintpalette',
|
|
IosGlassNavigationIcon.droplet => 'drop',
|
|
IosGlassNavigationIcon.emoji => 'face.smiling',
|
|
IosGlassNavigationIcon.person => 'person',
|
|
IosGlassNavigationIcon.frame => 'crop',
|
|
IosGlassNavigationIcon.rotateCamera =>
|
|
'arrow.triangle.2.circlepath.camera',
|
|
IosGlassNavigationIcon.shutter => 'circle',
|
|
IosGlassNavigationIcon.colorSwatch => 'circle.fill',
|
|
IosGlassNavigationIcon.sun => 'sun.max',
|
|
IosGlassNavigationIcon.moon => 'moon',
|
|
IosGlassNavigationIcon.systemAppearance => 'circle.lefthalf.filled',
|
|
};
|
|
return IosNavigationAction(
|
|
label: widget.label ?? widget.semanticLabel,
|
|
symbol: widget.label == null ? symbol : null,
|
|
selected: widget.isSelected,
|
|
onPressed: widget.isBusy ? null : widget.onPressed,
|
|
);
|
|
}
|
|
if (widget is IconButton) {
|
|
final icon = widget.icon is Icon ? (widget.icon as Icon).icon : null;
|
|
final symbol = icon == BuzzIcons.x
|
|
? 'xmark'
|
|
: icon == BuzzIcons.chevronLeft || icon == BuzzIcons.arrowLeft
|
|
? 'chevron.backward'
|
|
: icon == BuzzIcons.users
|
|
? 'person.2'
|
|
: 'ellipsis';
|
|
return IosNavigationAction(
|
|
label: widget.tooltip ?? 'Action',
|
|
symbol: symbol,
|
|
onPressed: widget.onPressed,
|
|
);
|
|
}
|
|
if (widget is ButtonStyleButton && widget.child is Text) {
|
|
return IosNavigationAction(
|
|
label: (widget.child as Text).data ?? '',
|
|
onPressed: widget.onPressed,
|
|
);
|
|
}
|
|
return null;
|
|
}
|