Merge branch 'fix/mobile-motion'
This commit is contained in:
@@ -75,24 +75,35 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(listTop(tester), 8);
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) => widget is EditableText && !widget.readOnly,
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byType(EditableText, skipOffstage: false), findsWidgets);
|
||||
expect(find.text('Message 0'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a leaving bar fades in place, keeping the list clear', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, peek: true, reveal: .4);
|
||||
expect(header, findsOneWidget);
|
||||
expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5));
|
||||
final fade = tester.widget<FadeTransition>(
|
||||
find.ancestor(of: header, matching: find.byType(FadeTransition)).first,
|
||||
);
|
||||
expect(fade.opacity.value, .4);
|
||||
expect(
|
||||
find.ancestor(of: header, matching: find.byType(IgnorePointer)),
|
||||
findsWidgets,
|
||||
);
|
||||
});
|
||||
testWidgets(
|
||||
'leaving controls fade and release their viewport height smoothly',
|
||||
(tester) async {
|
||||
await _pump(tester, peek: true, reveal: .4);
|
||||
expect(header, findsOneWidget);
|
||||
expect(
|
||||
listTop(tester),
|
||||
closeTo(tester.getSize(header).height * .4 + 8, .5),
|
||||
);
|
||||
final fade = tester.widget<FadeTransition>(
|
||||
find.ancestor(of: header, matching: find.byType(FadeTransition)).first,
|
||||
);
|
||||
expect(fade.opacity.value, .4);
|
||||
expect(
|
||||
find.ancestor(of: header, matching: find.byType(IgnorePointer)),
|
||||
findsWidgets,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('without a presentation the bar is itself', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
@@ -115,7 +126,13 @@ void main() {
|
||||
expect(header, findsOneWidget);
|
||||
Widget? child;
|
||||
tester
|
||||
.element(find.byType(ChatPaneBarReveal))
|
||||
.element(
|
||||
find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is ChatPaneBarReveal &&
|
||||
widget.bar.key == const Key('chat-thread-header'),
|
||||
),
|
||||
)
|
||||
.visitChildren((element) => child = element.widget);
|
||||
expect(child?.key, const Key('chat-thread-header'));
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -123,212 +121,99 @@ class _Thread extends StatelessWidget {
|
||||
|
||||
const _top = (800 - 6) * .8;
|
||||
const _peekTop = _top + 6;
|
||||
final _duration = ChatPaneSwitchMotion.duration.inMilliseconds;
|
||||
|
||||
/// The rise's progress [ms] into a switch (1 once the chat has arrived).
|
||||
double _rise(int ms) => ChatPaneSwitchMotion.curve.transform(
|
||||
math.min(1, ms / _duration / ChatPaneSwitchMotion.riseShare),
|
||||
);
|
||||
|
||||
/// The settle's progress [ms] into a switch (0 until the chat has arrived).
|
||||
double _settle(int ms) => ChatPaneSwitchMotion.curve.transform(
|
||||
math.max(
|
||||
0,
|
||||
(ms / _duration - ChatPaneSwitchMotion.riseShare) /
|
||||
(1 - ChatPaneSwitchMotion.riseShare),
|
||||
),
|
||||
);
|
||||
Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
|
||||
Finder rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
|
||||
void main() {
|
||||
void phone(WidgetTester tester) {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'active chat travels to the top on the switch curve with a stable thread layout',
|
||||
'one eased swap moves both panes, interruptions retain draft and reveal',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
addTearDown(tester.view.reset);
|
||||
phone(tester);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final first = controller.activePaneId!;
|
||||
final a = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final second = controller.activePaneId!;
|
||||
controller.resize(controller.root!.id, .31);
|
||||
final saved = controller.snapshot()!.encode();
|
||||
final b = controller.activePaneId!;
|
||||
await tester.pumpWidget(_host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final aState = tester.state(find.byKey(const ValueKey('a')));
|
||||
final bState = tester.state(find.byKey(const ValueKey('b')));
|
||||
await tester.enterText(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
'Draft b',
|
||||
);
|
||||
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .2, 1));
|
||||
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
|
||||
expect(tester.getSize(_rect(second)).height, closeTo(_top, 1));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
|
||||
expect(
|
||||
controller.activePane?.sessionId,
|
||||
'a',
|
||||
reason: 'tap activates immediately',
|
||||
);
|
||||
// The switch starts where the panes are: the tapped chat rises over
|
||||
// the other, which stays put until covered.
|
||||
final aState = tester.state<_DraftState>(find.byKey(const ValueKey('a')));
|
||||
final bState = tester.state<_DraftState>(find.byKey(const ValueKey('b')));
|
||||
bState.controller.text = 'Retained draft';
|
||||
controller.activate(a);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
|
||||
expect(tester.getRect(_rect(second)).top, 0);
|
||||
final aLayouts = (aState as _DraftState).layouts;
|
||||
final bLayouts = (bState as _DraftState).layouts;
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
final firstTop = tester.getRect(_rect(first)).top;
|
||||
expect(firstTop, closeTo(_peekTop * (1 - _rise(60)), 1));
|
||||
expect(tester.getRect(_rect(first)).bottom, 800);
|
||||
expect(
|
||||
tester.getRect(_rect(second)),
|
||||
const Offset(0, 0) & const Size(560, _top),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
expect(tester.getRect(_rect(first)).top, lessThan(firstTop));
|
||||
expect(
|
||||
tester.getRect(_rect(first)).top,
|
||||
closeTo(_peekTop * (1 - _rise(120)), 1),
|
||||
);
|
||||
expect(tester.getRect(_rect(second)).top, 0);
|
||||
// The run only composites retained content: neither transcript nor
|
||||
// composer receives a new size on any tick.
|
||||
await tester.pump(const Duration(milliseconds: 90));
|
||||
final t = ChatPaneSwitchMotion.curve.transform(.25);
|
||||
expect(tester.getRect(rect(a)).top, closeTo(_peekTop * (1 - t), .5));
|
||||
expect(tester.getRect(rect(b)).top, closeTo(_peekTop * t, .5));
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('a'))).height,
|
||||
closeTo(_top, 1),
|
||||
closeTo(tester.getRect(rect(a)).height, .5),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||
closeTo(_top, 1),
|
||||
);
|
||||
expect(aState.layouts, aLayouts);
|
||||
expect(bState.layouts, bLayouts);
|
||||
// Arrived: the covered chat slides up into the slot from the bottom.
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
expect(tester.getRect(_rect(first)).top, 0);
|
||||
expect(tester.getSize(_rect(first)).height, closeTo(_top, 1));
|
||||
final secondTop = tester.getRect(_rect(second)).top;
|
||||
expect(secondTop, inExclusiveRange(_peekTop, 800));
|
||||
expect(secondTop, closeTo(800 - (800 - _peekTop) * _settle(200), 1));
|
||||
expect(tester.getSize(_rect(second)).height, closeTo(800 - _peekTop, 1));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(tester.getRect(_rect(second)).top, closeTo(_peekTop, 1));
|
||||
expect(aState.layouts, aLayouts);
|
||||
expect(bState.layouts, bLayouts);
|
||||
final beforeA = tester.getRect(rect(a));
|
||||
final beforeB = tester.getRect(rect(b));
|
||||
double reveal(String session) => tester
|
||||
.widget<ChatPanePresentation>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byKey(ValueKey(session)),
|
||||
matching: find.byType(ChatPanePresentation),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.barReveal
|
||||
.value;
|
||||
final bar = reveal('a');
|
||||
controller.activate(b);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(rect(a)), beforeA);
|
||||
expect(tester.getRect(rect(b)), beforeB);
|
||||
expect(reveal('a'), closeTo(bar, .001));
|
||||
await tester.pump(const Duration(milliseconds: 90));
|
||||
expect(tester.getRect(rect(a)).top, greaterThan(beforeA.top));
|
||||
expect(reveal('a'), lessThan(bar));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
expect(tester.getRect(rect(a)).top, _peekTop);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('a'))).height,
|
||||
closeTo((800 - 6) * .2, .5),
|
||||
);
|
||||
expect(tester.state(find.byKey(const ValueKey('a'))), same(aState));
|
||||
expect(tester.state(find.byKey(const ValueKey('b'))), same(bState));
|
||||
expect(bState.controller.text, 'Draft b');
|
||||
expect(
|
||||
tester
|
||||
.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
)
|
||||
.focusNode
|
||||
.hasFocus,
|
||||
isFalse,
|
||||
);
|
||||
// A switch that interrupts another continues from where the panes are:
|
||||
// the rising chat returns to the slot while the covered one stays.
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$second')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
final interrupted = tester.getRect(_rect(second)).top;
|
||||
expect(interrupted, inExclusiveRange(0, _peekTop));
|
||||
controller.activate(first);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(_rect(second)).top, closeTo(interrupted, 1));
|
||||
expect(tester.getRect(_rect(first)).top, 0);
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
expect(
|
||||
tester.getRect(_rect(second)).top,
|
||||
inExclusiveRange(interrupted, _peekTop),
|
||||
);
|
||||
expect(tester.getRect(_rect(first)).top, 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(_rect(second)).top, closeTo(_peekTop, 1));
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$second')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(_rect(second)).top, 0);
|
||||
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
|
||||
expect(controller.snapshot()!.encode(), saved);
|
||||
await tester.pumpWidget(_host(controller, mobile: false));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.state(find.byKey(const ValueKey('a'))), same(aState));
|
||||
expect(
|
||||
tester.getSize(_rect(first)).width,
|
||||
lessThan(tester.getSize(_rect(second)).width),
|
||||
);
|
||||
expect(bState.controller.text, 'Retained draft');
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('reduced motion settles immediately', (tester) async {
|
||||
phone(tester);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final a = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final b = controller.activePaneId!;
|
||||
await tester.pumpWidget(_host(controller, reduced: true));
|
||||
controller.activate(a);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(rect(a)).top, 0);
|
||||
expect(tester.getRect(rect(b)).top, _peekTop);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
});
|
||||
testWidgets(
|
||||
'three retained panes expose active+previous and honor reduced motion',
|
||||
'peek uses visible viewport, reaches final row and retains reading offset',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final first = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
controller.splitActive('c', ChatSplitAxis.vertical);
|
||||
await tester.pumpWidget(_host(controller, reduced: true));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(_Draft), findsNWidgets(2));
|
||||
final third = controller.activePaneId!;
|
||||
controller.activate(first);
|
||||
await tester.pump();
|
||||
// Reduced motion: the panes take their places at once.
|
||||
expect(tester.getSize(_rect(first)).height, closeTo(_top, 1));
|
||||
expect(tester.getRect(_rect(first)).top, 0);
|
||||
expect(tester.getRect(_rect(third)).top, closeTo(_peekTop, 1));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(tester.getRect(_rect(first)).top, 0);
|
||||
expect(tester.getRect(_rect(third)).top, closeTo(_peekTop, 1));
|
||||
expect(find.byType(_Draft), findsNWidgets(2));
|
||||
expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3));
|
||||
controller.activate(third);
|
||||
await tester.pump();
|
||||
expect(tester.getSize(_rect(third)).height, closeTo(_top, 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'peek shows its transcript from the top, scrolls under a drag and opens on a tap',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
phone(tester);
|
||||
final scrolls = {'a': ScrollController(), 'b': ScrollController()};
|
||||
addTearDown(() {
|
||||
for (final scroll in scrolls.values) {
|
||||
scroll.dispose();
|
||||
}
|
||||
});
|
||||
final pressed = <String>[];
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final first = controller.activePaneId!;
|
||||
final a = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final second = controller.activePaneId!;
|
||||
Finder bar(String id) => find.byKey(ValueKey('bar-$id'));
|
||||
final b = controller.activePaneId!;
|
||||
var pressed = 0;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
controller,
|
||||
@@ -336,88 +221,45 @@ void main() {
|
||||
key: ValueKey(pane.sessionId),
|
||||
id: pane.sessionId,
|
||||
scroll: scrolls[pane.sessionId]!,
|
||||
onPressed: () => pressed.add(pane.sessionId),
|
||||
onPressed: () => pressed++,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
// The active chat keeps its bar and its list clear of it; the peek has
|
||||
// no bar and its list starts at the pane's top edge.
|
||||
expect(bar('b'), findsOneWidget);
|
||||
expect(bar('a'), findsNothing);
|
||||
final peek = tester.getRect(rect(a));
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
|
||||
tester.getRect(_rect(second)).top + 48,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('row-a-0'))).top,
|
||||
tester.getRect(_rect(first)).top,
|
||||
);
|
||||
// A drag scrolls the peek's list without opening it.
|
||||
await tester.drag(
|
||||
find.byKey(ValueKey('chat-peek-$first')),
|
||||
const Offset(0, -40),
|
||||
scrolls['a']!.position.viewportDimension,
|
||||
closeTo(peek.height, .5),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('bar-a')), findsNothing);
|
||||
await tester.dragFrom(peek.center, const Offset(0, -90));
|
||||
await tester.pumpAndSettle();
|
||||
expect(scrolls['a']!.offset, greaterThan(0));
|
||||
expect(controller.activePane?.sessionId, 'b');
|
||||
// A tap, even on a button inside, opens the chat and presses nothing.
|
||||
await tester.tap(find.byKey(const ValueKey('button-a')));
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
expect(pressed, isEmpty);
|
||||
await tester.pump();
|
||||
// During the rise the leaving bar fades out in place (its list moves
|
||||
// only once covered) and the arriving bar fades in over a list that
|
||||
// already keeps clear of it.
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
expect(bar('b'), findsOneWidget);
|
||||
expect(bar('a'), findsOneWidget);
|
||||
double opacity(String id) => tester
|
||||
.widget<FadeTransition>(
|
||||
find
|
||||
.ancestor(of: bar(id), matching: find.byType(FadeTransition))
|
||||
.first,
|
||||
)
|
||||
.opacity
|
||||
.value;
|
||||
expect(opacity('b'), inExclusiveRange(0, 1));
|
||||
expect(opacity('a'), inExclusiveRange(0, 1));
|
||||
expect(opacity('a'), closeTo(1 - opacity('b'), .001));
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
|
||||
tester.getRect(_rect(second)).top + 48,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('row-a-0'))).top,
|
||||
tester.getRect(_rect(first)).top + 48 - scrolls['a']!.offset,
|
||||
);
|
||||
expect(controller.activePaneId, b);
|
||||
scrolls['a']!.jumpTo(scrolls['a']!.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(bar('a'), findsOneWidget);
|
||||
expect(bar('b'), findsNothing);
|
||||
expect(opacity('a'), 1);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
|
||||
tester.getRect(_rect(second)).top,
|
||||
);
|
||||
// The active chat's button still works.
|
||||
await tester.tap(find.byKey(const ValueKey('button-a')));
|
||||
final last = tester.getRect(find.byKey(const ValueKey('row-a-39')));
|
||||
expect(last.bottom, closeTo(peek.bottom, .5));
|
||||
expect(last.top, greaterThanOrEqualTo(peek.top));
|
||||
scrolls['a']!.jumpTo(300);
|
||||
await tester.pump();
|
||||
expect(pressed, ['a']);
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pump();
|
||||
final peek = find.byKey(ValueKey('chat-peek-$second'));
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$a')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.activePaneId, a);
|
||||
expect(scrolls['a']!.offset, 300);
|
||||
controller.activate(b);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scrolls['a']!.offset, 300);
|
||||
expect(
|
||||
tester.getSemantics(peek),
|
||||
matchesSemantics(
|
||||
identifier: 'chat-peek-$second',
|
||||
label: 'Expand b',
|
||||
isButton: true,
|
||||
hasTapAction: true,
|
||||
),
|
||||
scrolls['a']!.position.viewportDimension,
|
||||
closeTo(peek.height, .5),
|
||||
);
|
||||
semantics.dispose();
|
||||
expect(pressed, 0);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
for (final scroll in scrolls.values) {
|
||||
scroll.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user