mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Fixes three regressions that #9717 (Duo chat switching) introduced. **Glass controls blank when anything covers their route.** #9717 gated `IosGlassNavigationButton` and `IosGlassNavigationAction` on `useNativeRouteControlsVisible`, so every glass control (Home's filter chips, glass Back, Close, Done) unmounted under any dialog, alert or modal sheet and during every push, pop and back swipe, then came back as a new platform view near the end of the transition. This drops the gate from those two widgets, which restores their behaviour from before #9717. The problem #9717 targets is unaffected: under Search and Activity sheets the hook already returns true and the opaque backing hides the controls. Home's gate, the Channels route sync and `IosMessageCreateButton` keep the hook. **The visibility hook rebuilt its host on every animation frame.** It subscribed to the route's animation values but only reads whether the covering animation is at zero and whether the route is reversing. It now uses `useListenableSelector` on those two booleans, so a host rebuilds only when visibility can change. **A wide thread push lost the outgoing chat's slide.** For an immediate wide selection, `_ConversationDetailRoute.buildTransitions` returned its child directly, which also discarded the secondary animation that moves the chat left when a thread is pushed over it. It now builds the platform transition with a completed primary animation, so selection stays immediate and the covered chat keeps its parallax. ### Regressions - Glass controls go back to staying mounted under covering routes, as they did before #9717. Platform-view bleed under non-sheet routes is therefore the pre-#9717 behaviour, not new. - No change to compact navigation or to the Search and Activity sheet composition. ### Validation Added tests: - [native_route_controls_test.dart](fb0d16ef56/mobile/test/shared/widgets/native_route_controls_test.dart): glass controls stay mounted, with the same channels, under a dialog and keep receiving appearance updates, while only the create control unmounts and returns; glass controls stay mounted with no platform-view churn across a modal bottom sheet; the `bottomUp=false` composition case keeps the glass views; the hook rebuilds its host a small constant number of times across a full push and pop. - [adaptive_conversation_pane_test.dart](fb0d16ef56/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart): in the wide layout, the covered chat has moved left 150 ms into a thread push on iOS. Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
899 lines
31 KiB
Dart
899 lines
31 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:buzz/shared/widgets/text_editor.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:buzz/shared/widgets/ios_navigation_bar.dart';
|
|
import 'package:duo_kit/duo_kit.dart';
|
|
import 'package:buzz/shared/widgets/frosted_scaffold.dart';
|
|
import 'package:buzz/shared/widgets/frosted_app_bar.dart';
|
|
import 'package:buzz/shared/widgets/modal_presentation.dart';
|
|
import 'package:buzz/shared/widgets/adaptive_conversation_pane.dart';
|
|
import 'package:buzz/shared/theme/theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
for (final platform in [TargetPlatform.iOS, TargetPlatform.android]) {
|
|
testWidgets(
|
|
'wide selections are immediate but threads animate on $platform',
|
|
(tester) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(1000, 800);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
theme: ThemeData(platform: platform),
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: const Text('Chat list'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
controller.open('one', (_) => const _Conversation());
|
|
await tester.pump();
|
|
var route = ModalRoute.of(tester.element(find.text('Conversation')))!;
|
|
expect(route.animation!.value, 1);
|
|
expect(route.animation!.status, AnimationStatus.completed);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Thread'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
route = ModalRoute.of(tester.element(find.text('Thread content')))!;
|
|
expect(route.animation!.value, greaterThan(0));
|
|
expect(route.animation!.value, lessThan(1));
|
|
await tester.pumpAndSettle();
|
|
|
|
// Switching from a nested thread must also immediately replace the chat.
|
|
controller.open(
|
|
'two',
|
|
(_) => const Scaffold(body: Text('Second chat')),
|
|
);
|
|
await tester.pump();
|
|
route = ModalRoute.of(tester.element(find.text('Second chat')))!;
|
|
expect(route.animation!.value, 1);
|
|
expect(route.animation!.status, AnimationStatus.completed);
|
|
expect(find.text('Thread content'), findsNothing);
|
|
await tester.pumpAndSettle();
|
|
},
|
|
);
|
|
}
|
|
|
|
testWidgets('a wide thread push slides the outgoing chat on iOS', (
|
|
tester,
|
|
) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(1000, 800);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
theme: ThemeData(platform: TargetPlatform.iOS),
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: const Text('Chat list'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
controller.open('one', (_) => const _Conversation());
|
|
await tester.pumpAndSettle();
|
|
final settled = tester.getTopLeft(find.text('Conversation')).dx;
|
|
await tester.tap(find.text('Thread'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 150));
|
|
expect(
|
|
tester.getTopLeft(find.text('Conversation')).dx,
|
|
lessThan(settled),
|
|
reason: 'the covered chat keeps the platform parallax',
|
|
);
|
|
await tester.pumpAndSettle();
|
|
});
|
|
|
|
testWidgets(
|
|
'wide chat switches retain the native header but reset chat state',
|
|
(tester) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(1000, 800);
|
|
addTearDown(tester.view.reset);
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform_views,
|
|
(_) async => null,
|
|
);
|
|
addTearDown(
|
|
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform_views,
|
|
null,
|
|
),
|
|
);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: const Text('Chats'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
Widget chat(String title) => FrostedScaffold(
|
|
appBar: FrostedAppBar(
|
|
nativeTitle: title,
|
|
title: Text(title),
|
|
alwaysFrosted: true,
|
|
),
|
|
body: const Center(child: TextField()),
|
|
);
|
|
controller.open('one', (_) => chat('One'));
|
|
await tester.pumpAndSettle();
|
|
final header = tester.element(find.byType(IosNavigationBar));
|
|
final native = tester.element(find.byType(UiKitView));
|
|
await tester.enterText(find.byType(TextField), 'First chat draft');
|
|
controller.open('two', (_) => chat('Two'));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(find.byType(IosNavigationBar)), same(header));
|
|
expect(tester.element(find.byType(UiKitView)), same(native));
|
|
expect(
|
|
tester.widget<IosNavigationBar>(find.byType(IosNavigationBar)).title,
|
|
'Two',
|
|
);
|
|
expect(find.text('First chat draft'), findsNothing);
|
|
Navigator.of(
|
|
tester.element(find.byType(TextField)),
|
|
).push(MaterialPageRoute<void>(builder: (_) => chat('Thread')));
|
|
await tester.pumpAndSettle();
|
|
controller.open('three', (_) => chat('Three'));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(find.byType(IosNavigationBar)), same(header));
|
|
expect(tester.element(find.byType(UiKitView)), same(native));
|
|
expect(
|
|
tester.widget<IosNavigationBar>(find.byType(IosNavigationBar)).title,
|
|
'Three',
|
|
);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
|
|
testWidgets('reopening a deep link resets its route after thread Back', (
|
|
tester,
|
|
) async {
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(1000, 800);
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () => openConversationPane(
|
|
context,
|
|
'activity-item',
|
|
(_) => const _DeepLink(),
|
|
reopen: true,
|
|
),
|
|
child: const Text('Open activity'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
for (var attempt = 0; attempt < 2; attempt++) {
|
|
await tester.tap(find.text('Open activity'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Deep-linked thread'), findsOneWidget);
|
|
await tester.tap(find.byType(BackButton));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Selected channel'), findsOneWidget);
|
|
expect(controller.selectedId, 'activity-item');
|
|
expect(
|
|
ConversationPaneScope.isBaseRouteOf(
|
|
tester.element(find.text('Selected channel')),
|
|
),
|
|
isTrue,
|
|
);
|
|
}
|
|
});
|
|
|
|
testWidgets('phones stay compact while tablets and Duo retain panes', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
for (final platform in [TargetPlatform.iOS, TargetPlatform.android]) {
|
|
debugDefaultTargetPlatformOverride = platform;
|
|
for (final scenario in [
|
|
(size: const Size(402, 874), duo: false, top: 24.0, wide: false),
|
|
(size: const Size(874, 402), duo: false, top: 24.0, wide: false),
|
|
(size: const Size(1024, 768), duo: false, top: 24.0, wide: true),
|
|
(size: const Size(768, 1024), duo: false, top: 24.0, wide: true),
|
|
(size: const Size(874, 402), duo: true, top: 0.0, wide: true),
|
|
(
|
|
size: const Size(669, 951),
|
|
duo: false,
|
|
top: 82.0,
|
|
wide: platform != TargetPlatform.iOS,
|
|
),
|
|
]) {
|
|
tester.view.physicalSize = scenario.size;
|
|
tester.view.viewPadding = FakeViewPadding(top: scenario.top);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Builder(
|
|
builder: (context) {
|
|
final wide = usesConversationPanes(
|
|
context,
|
|
strip: scenario.duo
|
|
? const FoldStrip(
|
|
side: FoldStripSide.right,
|
|
rect: Rect.fromLTWH(798, 0, 76, 402),
|
|
topClearance: 0,
|
|
bottomClearance: 0,
|
|
isClearanceEstimated: true,
|
|
)
|
|
: null,
|
|
);
|
|
return Text(wide ? 'Split panes' : 'Single pane');
|
|
},
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
find.text(scenario.wide ? 'Split panes' : 'Single pane'),
|
|
findsOneWidget,
|
|
);
|
|
}
|
|
}
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
|
|
testWidgets(
|
|
'detail surface reaches rail and sheet covers the whole workspace',
|
|
(tester) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(951, 669);
|
|
tester.view.padding = const FakeViewPadding(right: 76);
|
|
tester.view.viewPadding = const FakeViewPadding(right: 76);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
controller.open(
|
|
'settings',
|
|
(context) => FrostedScaffold(
|
|
key: const ValueKey('detail-surface'),
|
|
appBar: const FrostedAppBar(title: Text('Channel settings')),
|
|
body: Center(
|
|
child: TextButton(
|
|
onPressed: () => showBuzzModalBottomSheet<void>(
|
|
context: context,
|
|
title: 'Channel actions',
|
|
builder: (_) => const SizedBox(
|
|
height: 200,
|
|
child: Center(child: Text('Sheet content')),
|
|
),
|
|
),
|
|
child: const Text('Open sheet'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: IosNavigationMetricsHost(
|
|
child: AdaptiveConversationPane(
|
|
controller: controller,
|
|
strip: const FoldStrip(
|
|
side: FoldStripSide.right,
|
|
rect: Rect.fromLTWH(875, 0, 76, 669),
|
|
topClearance: 110,
|
|
bottomClearance: 0,
|
|
isClearanceEstimated: true,
|
|
),
|
|
list: const ColoredBox(
|
|
color: Colors.white,
|
|
child: Text('Sidebar'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getRect(find.byKey(const ValueKey('detail-surface'))).right,
|
|
951,
|
|
);
|
|
expect(
|
|
tester.getCenter(find.text('Open sheet')).dx,
|
|
closeTo((875 / 3 + 1 + 875) / 2, 1),
|
|
);
|
|
final flatLeft = tester
|
|
.getRect(find.byKey(const ValueKey('detail-surface')))
|
|
.left;
|
|
for (final division in [
|
|
<double>[470, 0, 12, 669],
|
|
null,
|
|
]) {
|
|
IosNavigationMetrics.updateRail(tester.element(find.text('Sidebar')), {
|
|
'centerX': 920,
|
|
'windowWidth': 951,
|
|
'windowHeight': 669,
|
|
'bookDivision': division,
|
|
});
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 120));
|
|
final moving = tester.getRect(
|
|
find.byKey(const ValueKey('detail-surface')),
|
|
);
|
|
expect(moving.left, greaterThan(flatLeft));
|
|
expect(moving.left, lessThan(476));
|
|
expect(moving.right, 951);
|
|
await tester.pumpAndSettle();
|
|
final detail = tester.getRect(
|
|
find.byKey(const ValueKey('detail-surface')),
|
|
);
|
|
expect(detail.left, division == null ? flatLeft : 476);
|
|
expect(detail.right, 951);
|
|
if (division != null) {
|
|
expect(tester.getRect(find.text('Sidebar')).right, detail.left);
|
|
expect(
|
|
tester.getCenter(find.text('Open sheet')).dx,
|
|
closeTo((482 + 875) / 2, 1),
|
|
);
|
|
}
|
|
expect(controller.selectedId, 'settings');
|
|
expect(find.text('Open sheet'), findsOneWidget);
|
|
}
|
|
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
|
const FakeAccessibilityFeatures(disableAnimations: true);
|
|
addTearDown(
|
|
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
|
);
|
|
await tester.pump();
|
|
IosNavigationMetrics.updateRail(tester.element(find.text('Sidebar')), {
|
|
'centerX': 920,
|
|
'windowWidth': 951,
|
|
'windowHeight': 669,
|
|
'bookDivision': <double>[470, 0, 12, 669],
|
|
});
|
|
await tester.pump();
|
|
expect(
|
|
tester.getRect(find.byKey(const ValueKey('detail-surface'))).left,
|
|
476,
|
|
);
|
|
IosNavigationMetrics.updateRail(tester.element(find.text('Sidebar')), {
|
|
'centerX': 920,
|
|
'windowWidth': 951,
|
|
'windowHeight': 669,
|
|
});
|
|
await tester.pump();
|
|
expect(
|
|
tester.getRect(find.byKey(const ValueKey('detail-surface'))).left,
|
|
flatLeft,
|
|
);
|
|
await tester.tap(find.text('Open sheet'));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getRect(find.byType(BottomSheet)).left, 0);
|
|
expect(tester.getRect(find.byType(BottomSheet)).right, 951);
|
|
expect(tester.getRect(find.text('Sheet content')).right, lessThan(875));
|
|
final close = find.byKey(
|
|
const ValueKey('duo-toolbar-Close Channel actions'),
|
|
);
|
|
expect(close, findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('buzz-sheet-ios-glass-close')),
|
|
findsNothing,
|
|
);
|
|
expect(tester.getRect(close).center.dx, greaterThan(875));
|
|
final railBar = tester.widget<IosNavigationBar>(
|
|
find.descendant(of: close, matching: find.byType(IosNavigationBar)),
|
|
);
|
|
railBar.leading!.onPressed!();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const ValueKey('detail-surface')), findsOneWidget);
|
|
expect(controller.selectedId, 'settings');
|
|
const nativeEditor = MethodChannel('buzz/profile_text_editor');
|
|
final nativeTitles = <String>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
nativeEditor,
|
|
(call) async {
|
|
nativeTitles.add((call.arguments as Map)['title'] as String);
|
|
return null;
|
|
},
|
|
);
|
|
addTearDown(
|
|
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
nativeEditor,
|
|
null,
|
|
),
|
|
);
|
|
for (final title in ['Display name', 'Profile description']) {
|
|
showTextEditor(
|
|
context: tester.element(find.text('Open sheet')),
|
|
title: title,
|
|
initialValue: 'Original',
|
|
hintText: title,
|
|
onSave: (_) async {},
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(TextField), findsNothing);
|
|
}
|
|
expect(nativeTitles, ['Display name', 'Profile description']);
|
|
expect(controller.selectedId, 'settings');
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
testWidgets(
|
|
'result destination keeps its list and closes detail before workspace',
|
|
(tester) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(900, 700);
|
|
addTearDown(tester.view.reset);
|
|
final navigator = GlobalKey<NavigatorState>();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
navigatorKey: navigator,
|
|
theme: AppTheme.light(),
|
|
home: const Scaffold(body: Text('Home')),
|
|
),
|
|
),
|
|
);
|
|
navigator.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => AdaptiveConversationDestination(
|
|
child: Builder(
|
|
builder: (context) => Scaffold(
|
|
body: Column(
|
|
children: [
|
|
const TextField(key: ValueKey('result-query')),
|
|
TextButton(
|
|
onPressed: () => openConversationPane(
|
|
context,
|
|
'result',
|
|
(_) => const _Conversation(),
|
|
),
|
|
child: const Text('Open result'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(
|
|
find.byKey(const ValueKey('result-query')),
|
|
'retained query',
|
|
);
|
|
await tester.tap(find.text('Open result'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('retained query'), findsOneWidget);
|
|
expect(find.byType(TextField), findsNWidgets(2));
|
|
tester.view.physicalSize = const Size(400, 700);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Open result'), findsNothing);
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Open result'), findsOneWidget);
|
|
expect(find.text('retained query'), findsOneWidget);
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Home'), findsOneWidget);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'selection, draft and thread survive compact and regular layouts',
|
|
(tester) async {
|
|
final controller = ConversationPaneController();
|
|
final active = ValueNotifier(true);
|
|
addTearDown(active.dispose);
|
|
addTearDown(controller.dispose);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(900, 700);
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: Scaffold(
|
|
body: ValueListenableBuilder<bool>(
|
|
valueListenable: active,
|
|
builder: (context, isActive, _) => AdaptiveConversationPane(
|
|
active: isActive,
|
|
controller: controller,
|
|
list: Builder(
|
|
builder: (context) => Column(
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => ConversationPaneScope.maybeOf(
|
|
context,
|
|
)!.open('one', (_) => const _Conversation()),
|
|
child: const Text('First chat'),
|
|
),
|
|
TextButton(
|
|
onPressed: () =>
|
|
ConversationPaneScope.maybeOf(context)!.open(
|
|
'two',
|
|
(_) => const Scaffold(
|
|
body: Text('Second conversation'),
|
|
),
|
|
),
|
|
child: const Text('Second chat'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('First chat'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getCenter(find.text('First chat')).dx,
|
|
lessThan(tester.getCenter(find.byType(TextField)).dx),
|
|
);
|
|
await tester.enterText(find.byType(TextField), 'Keep my draft');
|
|
active.value = false;
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Visible: false'), findsOneWidget);
|
|
active.value = true;
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Visible: true'), findsOneWidget);
|
|
tester.view.physicalSize = const Size(390, 700);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('First chat'), findsNothing);
|
|
expect(find.text('Keep my draft'), findsOneWidget);
|
|
await tester.tap(find.text('Thread'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Thread content'), findsOneWidget);
|
|
tester.view.physicalSize = const Size(900, 700);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('First chat'), findsOneWidget);
|
|
expect(find.text('Thread content'), findsOneWidget);
|
|
await tester.tap(find.byType(BackButton));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Keep my draft'), findsOneWidget);
|
|
await tester.tap(find.text('Second chat'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Second conversation'), findsOneWidget);
|
|
expect(controller.selectedId, 'two');
|
|
tester.view.physicalSize = const Size(390, 700);
|
|
await tester.pumpAndSettle();
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
expect(controller.selectedId, isNull);
|
|
expect(find.text('First chat'), findsOneWidget);
|
|
tester.view.physicalSize = const Size(900, 700);
|
|
await tester.pumpAndSettle();
|
|
final placeholder = find.text('Select a conversation');
|
|
expect(placeholder, findsOneWidget);
|
|
expect(
|
|
find.ancestor(of: placeholder, matching: find.byType(Material)),
|
|
findsWidgets,
|
|
);
|
|
expect(
|
|
tester.widget<Text>(placeholder).style!.decoration,
|
|
TextDecoration.none,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
|
|
testWidgets('iPhone back swipe and back button reveal the chat list', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(402, 874);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
var listTaps = 0;
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: Material(
|
|
child: Center(
|
|
child: TextButton(
|
|
onPressed: () => listTaps++,
|
|
child: const Text('Chat list'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final list = find.text('Chat list');
|
|
final placeholder = find.text('Select a conversation');
|
|
|
|
controller.open('chat', (_) => const _Conversation());
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(list, findsOneWidget, reason: 'the list stays beneath a push');
|
|
await tester.pumpAndSettle();
|
|
expect(list, findsNothing, reason: 'a settled chat covers the list');
|
|
|
|
final swipe = await tester.startGesture(const Offset(5, 400));
|
|
await swipe.moveBy(const Offset(100, 0));
|
|
await tester.pump();
|
|
await swipe.moveBy(const Offset(60, 0));
|
|
await tester.pump();
|
|
expect(list, findsOneWidget);
|
|
expect(placeholder, findsNothing);
|
|
expect(
|
|
tester.getSemantics(list.first),
|
|
isNot(matchesSemantics(label: 'Chat list')),
|
|
reason: 'the covered list is not a screen-reader stop',
|
|
);
|
|
// Cancelling the swipe settles the chat back over the list.
|
|
await swipe.moveBy(const Offset(-160, 0));
|
|
await swipe.up();
|
|
await tester.pumpAndSettle();
|
|
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;
|
|
});
|
|
|
|
group('compact keyboard', () {
|
|
Future<void> raiseKeyboard(WidgetTester tester) async {
|
|
for (var frame = 1; frame <= 20; frame++) {
|
|
tester.view.viewInsets = FakeViewPadding(bottom: frame * 15.0);
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
}
|
|
|
|
testWidgets('does not rebuild the covered list or detail routes', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(402, 874);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
var listBuilds = 0;
|
|
var channelBuilds = 0;
|
|
var threadBuilds = 0;
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: _CountedInsets('List', () => listBuilds++),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
controller.open(
|
|
'c',
|
|
(_) => _CountedSize('Channel', () => channelBuilds++),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
listBuilds = 0;
|
|
channelBuilds = 0;
|
|
|
|
await raiseKeyboard(tester);
|
|
|
|
expect(listBuilds, 0, reason: 'covered list');
|
|
expect(channelBuilds, 0, reason: 'channel detail');
|
|
|
|
Navigator.of(tester.element(find.text('Channel'))).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => _CountedSize('Thread', () => threadBuilds++),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
tester.view.viewInsets = FakeViewPadding.zero;
|
|
await tester.pump();
|
|
channelBuilds = 0;
|
|
threadBuilds = 0;
|
|
|
|
await raiseKeyboard(tester);
|
|
|
|
expect(threadBuilds, 0, reason: 'thread on top');
|
|
expect(channelBuilds, 0, reason: 'covered channel');
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
|
|
testWidgets('list keeps its insets while a popped detail keyboard lowers', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(402, 874);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
final listInsets = <double>[];
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: Builder(
|
|
builder: (context) {
|
|
listInsets.add(MediaQuery.viewInsetsOf(context).bottom);
|
|
return const Text('List');
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
controller.open(
|
|
'c',
|
|
(_) => const Material(
|
|
child: Column(
|
|
children: [Text('Channel'), TextField(autofocus: true)],
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
|
|
await tester.pump();
|
|
listInsets.clear();
|
|
|
|
Navigator.of(tester.element(find.text('Channel'))).pop();
|
|
await tester.pumpAndSettle();
|
|
for (var bottom = 280.0; bottom >= 0; bottom -= 40) {
|
|
tester.view.viewInsets = FakeViewPadding(bottom: bottom);
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
|
|
expect(listInsets.where((bottom) => bottom != 0), isEmpty);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
});
|
|
}
|
|
|
|
class _Conversation extends StatelessWidget {
|
|
const _Conversation();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Scaffold(
|
|
appBar: AppBar(title: const Text('Conversation')),
|
|
body: Column(
|
|
children: [
|
|
Text('Visible: ${ConversationPaneScope.isActiveOf(context)}'),
|
|
const TextField(),
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => Scaffold(
|
|
appBar: AppBar(),
|
|
body: const Text('Thread content'),
|
|
),
|
|
),
|
|
),
|
|
child: const Text('Thread'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class _DeepLink extends StatefulWidget {
|
|
const _DeepLink();
|
|
@override
|
|
State<_DeepLink> createState() => _DeepLinkState();
|
|
}
|
|
|
|
class _DeepLinkState extends State<_DeepLink> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => Scaffold(
|
|
appBar: AppBar(),
|
|
body: const Text('Deep-linked thread'),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
const Scaffold(body: Text('Selected channel'));
|
|
}
|
|
|
|
class _CountedInsets extends StatelessWidget {
|
|
const _CountedInsets(this.label, this.onBuild);
|
|
final String label;
|
|
final VoidCallback onBuild;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
onBuild();
|
|
MediaQuery.viewInsetsOf(context);
|
|
return Text(label);
|
|
}
|
|
}
|
|
|
|
class _CountedSize extends StatelessWidget {
|
|
const _CountedSize(this.label, this.onBuild);
|
|
final String label;
|
|
final VoidCallback onBuild;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
onBuild();
|
|
MediaQuery.sizeOf(context);
|
|
return Text(label);
|
|
}
|
|
}
|