Capture fixture: ?inset=top,bottom&fold=1 emulates Android insets and a fold
A browser reports no system insets, so inset-dependent layout (anchored menus) could not be captured on web. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import '../perf/backdrop_census.dart';
|
||||
import '../perf/chat_scroll_probe.dart';
|
||||
import '../perf/design_probe.dart';
|
||||
import '../perf/frame_log.dart';
|
||||
import 'inset_view.dart';
|
||||
|
||||
/// The fixture options: the page URL's query.
|
||||
Map<String, String> fixtureParams() => Uri.base.queryParameters;
|
||||
@@ -30,5 +31,26 @@ ServerEndpoint fixtureServer(Map<String, String> params) =>
|
||||
/// The browser's location is the route; no provider is needed.
|
||||
RouteInformationProvider? fixtureRouteProvider(String? route) => null;
|
||||
|
||||
/// Runs [app] unchanged.
|
||||
void runFixtureApp(Widget app, Map<String, String> params) => runApp(app);
|
||||
/// Runs [app], under an Android phone's system insets (and a fold) when
|
||||
/// `?inset=<top>,<bottom>` (and `&fold=1`) ask for them; see [InsetView].
|
||||
void runFixtureApp(Widget app, Map<String, String> params) {
|
||||
final inset = params['inset'];
|
||||
if (inset == null && params['fold'] != '1') {
|
||||
runApp(app);
|
||||
return;
|
||||
}
|
||||
final parts = (inset ?? '').split(',');
|
||||
final binding = WidgetsFlutterBinding.ensureInitialized();
|
||||
final view = binding.platformDispatcher.implicitView!;
|
||||
runWidget(
|
||||
View(
|
||||
view: InsetView(
|
||||
view,
|
||||
top: double.tryParse(parts.first) ?? 0,
|
||||
bottom: parts.length > 1 ? double.tryParse(parts[1]) ?? 0 : 0,
|
||||
fold: params['fold'] == '1',
|
||||
),
|
||||
child: app,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
/// The real view with an Android phone's system insets: a status bar
|
||||
/// [top] and a gesture bar [bottom] logical pixels tall, drawn over the app
|
||||
/// edge to edge, and with [fold] a vertical fold down the middle, as an
|
||||
/// unfolded foldable reports it. A browser always reports no insets, so this
|
||||
/// is how a capture sees inset-dependent layout (anchored menus, bars).
|
||||
///
|
||||
/// `?inset=52,24&fold=1` in the fixture URL.
|
||||
class InsetView implements ui.FlutterView {
|
||||
InsetView(this._view, {this.top = 0, this.bottom = 0, this.fold = false});
|
||||
|
||||
final ui.FlutterView _view;
|
||||
final double top;
|
||||
final double bottom;
|
||||
final bool fold;
|
||||
|
||||
ui.ViewPadding get _insets => _Padding(
|
||||
top: top * _view.devicePixelRatio,
|
||||
bottom: bottom * _view.devicePixelRatio,
|
||||
);
|
||||
|
||||
@override
|
||||
ui.Size get physicalSize => _view.physicalSize;
|
||||
|
||||
@override
|
||||
ui.ViewConstraints get physicalConstraints => _view.physicalConstraints;
|
||||
|
||||
@override
|
||||
int get viewId => _view.viewId;
|
||||
|
||||
@override
|
||||
ui.PlatformDispatcher get platformDispatcher => _view.platformDispatcher;
|
||||
|
||||
@override
|
||||
ui.Display get display => _view.display;
|
||||
|
||||
@override
|
||||
double get devicePixelRatio => _view.devicePixelRatio;
|
||||
|
||||
@override
|
||||
ui.ViewPadding get viewInsets => _view.viewInsets;
|
||||
|
||||
@override
|
||||
ui.ViewPadding get viewPadding => _insets;
|
||||
|
||||
@override
|
||||
ui.ViewPadding get systemGestureInsets => _view.systemGestureInsets;
|
||||
|
||||
@override
|
||||
ui.ViewPadding get padding => _insets;
|
||||
|
||||
@override
|
||||
ui.GestureSettings get gestureSettings => _view.gestureSettings;
|
||||
|
||||
@override
|
||||
List<ui.DisplayFeature> get displayFeatures {
|
||||
if (!fold) return _view.displayFeatures;
|
||||
final size = _view.physicalSize;
|
||||
return [
|
||||
ui.DisplayFeature(
|
||||
bounds: ui.Rect.fromLTWH(size.width / 2, 0, 0, size.height),
|
||||
type: ui.DisplayFeatureType.fold,
|
||||
state: ui.DisplayFeatureState.postureFlat,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
ui.DisplayCornerRadii? get displayCornerRadii => _view.displayCornerRadii;
|
||||
|
||||
@override
|
||||
void render(ui.Scene scene, {ui.Size? size}) =>
|
||||
_view.render(scene, size: size);
|
||||
|
||||
@override
|
||||
void updateSemantics(ui.SemanticsUpdate update) =>
|
||||
_view.updateSemantics(update);
|
||||
}
|
||||
|
||||
class _Padding implements ui.ViewPadding {
|
||||
const _Padding({required this.top, required this.bottom});
|
||||
|
||||
@override
|
||||
final double top;
|
||||
@override
|
||||
final double bottom;
|
||||
@override
|
||||
double get left => 0;
|
||||
@override
|
||||
double get right => 0;
|
||||
}
|
||||
Reference in New Issue
Block a user