Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions mobile/lib/features/channels/channels_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class ChannelsPage extends HookConsumerWidget {
required this.settingsPageBuilder,
this.onSearch,
this.messagesActionsBuilder,
this.messagesRailActionsBuilder,
this.soloSliver,
this.newChannelAction,
this.newDmAction,
Expand All @@ -167,6 +168,11 @@ class ChannelsPage extends HookConsumerWidget {
/// standalone Channels header.
final List<Widget> Function(VoidCallback openSwitcher, GlobalKey avatarKey)?
messagesActionsBuilder;

/// Builds the Messages header actions as native controls for Duo's rail,
/// which replaces the header actions there.
final List<IosNavigationAction> Function(VoidCallback openSwitcher)?
messagesRailActionsBuilder;
final Widget? soloSliver;
final ValueNotifier<VoidCallback?>? newChannelAction;
final ValueNotifier<VoidCallback?>? newDmAction;
Expand Down Expand Up @@ -211,6 +217,7 @@ class ChannelsPage extends HookConsumerWidget {
(DuoToolbarScope.maybeStripOf(context) ??
FoldGeometry.of(context).strip) !=
null;
final railActions = nativeDuoTitle && messagesRailActionsBuilder != null;
final topSectionHeight = frostedAppBarHeight(
context,
titleStyle: headerTitleStyle,
Expand Down Expand Up @@ -724,7 +731,9 @@ class ChannelsPage extends HookConsumerWidget {
child: Text('Messages', style: headerTitleStyle),
)
: const SizedBox.shrink(),
actions: messages
actions: railActions
? const []
: messages
? messagesActionsBuilder?.call(
openCommunityGrid,
communityAvatarKey,
Expand All @@ -746,7 +755,14 @@ class ChannelsPage extends HookConsumerWidget {
current: routeCurrent,
nativeSuppressed: headerNativeSuppressed,
suppressesNative: messages,
child: page,
// Outside the header's scroll-driven builder and scroll scope, so the
// rail controls do not rebuild or receive scroll updates per frame.
child: railActions
? _DuoRailActions(
actions: messagesRailActionsBuilder!(openCommunityGrid),
child: page,
)
: page,
);
}
}
Expand Down Expand Up @@ -867,3 +883,27 @@ BoxConstraints _quickActionSheetConstraints(BuildContext context) {
maxHeight: mediaQuery.size.height - mediaQuery.viewPadding.top,
);
}

/// Shows Home's Messages actions in Duo's rail while its pane and route are
/// current.
class _DuoRailActions extends StatelessWidget {
const _DuoRailActions({required this.actions, required this.child});

final List<IosNavigationAction> actions;
final Widget child;

@override
Widget build(BuildContext context) {
final toolbarScope = DuoToolbarScope.maybeOf(context);
return DuoToolbarPortal(
strip: toolbarScope == null
? FoldGeometry.of(context).strip
: toolbarScope.strip,
active:
(toolbarScope?.active ?? true) &&
(ModalRoute.isCurrentOf(context) ?? true),
actions: actions,
child: child,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ class CommunitySwitcherPage extends HookConsumerWidget {
Navigator.of(context).pop();
return;
}
if (animate) {
// On Duo the header avatar is in the rail and is not measured, so
// reveal Home at once rather than hold the avatar still mid-flight.
if (animate && landingBounds.value != null) {
await controller.forward(from: 0).orCancel;
if (!context.mounted) return;
// Reveal the settled page only after the avatar stops moving.
Expand Down
87 changes: 59 additions & 28 deletions mobile/lib/features/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:duo_kit/duo_kit.dart';
import '../../shared/widgets/adaptive_conversation_pane.dart';
import '../../shared/widgets/duo_workspace_scaffold.dart';
import '../../shared/widgets/duo_toolbar.dart';
import '../../shared/widgets/ios_navigation_metrics.dart';
import '../../shared/widgets/ios_navigation_bar.dart';
import '../../shared/widgets/android_expanding_menu_button.dart';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -133,36 +133,61 @@ class HomePage extends HookConsumerWidget {
reducedMotion: reducedMotion,
),
);
List<({String label, String symbol, VoidCallback? onPressed})>
moreActionsFor(VoidCallback openSwitcher) => [
// An internal build reaches only its organization's community.
if (!OrganizationEnvironment.enabled)
(
label: 'Switch community',
symbol: 'arrow.left.arrow.right',
onPressed: openSwitcher,
),
if (canInvite && communityInvitePageBuilder != null)
(
label: 'Invite',
symbol: 'person.badge.plus',
onPressed: () => openPage(communityInvitePageBuilder!),
),
(label: 'Agents', symbol: 'agent', onPressed: () => onAgents(context)),
if (communityAppearancePageBuilder != null)
(
label: 'Appearance',
symbol: 'circle.lefthalf.filled',
onPressed: () => openPage(communityAppearancePageBuilder!),
),
(label: 'Settings', symbol: 'gearshape', onPressed: openSettings),
];
final messages = ChannelsPage(
settingsPageBuilder: settingsPageBuilder,
// On Duo, Activity and the Community menu sit in the rail. Like the
// header controls, they hide while Bestie records.
messagesRailActionsBuilder: (openSwitcher) => recordingFocus.value
? const []
: [
IosNavigationAction(
label: 'Activity',
symbol: 'bell',
activityColor: hasUnreadInbox ? context.colors.primary : null,
activityLabel: hasUnreadInbox ? 'Unread items' : null,
onPressed: openInbox,
),
IosNavigationAction(
label: 'Community menu',
avatarInitial: communityName.isEmpty
? '?'
: communityName.characters.first.toUpperCase(),
children: [
for (final action in moreActionsFor(openSwitcher))
IosNavigationAction(
label: action.label,
symbol: action.symbol,
onPressed: action.onPressed,
),
],
),
],
messagesActionsBuilder: (openSwitcher, avatarKey) {
final moreActions = [
// An internal build reaches only its organization's community.
if (!OrganizationEnvironment.enabled)
(
label: 'Switch community',
symbol: 'arrow.left.arrow.right',
onPressed: openSwitcher,
),
if (canInvite && communityInvitePageBuilder != null)
(
label: 'Invite',
symbol: 'person.badge.plus',
onPressed: () => openPage(communityInvitePageBuilder!),
),
(
label: 'Agents',
symbol: 'agent',
onPressed: () => onAgents(context),
),
if (communityAppearancePageBuilder != null)
(
label: 'Appearance',
symbol: 'circle.lefthalf.filled',
onPressed: () => openPage(communityAppearancePageBuilder!),
),
(label: 'Settings', symbol: 'gearshape', onPressed: openSettings),
];
final moreActions = moreActionsFor(openSwitcher);
return [
_NativeControlsGate(
builder: (_, nativeControlsVisible) =>
Expand Down Expand Up @@ -452,6 +477,12 @@ class HomePage extends HookConsumerWidget {
child: AdaptiveConversationPane(
controller: conversations,
strip: strip,
// Keep an open conversation's rail controls below Home's.
listToolbarSlots:
defaultTargetPlatform == TargetPlatform.iOS &&
strip != null
? 2
: 0,
preferredListWidth: sidebarWidth,
emptyContent: strip == null
? null
Expand Down
45 changes: 36 additions & 9 deletions mobile/test/features/channels/channels_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2554,13 +2554,28 @@ void main() {
);
});

for (final reduceMotion in [false, true]) {
for (final (duo, reduceMotion) in [
(false, false),
(false, true),
(true, false),
]) {
testWidgets(
'paired community waits then uses the community landing (reduced motion: $reduceMotion)',
'paired community waits then uses the community landing (Duo: $duo, reduced motion: $reduceMotion)',
(tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
// Duo moves Home's header avatar into the rail, so there is no
// destination to fly to.
debugDefaultTargetPlatformOverride = duo
? TargetPlatform.iOS
: TargetPlatform.android;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
tester.view.physicalSize = const Size(390, 844);
final screen = duo ? const Size(466, 678) : const Size(390, 844);
tester.view.physicalSize = screen;
if (duo) {
tester.view.viewPadding = const FakeViewPadding(right: 76);
tester.view.padding = const FakeViewPadding(right: 76);
addTearDown(tester.view.resetViewPadding);
addTearDown(tester.view.resetPadding);
}
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
Expand All @@ -2575,6 +2590,7 @@ void main() {
await tester.pumpWidget(
buildTestable(
disableAnimations: reduceMotion,
realHome: duo,
overrides: [
pairingProvider.overrideWith(_CompletedPairingNotifier.new),
channelsProvider.overrideWith(
Expand Down Expand Up @@ -2611,7 +2627,7 @@ void main() {
await tester.pump();
final avatar = find.byKey(const Key('community-flying-avatar'));
expect(avatar, findsOneWidget);
expect(tester.getCenter(avatar), const Offset(195, 422));
expect(tester.getCenter(avatar), screen.center(Offset.zero));
expect(
find.byKey(const Key('community-switch-loading')),
findsOneWidget,
Expand All @@ -2624,11 +2640,22 @@ void main() {
for (var i = 0; i < 12; i++) {
await tester.pump();
}
await tester.pump(const Duration(milliseconds: 450));
for (var i = 0; i < 6; i++) {
await tester.pump();
if (duo) {
// The avatar leaves with its loading indicator. A departure toward
// the missing header avatar would hold it still at the center.
final loading = find.byKey(const Key('community-switch-loading'));
for (var i = 0; i < 200 && avatar.evaluate().isNotEmpty; i++) {
expect(loading, findsOneWidget);
await tester.pump(const Duration(milliseconds: 10));
}
expect(avatar, findsNothing);
} else {
await tester.pump(const Duration(milliseconds: 450));
for (var i = 0; i < 6; i++) {
await tester.pump();
}
}
if (!reduceMotion) {
if (!duo && !reduceMotion) {
await tester.pump(const Duration(milliseconds: 260));
expect(tester.getCenter(avatar).dy, lessThan(422));
}
Expand Down
Loading
Loading