e00c39aa5f
Flutter's safe area leaves out the window controls of a windowed iPad app, so they covered the list pane's title pill and took its taps. A small Runner plugin reports their corner from UIKit's corner-adapted safe-area regions over a method channel, and SegmentedBar pads the side they overlap. No-op off iOS and when there are no controls.
224 lines
6.8 KiB
Dart
224 lines
6.8 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
|
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
|
|
import 'package:pipelines_app/ui/adaptive/window_controls.dart';
|
|
|
|
/// Where UIKit put iPadOS 26.4's window controls in a window on the
|
|
/// simulator: safe area top 10, adapted left 66 and top 53.
|
|
const _controls = Rect.fromLTRB(0, 0, 66, 53);
|
|
|
|
void _window(WidgetTester tester, {double top = 10, double width = 800}) {
|
|
tester.view.physicalSize = Size(width, 700);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.padding = FakeViewPadding(top: top);
|
|
addTearDown(tester.view.reset);
|
|
}
|
|
|
|
SegmentedBar _bar({String title = 'Chat', List<Widget> actions = const []}) =>
|
|
SegmentedBar(cupertino: false, title: title, actions: actions);
|
|
|
|
Widget _page(SegmentedBar bar, {ValueListenable<Rect?>? controls}) {
|
|
final page = Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: bar,
|
|
body: const SizedBox.expand(),
|
|
);
|
|
return MaterialApp(
|
|
home: controls == null
|
|
? page
|
|
: WindowControlsScope(rect: controls, child: page),
|
|
);
|
|
}
|
|
|
|
double _titleLeft(WidgetTester tester) =>
|
|
tester.getTopLeft(find.byType(SegmentedTitlePill)).dx;
|
|
|
|
void main() {
|
|
testWidgets('without window controls the title pill keeps its margin', (
|
|
tester,
|
|
) async {
|
|
_window(tester);
|
|
await tester.pumpWidget(_page(_bar(), controls: ValueNotifier(null)));
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 12);
|
|
});
|
|
|
|
testWidgets('the title pill starts clear of the window controls', (
|
|
tester,
|
|
) async {
|
|
_window(tester);
|
|
await tester.pumpWidget(_page(_bar(), controls: ValueNotifier(_controls)));
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), _controls.right + 8);
|
|
// The pill keeps its height and row; only its leading edge moves.
|
|
expect(tester.getTopLeft(find.byType(SegmentedTitlePill)).dy, 18);
|
|
});
|
|
|
|
testWidgets('the clearance follows the controls as the window changes', (
|
|
tester,
|
|
) async {
|
|
_window(tester);
|
|
final controls = ValueNotifier<Rect?>(null);
|
|
await tester.pumpWidget(_page(_bar(), controls: controls));
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 12);
|
|
|
|
controls.value = _controls;
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 74);
|
|
|
|
// Back to full screen.
|
|
controls.value = null;
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 12);
|
|
});
|
|
|
|
testWidgets('controls above the bar (below the status bar) leave it be', (
|
|
tester,
|
|
) async {
|
|
_window(tester, top: 60);
|
|
await tester.pumpWidget(_page(_bar(), controls: ValueNotifier(_controls)));
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 12);
|
|
});
|
|
|
|
testWidgets('a bar away from the controls, such as a detail pane\'s, keeps '
|
|
'its margin', (tester) async {
|
|
_window(tester);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: WindowControlsScope(
|
|
rect: ValueNotifier(_controls),
|
|
child: Row(
|
|
children: [
|
|
const SizedBox(width: 300),
|
|
Expanded(
|
|
child: Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: _bar(title: 'Release notes'),
|
|
body: const SizedBox.expand(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 312);
|
|
});
|
|
|
|
testWidgets('controls at the trailing corner keep the actions clear', (
|
|
tester,
|
|
) async {
|
|
_window(tester);
|
|
const trailing = Rect.fromLTRB(734, 0, 800, 53);
|
|
await tester.pumpWidget(
|
|
_page(
|
|
_bar(
|
|
actions: [IconButton(onPressed: () {}, icon: const Icon(Icons.add))],
|
|
),
|
|
controls: ValueNotifier(trailing),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(_titleLeft(tester), 12);
|
|
expect(
|
|
tester.getTopRight(find.byIcon(Icons.add)).dx,
|
|
lessThanOrEqualTo(trailing.left - 8),
|
|
);
|
|
});
|
|
|
|
testWidgets('a pushed page\'s Back clears the controls once it has slid in', (
|
|
tester,
|
|
) async {
|
|
_window(tester);
|
|
final navigator = GlobalKey<NavigatorState>();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
navigatorKey: navigator,
|
|
builder: (context, child) =>
|
|
WindowControlsScope(rect: ValueNotifier(_controls), child: child!),
|
|
home: const SizedBox.expand(),
|
|
),
|
|
);
|
|
navigator.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: _bar(title: 'Release notes'),
|
|
body: const SizedBox.expand(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getTopLeft(find.byType(BackButton)).dx, greaterThan(66));
|
|
});
|
|
|
|
group('platform rect', () {
|
|
setUp(WindowControls.debugReset);
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(WindowControls.channel, null);
|
|
WindowControls.debugReset();
|
|
});
|
|
|
|
testWidgets(
|
|
'comes from the iOS host and follows its updates',
|
|
(tester) async {
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
messenger.setMockMethodCallHandler(WindowControls.channel, (
|
|
call,
|
|
) async {
|
|
expect(call.method, 'start');
|
|
return {'left': 0, 'top': 0, 'right': 66, 'bottom': 53};
|
|
});
|
|
late ValueListenable<Rect?> rect;
|
|
await tester.pumpWidget(
|
|
Builder(
|
|
builder: (context) {
|
|
rect = WindowControls.of(context);
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(rect.value, _controls);
|
|
|
|
// The host reports the window going full screen.
|
|
await messenger.handlePlatformMessage(
|
|
WindowControls.channel.name,
|
|
WindowControls.channel.codec.encodeMethodCall(
|
|
const MethodCall('changed'),
|
|
),
|
|
(_) {},
|
|
);
|
|
expect(rect.value, isNull);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
|
);
|
|
|
|
testWidgets(
|
|
'an iOS host without the plugin reports none',
|
|
(tester) async {
|
|
late ValueListenable<Rect?> rect;
|
|
await tester.pumpWidget(
|
|
Builder(
|
|
builder: (context) {
|
|
rect = WindowControls.of(context);
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(rect.value, isNull);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
|
);
|
|
});
|
|
}
|