mirror of
https://github.com/block/buzz.git
synced 2026-11-15 22:02:04 +00:00
fix(mobile): slide a closing chat away instead of cutting to the list (#9511)
On iPhone, tapping back from a chat (or finishing a back swipe) cut straight to the chat list with no slide. This affects every chat opened in a compact conversation pane: Home channels and DMs, Solo chats, Search and Inbox. ### Cause Since the nested conversation navigator landed, popping a detail clears the pane's selection when the pop starts (Flutter reports the removed page right away, before the reverse transition). The pane then put the detail navigator offstage and stopped its tickers in that same frame, so the reverse slide ran invisibly and the list appeared at once. ### Fix The pane counts mounted detail routes. A popped route keeps its content mounted until its reverse transition ends, so the detail stays onstage and ticking until then. The selection still clears at the start of the pop, so nothing else about the pop changes (the list is uncovered and its toolbar returns as before). ### Regressions - Wide layouts (iPad, Duo) are unchanged: their detail was always onstage. - No extra rebuilds: the count drives only the detail's visibility and tickers, so opening or switching chats builds the chat screen as often as before (checked with a build-count test in compact and wide layouts). - Reopening a chat while the previous one slides away behaves as before: the new chat covers the list. ### Validation - Added steps to the existing iPhone back test: the chat is still on screen mid-pop after the back button and after a completed back swipe, then gone once settled; reopening mid-pop shows the reopened chat. The mid-pop step fails without the fix. - Full mobile suite, analyze and format. One unrelated media-placeholder test (`message_skeleton_geometry_test.dart`) failed once while two iOS builds loaded the machine, and passed on rerun. - Simulator run (iPhone 17 Pro, debug build, signed-in test community): Home list, open a Solo chat, back button, reopen, back swipe. Before on the left, after on the right. https://github.com/user-attachments/assets/a5b88c2b-dc86-4345-8a88-29142a0bf7dc buzz-review-completed --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -195,6 +195,11 @@ class AdaptiveConversationPane extends HookConsumerWidget {
|
||||
// The compact detail route that fully covers the list. While a detail
|
||||
// pushes, pops or follows a back swipe, the list stays painted beneath it.
|
||||
final coveringDetail = useValueNotifier<Route<Object?>?>(null);
|
||||
// Compact detail routes still mounted. A pop clears the selection as it
|
||||
// starts, so the detail stays onstage until its reverse transition ends.
|
||||
// Not disposed with the pane: a detail unmounting with the pane reports
|
||||
// after the frame, once the pane is gone.
|
||||
final mountedDetails = useMemoized(() => ValueNotifier(0));
|
||||
return ConversationPaneScope(
|
||||
controller: controller,
|
||||
active: active && (ModalRoute.isCurrentOf(context) ?? true),
|
||||
@@ -291,118 +296,122 @@ class AdaptiveConversationPane extends HookConsumerWidget {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
width: detailWidth,
|
||||
child: Offstage(
|
||||
offstage: !wide && selected == null,
|
||||
child: TickerMode(
|
||||
enabled: wide || selected != null,
|
||||
child: MediaQueryOverride(
|
||||
transform: (media) => media.copyWith(
|
||||
size: Size(detailWidth, constraints.maxHeight),
|
||||
child: ValueListenableBuilder<int>(
|
||||
valueListenable: mountedDetails,
|
||||
builder: (context, mounted, detail) {
|
||||
final shown = wide || selected != null || mounted > 0;
|
||||
return Offstage(
|
||||
offstage: !shown,
|
||||
child: TickerMode(enabled: shown, child: detail!),
|
||||
);
|
||||
},
|
||||
child: MediaQueryOverride(
|
||||
transform: (media) => media.copyWith(
|
||||
size: Size(detailWidth, constraints.maxHeight),
|
||||
),
|
||||
child: DuoToolbarScope(
|
||||
strip: strip,
|
||||
leadingSlots: wide ? listToolbarSlots : 0,
|
||||
contentInsets: EdgeInsets.only(
|
||||
left: wide ? (book?.width ?? 0) / 2 : leftInset,
|
||||
right: rightInset,
|
||||
),
|
||||
child: DuoToolbarScope(
|
||||
strip: strip,
|
||||
leadingSlots: wide ? listToolbarSlots : 0,
|
||||
contentInsets: EdgeInsets.only(
|
||||
left: wide ? (book?.width ?? 0) / 2 : leftInset,
|
||||
right: rightInset,
|
||||
),
|
||||
active:
|
||||
active &&
|
||||
selected != null &&
|
||||
(ModalRoute.isCurrentOf(context) ?? true),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
child: PopScope<Object?>(
|
||||
canPop:
|
||||
!active ||
|
||||
selected == null ||
|
||||
(wide && persistentSelection),
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop &&
|
||||
active &&
|
||||
selected != null &&
|
||||
!(wide && persistentSelection)) {
|
||||
navigator.currentState!.maybePop(result);
|
||||
}
|
||||
},
|
||||
child: ExcludeFocus(
|
||||
excluding: selected == null,
|
||||
child: NavigatorPopHandler<Object?>(
|
||||
enabled: wide && persistentSelection,
|
||||
onPopWithResult: (result) =>
|
||||
navigator.currentState!.pop(result),
|
||||
child: Navigator(
|
||||
requestFocus: selected != null,
|
||||
key: navigator,
|
||||
observers: [routeObserver],
|
||||
pages: [
|
||||
if (!(wide &&
|
||||
persistentSelection &&
|
||||
selected != null))
|
||||
MaterialPage<void>(
|
||||
key: const ValueKey(
|
||||
'conversation-placeholder',
|
||||
),
|
||||
// Compact panes show the list
|
||||
// through this page while a
|
||||
// detail pushes or pops.
|
||||
child: !wide
|
||||
? const SizedBox.shrink()
|
||||
: Material(
|
||||
color: context
|
||||
.colors
|
||||
.surface,
|
||||
child: Center(
|
||||
child:
|
||||
emptyContent ??
|
||||
Text(
|
||||
emptyLabel,
|
||||
textAlign:
|
||||
TextAlign
|
||||
.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
decoration:
|
||||
TextDecoration
|
||||
.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
active:
|
||||
active &&
|
||||
selected != null &&
|
||||
(ModalRoute.isCurrentOf(context) ?? true),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
child: PopScope<Object?>(
|
||||
canPop:
|
||||
!active ||
|
||||
selected == null ||
|
||||
(wide && persistentSelection),
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop &&
|
||||
active &&
|
||||
selected != null &&
|
||||
!(wide && persistentSelection)) {
|
||||
navigator.currentState!.maybePop(result);
|
||||
}
|
||||
},
|
||||
child: ExcludeFocus(
|
||||
excluding: selected == null,
|
||||
child: NavigatorPopHandler<Object?>(
|
||||
enabled: wide && persistentSelection,
|
||||
onPopWithResult: (result) =>
|
||||
navigator.currentState!.pop(result),
|
||||
child: Navigator(
|
||||
requestFocus: selected != null,
|
||||
key: navigator,
|
||||
observers: [routeObserver],
|
||||
pages: [
|
||||
if (!(wide &&
|
||||
persistentSelection &&
|
||||
selected != null))
|
||||
MaterialPage<void>(
|
||||
key: const ValueKey(
|
||||
'conversation-placeholder',
|
||||
),
|
||||
if (selected != null)
|
||||
if (controller.animateSelection)
|
||||
MaterialPage<void>(
|
||||
key: controller.selectionKey,
|
||||
child: _CoveringDetail(
|
||||
covering: coveringDetail,
|
||||
builder:
|
||||
controller.detailBuilder!,
|
||||
),
|
||||
)
|
||||
else
|
||||
_ImmediateDetailPage(
|
||||
key: controller.selectionKey,
|
||||
builder: (_) => _CoveringDetail(
|
||||
covering: coveringDetail,
|
||||
builder:
|
||||
controller.detailBuilder!,
|
||||
),
|
||||
// Compact panes show the list
|
||||
// through this page while a
|
||||
// detail pushes or pops.
|
||||
child: !wide
|
||||
? const SizedBox.shrink()
|
||||
: Material(
|
||||
color:
|
||||
context.colors.surface,
|
||||
child: Center(
|
||||
child:
|
||||
emptyContent ??
|
||||
Text(
|
||||
emptyLabel,
|
||||
textAlign: TextAlign
|
||||
.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
decoration:
|
||||
TextDecoration
|
||||
.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (selected != null)
|
||||
if (controller.animateSelection)
|
||||
MaterialPage<void>(
|
||||
key: controller.selectionKey,
|
||||
child: _CoveringDetail(
|
||||
covering: coveringDetail,
|
||||
mounted: mountedDetails,
|
||||
builder:
|
||||
controller.detailBuilder!,
|
||||
),
|
||||
],
|
||||
onDidRemovePage: (page) {
|
||||
if (page.key ==
|
||||
controller.selectionKey) {
|
||||
controller.clear();
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
else
|
||||
_ImmediateDetailPage(
|
||||
key: controller.selectionKey,
|
||||
builder: (_) => _CoveringDetail(
|
||||
covering: coveringDetail,
|
||||
mounted: mountedDetails,
|
||||
builder:
|
||||
controller.detailBuilder!,
|
||||
),
|
||||
),
|
||||
],
|
||||
onDidRemovePage: (page) {
|
||||
if (page.key ==
|
||||
controller.selectionKey) {
|
||||
controller.clear();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -483,15 +492,30 @@ class MediaQueryOverride extends StatelessWidget {
|
||||
/// Reports its route as [covering] once the route fully covers the compact
|
||||
/// list, and withdraws it while the route pushes, pops or follows a back swipe.
|
||||
class _CoveringDetail extends HookWidget {
|
||||
const _CoveringDetail({required this.covering, required this.builder});
|
||||
const _CoveringDetail({
|
||||
required this.covering,
|
||||
required this.mounted,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
final ValueNotifier<Route<Object?>?> covering;
|
||||
|
||||
/// Counts mounted details. A popped route unmounts its content only once
|
||||
/// its reverse transition has finished.
|
||||
final ValueNotifier<int> mounted;
|
||||
final WidgetBuilder builder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final route = ModalRoute.of(context);
|
||||
final navigator = Navigator.of(context);
|
||||
useEffect(() {
|
||||
// The count rebuilds an ancestor, which cannot rebuild while this
|
||||
// mounts or unmounts.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => mounted.value++);
|
||||
return () =>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => mounted.value--);
|
||||
}, [mounted]);
|
||||
useEffect(() {
|
||||
if (route == null) return null;
|
||||
void sync() {
|
||||
|
||||
@@ -513,15 +513,47 @@ void main() {
|
||||
expect(controller.selectedId, 'chat');
|
||||
expect(list, findsNothing);
|
||||
|
||||
final chat = find.byType(_Conversation);
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(list, findsOneWidget, reason: 'the list stays beneath a pop');
|
||||
expect(placeholder, findsNothing);
|
||||
expect(chat, findsOneWidget, reason: 'the chat slides away, not vanishes');
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.selectedId, isNull);
|
||||
expect(chat, findsNothing);
|
||||
await tester.tap(list);
|
||||
expect(listTaps, 1);
|
||||
|
||||
// A completed back swipe also slides the chat away.
|
||||
controller.open('chat', (_) => const _Conversation());
|
||||
await tester.pumpAndSettle();
|
||||
final release = await tester.startGesture(const Offset(5, 400));
|
||||
await release.moveBy(const Offset(150, 0));
|
||||
await tester.pump();
|
||||
await release.moveBy(const Offset(150, 0));
|
||||
await tester.pump();
|
||||
await release.up();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(chat, findsOneWidget, reason: 'the swiped chat finishes sliding');
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.selectedId, isNull);
|
||||
expect(chat, findsNothing);
|
||||
|
||||
// Reopening while the chat slides away shows the reopened chat.
|
||||
controller.open('chat', (_) => const _Conversation());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
controller.open('chat', (_) => const _Conversation());
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.selectedId, 'chat');
|
||||
expect(chat, findsOneWidget);
|
||||
expect(list, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user