Skip to content

Commit b4019f9

Browse files
authored
Reland "Remove single view assumption from TestViewConfiguration (#122352)" (#122414)
Reland "Remove single view assumption from TestViewConfiguration (#122352)"
1 parent e078c93 commit b4019f9

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ Future<void> main() async {
3131
await tester.pump(); // Start drawer animation
3232
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
3333

34-
final TestViewConfiguration big = TestViewConfiguration(
34+
final TestViewConfiguration big = TestViewConfiguration.fromView(
3535
size: const Size(360.0, 640.0),
36-
window: RendererBinding.instance.window,
36+
view: RendererBinding.instance.window,
3737
);
38-
final TestViewConfiguration small = TestViewConfiguration(
38+
final TestViewConfiguration small = TestViewConfiguration.fromView(
3939
size: const Size(355.0, 635.0),
40-
window: RendererBinding.instance.window,
40+
view: RendererBinding.instance.window,
4141
);
4242
final RenderView renderView = WidgetsBinding.instance.renderView;
4343
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;

packages/flutter_test/lib/src/binding.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,9 +1912,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
19121912

19131913
@override
19141914
ViewConfiguration createViewConfiguration() {
1915-
return TestViewConfiguration(
1915+
return TestViewConfiguration.fromView(
19161916
size: _surfaceSize ?? _kDefaultTestViewportSize,
1917-
window: window,
1917+
view: window,
19181918
);
19191919
}
19201920

@@ -1938,20 +1938,31 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
19381938
/// size is in logical pixels. The resulting ViewConfiguration maps the given
19391939
/// size onto the actual display using the [BoxFit.contain] algorithm.
19401940
class TestViewConfiguration extends ViewConfiguration {
1941-
/// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600.
1941+
/// Deprecated. Will be removed in a future version of Flutter.
1942+
///
1943+
/// This property has been deprecated to prepare for Flutter's upcoming
1944+
/// support for multiple views and multiple windows.
19421945
///
1943-
/// If a [window] instance is not provided it defaults to [ui.window].
1946+
/// Use [TestViewConfiguration.fromView] instead.
1947+
@Deprecated(
1948+
'Use TestViewConfiguration.fromView instead. '
1949+
'Deprecated to prepare for the upcoming multi-window support. '
1950+
'This feature was deprecated after v3.7.0-32.0.pre.'
1951+
)
19441952
factory TestViewConfiguration({
19451953
Size size = _kDefaultTestViewportSize,
19461954
ui.FlutterView? window,
19471955
}) {
1948-
return TestViewConfiguration._(size, window ?? ui.window);
1956+
return TestViewConfiguration.fromView(size: size, view: window ?? ui.window);
19491957
}
19501958

1951-
TestViewConfiguration._(Size size, ui.FlutterView window)
1952-
: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
1953-
_hitTestMatrix = _getMatrix(size, 1.0, window),
1954-
super(size: size, devicePixelRatio: window.devicePixelRatio);
1959+
/// Creates a [TestViewConfiguration] with the given size and view.
1960+
///
1961+
/// The [size] defaults to 800x600.
1962+
TestViewConfiguration.fromView({required ui.FlutterView view, super.size = _kDefaultTestViewportSize})
1963+
: _paintMatrix = _getMatrix(size, view.devicePixelRatio, view),
1964+
_hitTestMatrix = _getMatrix(size, 1.0, view),
1965+
super(devicePixelRatio: view.devicePixelRatio);
19551966

19561967
static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
19571968
final double inverseRatio = devicePixelRatio / window.devicePixelRatio;

packages/integration_test/lib/integration_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
120120
ViewConfiguration createViewConfiguration() {
121121
final double devicePixelRatio = window.devicePixelRatio;
122122
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio;
123-
return TestViewConfiguration(
123+
return TestViewConfiguration.fromView(
124124
size: size,
125-
window: window,
125+
view: window,
126126
);
127127
}
128128

0 commit comments

Comments
 (0)