Skip to content

Commit d24c01b

Browse files
authored
Revert "Dynamic view sizing" (#140165)
Reverts #138648 This caused the app to be stuck in the splash screen on certain phone models. Context: b/316244317
1 parent f8ddd4b commit d24c01b

16 files changed

+43
-291
lines changed

packages/flutter/lib/src/rendering/binding.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
350350
final FlutterView view = renderView.flutterView;
351351
final double devicePixelRatio = view.devicePixelRatio;
352352
return ViewConfiguration(
353-
constraints: view.physicalConstraints / devicePixelRatio,
353+
size: view.physicalSize / devicePixelRatio,
354354
devicePixelRatio: devicePixelRatio,
355355
);
356356
}

packages/flutter/lib/src/rendering/box.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:math' as math;
6-
import 'dart:ui' as ui show ViewConstraints, lerpDouble;
6+
import 'dart:ui' as ui show lerpDouble;
77

88
import 'package:flutter/foundation.dart';
99
import 'package:flutter/gestures.dart';
@@ -153,13 +153,6 @@ class BoxConstraints extends Constraints {
153153
minHeight = height ?? double.infinity,
154154
maxHeight = height ?? double.infinity;
155155

156-
/// Creates box constraints that match the given view constraints.
157-
BoxConstraints.fromViewConstraints(ui.ViewConstraints constraints)
158-
: minWidth = constraints.minWidth,
159-
maxWidth = constraints.maxWidth,
160-
minHeight = constraints.minHeight,
161-
maxHeight = constraints.maxHeight;
162-
163156
/// The minimum width that satisfies the constraints.
164157
final double minWidth;
165158

packages/flutter/lib/src/rendering/view.dart

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:io' show Platform;
6-
import 'dart:ui' as ui show FlutterView, Scene, SceneBuilder, SemanticsUpdate, ViewConstraints;
6+
import 'dart:ui' as ui show FlutterView, Scene, SceneBuilder, SemanticsUpdate;
77

88
import 'package:flutter/foundation.dart';
99
import 'package:flutter/services.dart';
@@ -19,15 +19,14 @@ import 'object.dart';
1919
class ViewConfiguration {
2020
/// Creates a view configuration.
2121
///
22-
/// By default, the view has [ViewConstraints] with all dimensions set to zero
23-
/// (i.e. the view is forced to [Size.zero]) and a [devicePixelRatio] of 1.0.
22+
/// By default, the view has zero [size] and a [devicePixelRatio] of 1.0.
2423
const ViewConfiguration({
25-
this.constraints = const ui.ViewConstraints(maxWidth: 0.0, maxHeight: 0.0),
24+
this.size = Size.zero,
2625
this.devicePixelRatio = 1.0,
2726
});
2827

29-
/// The constraints of the output surface in logical pixel.
30-
final ui.ViewConstraints constraints;
28+
/// The size of the output surface.
29+
final Size size;
3130

3231
/// The pixel density of the output surface.
3332
final double devicePixelRatio;
@@ -41,34 +40,21 @@ class ViewConfiguration {
4140
return Matrix4.diagonal3Values(devicePixelRatio, devicePixelRatio, 1.0);
4241
}
4342

44-
/// Transforms the provided [Size] in logical pixels to physical pixels.
45-
///
46-
/// The [FlutterView.render] method accepts only sizes in physical pixels,
47-
/// but the framework operates in logical pixels. This method is used to
48-
/// transform the logical size calculated for a [RenderView] back to a
49-
/// physical size suitable to be passed to [FlutterView.render].
50-
///
51-
/// By default, this method just multiplies the provided [Size] with the
52-
/// [devicePixelRatio].
53-
Size toPhysicalSize(Size logicalSize) {
54-
return logicalSize * devicePixelRatio;
55-
}
56-
5743
@override
5844
bool operator ==(Object other) {
5945
if (other.runtimeType != runtimeType) {
6046
return false;
6147
}
6248
return other is ViewConfiguration
63-
&& other.constraints == constraints
49+
&& other.size == size
6450
&& other.devicePixelRatio == devicePixelRatio;
6551
}
6652

6753
@override
68-
int get hashCode => Object.hash(constraints, devicePixelRatio);
54+
int get hashCode => Object.hash(size, devicePixelRatio);
6955

7056
@override
71-
String toString() => '$constraints at ${debugFormatDouble(devicePixelRatio)}x';
57+
String toString() => '$size at ${debugFormatDouble(devicePixelRatio)}x';
7258
}
7359

7460
/// The root of the render tree.
@@ -90,10 +76,8 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
9076
RenderBox? child,
9177
ViewConfiguration? configuration,
9278
required ui.FlutterView view,
93-
}) : _view = view {
94-
if (configuration != null) {
95-
this.configuration = configuration;
96-
}
79+
}) : _configuration = configuration,
80+
_view = view {
9781
this.child = child;
9882
}
9983

@@ -121,7 +105,6 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
121105
}
122106
final ViewConfiguration? oldConfiguration = _configuration;
123107
_configuration = value;
124-
_constraints = BoxConstraints.fromViewConstraints(configuration.constraints);
125108
if (_rootTransform == null) {
126109
// [prepareInitialFrame] has not been called yet, nothing to do for now.
127110
return;
@@ -136,15 +119,6 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
136119
/// Whether a [configuration] has been set.
137120
bool get hasConfiguration => _configuration != null;
138121

139-
@override
140-
BoxConstraints get constraints {
141-
if (_constraints == null) {
142-
throw StateError('Constraints are not available because RenderView has not been given a configuration yet.');
143-
}
144-
return _constraints!;
145-
}
146-
BoxConstraints? _constraints;
147-
148122
/// The [FlutterView] into which this [RenderView] will render.
149123
ui.FlutterView get flutterView => _view;
150124
final ui.FlutterView _view;
@@ -214,13 +188,12 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
214188
@override
215189
void performLayout() {
216190
assert(_rootTransform != null);
217-
final bool sizedByChild = !constraints.isTight;
191+
_size = configuration.size;
192+
assert(_size.isFinite);
193+
218194
if (child != null) {
219-
child!.layout(constraints, parentUsesSize: sizedByChild);
195+
child!.layout(BoxConstraints.tight(_size));
220196
}
221-
_size = sizedByChild && child != null ? child!.size : constraints.smallest;
222-
assert(size.isFinite);
223-
assert(constraints.isSatisfiedBy(size));
224197
}
225198

226199
/// Determines the set of render objects located at the given position.
@@ -280,8 +253,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
280253
if (automaticSystemUiAdjustment) {
281254
_updateSystemChrome();
282255
}
283-
assert(configuration.constraints.isSatisfiedBy(size));
284-
_view.render(scene, size: configuration.toPhysicalSize(size));
256+
_view.render(scene);
285257
scene.dispose();
286258
assert(() {
287259
if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled) {

packages/flutter/test/foundation/service_extensions_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ void main() {
259259
r' debug mode enabled - [a-zA-Z]+\n'
260260
r' view size: Size\(2400\.0, 1800\.0\) \(in physical pixels\)\n'
261261
r' device pixel ratio: 3\.0 \(physical pixels per logical pixel\)\n'
262-
r' configuration: ViewConstraints\(w=800\.0, h=600\.0\) at 3\.0x \(in\n'
263-
r' logical pixels\)\n'
262+
r' configuration: Size\(800\.0, 600\.0\) at 3\.0x \(in logical pixels\)\n'
264263
r'$',
265264
),
266265
});

packages/flutter/test/rendering/box_constraints_test.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:ui';
6-
75
import 'package:flutter/rendering.dart';
86
import 'package:flutter_test/flutter_test.dart';
97

@@ -169,17 +167,4 @@ void main() {
169167
expect(copy.minHeight, 11.0);
170168
expect(copy.maxHeight, 18.0);
171169
});
172-
173-
test('BoxConstraints.fromViewConstraints', () {
174-
final BoxConstraints unconstrained = BoxConstraints.fromViewConstraints(
175-
const ViewConstraints(),
176-
);
177-
expect(unconstrained, const BoxConstraints());
178-
179-
final BoxConstraints constraints = BoxConstraints.fromViewConstraints(
180-
const ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4),
181-
);
182-
expect(constraints, const BoxConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4));
183-
});
184-
185170
}

packages/flutter/test/rendering/independent_layout_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:ui' show ViewConstraints;
6-
75
import 'package:flutter/rendering.dart';
86
import 'package:flutter_test/flutter_test.dart';
97

@@ -34,8 +32,8 @@ class TestLayout {
3432
void main() {
3533
TestRenderingFlutterBinding.ensureInitialized();
3634

37-
final ViewConfiguration testConfiguration = ViewConfiguration(
38-
constraints: ViewConstraints.tight(const Size(800.0, 600.0)),
35+
const ViewConfiguration testConfiguration = ViewConfiguration(
36+
size: Size(800.0, 600.0),
3937
);
4038

4139
test('onscreen layout does not affect offscreen', () {

packages/flutter/test/rendering/multi_view_binding_test.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818
binding.addRenderView(view);
1919
expect(binding.renderViews, contains(view));
2020
expect(view.configuration.devicePixelRatio, flutterView.devicePixelRatio);
21-
expect(view.configuration.constraints, ViewConstraints.tight(flutterView.physicalSize) / flutterView.devicePixelRatio);
21+
expect(view.configuration.size, flutterView.physicalSize / flutterView.devicePixelRatio);
2222

2323
binding.removeRenderView(view);
2424
expect(binding.renderViews, isEmpty);
@@ -51,17 +51,13 @@ void main() {
5151
final RenderView view = RenderView(view: flutterView);
5252
binding.addRenderView(view);
5353
expect(view.configuration.devicePixelRatio, 2.5);
54-
expect(view.configuration.constraints.isTight, isTrue);
55-
expect(view.configuration.constraints.minWidth, 160.0);
56-
expect(view.configuration.constraints.minHeight, 240.0);
54+
expect(view.configuration.size, const Size(160.0, 240.0));
5755

5856
flutterView.devicePixelRatio = 3.0;
5957
flutterView.physicalSize = const Size(300, 300);
6058
binding.handleMetricsChanged();
6159
expect(view.configuration.devicePixelRatio, 3.0);
62-
expect(view.configuration.constraints.isTight, isTrue);
63-
expect(view.configuration.constraints.minWidth, 100.0);
64-
expect(view.configuration.constraints.minHeight, 100.0);
60+
expect(view.configuration.size, const Size(100.0, 100.0));
6561

6662
binding.removeRenderView(view);
6763
});
@@ -187,8 +183,6 @@ class FakeFlutterView extends Fake implements FlutterView {
187183
@override
188184
Size physicalSize;
189185
@override
190-
ViewConstraints get physicalConstraints => ViewConstraints.tight(physicalSize);
191-
@override
192186
ViewPadding padding;
193187

194188
List<Scene> renderedScenes = <Scene>[];

packages/flutter/test/rendering/view_test.dart

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:ui' show ViewConstraints;
6-
75
import 'package:flutter/rendering.dart';
86
import 'package:flutter_test/flutter_test.dart';
97

@@ -18,14 +16,14 @@ void main() {
1816
Size size = const Size(20, 20),
1917
double devicePixelRatio = 2.0,
2018
}) {
21-
return ViewConfiguration(constraints: ViewConstraints.tight(size), devicePixelRatio: devicePixelRatio);
19+
return ViewConfiguration(size: size, devicePixelRatio: devicePixelRatio);
2220
}
2321

2422
group('RenderView', () {
2523
test('accounts for device pixel ratio in paintBounds', () {
2624
layout(RenderAspectRatio(aspectRatio: 1.0));
2725
pumpFrame();
28-
final Size logicalSize = TestRenderingFlutterBinding.instance.renderView.size;
26+
final Size logicalSize = TestRenderingFlutterBinding.instance.renderView.configuration.size;
2927
final double devicePixelRatio = TestRenderingFlutterBinding.instance.renderView.configuration.devicePixelRatio;
3028
final Size physicalSize = logicalSize * devicePixelRatio;
3129
expect(TestRenderingFlutterBinding.instance.renderView.paintBounds, Offset.zero & physicalSize);
@@ -128,38 +126,11 @@ void main() {
128126
final RenderView view = RenderView(
129127
view: RendererBinding.instance.platformDispatcher.views.single,
130128
);
131-
view.configuration = ViewConfiguration(constraints: ViewConstraints.tight(const Size(100, 200)), devicePixelRatio: 3.0);
132-
view.configuration = ViewConfiguration(constraints: ViewConstraints.tight(const Size(200, 300)), devicePixelRatio: 2.0);
129+
view.configuration = const ViewConfiguration(size: Size(100, 200), devicePixelRatio: 3.0);
130+
view.configuration = const ViewConfiguration(size: Size(200, 300), devicePixelRatio: 2.0);
133131
PipelineOwner().rootNode = view;
134132
view.prepareInitialFrame();
135133
});
136-
137-
test('Constraints are derived from configuration', () {
138-
const ViewConfiguration config = ViewConfiguration(
139-
constraints: ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4),
140-
devicePixelRatio: 3.0,
141-
);
142-
const BoxConstraints constraints = BoxConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4);
143-
144-
// Configuration set via setter.
145-
final RenderView view = RenderView(
146-
view: RendererBinding.instance.platformDispatcher.views.single,
147-
);
148-
expect(() => view.constraints, throwsA(isA<StateError>().having(
149-
(StateError e) => e.message,
150-
'message',
151-
contains('RenderView has not been given a configuration yet'),
152-
)));
153-
view.configuration = config;
154-
expect(view.constraints, constraints);
155-
156-
// Configuration set in constructor.
157-
final RenderView view2 = RenderView(
158-
view: RendererBinding.instance.platformDispatcher.views.single,
159-
configuration: config,
160-
);
161-
expect(view2.constraints, constraints);
162-
});
163134
}
164135

165136
const Color orange = Color(0xFFFF9000);

packages/flutter/test/widgets/independent_widget_layout_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:ui' show FlutterView, ViewConstraints;
5+
import 'dart:ui' show FlutterView;
66

77
import 'package:flutter/material.dart';
88
import 'package:flutter/rendering.dart';
@@ -36,7 +36,7 @@ class ScheduledFrameTrackingBindings extends AutomatedTestWidgetsFlutterBinding
3636

3737
class OffscreenRenderView extends RenderView {
3838
OffscreenRenderView({required super.view}) : super(
39-
configuration: ViewConfiguration(constraints: ViewConstraints.tight(_kTestViewSize)),
39+
configuration: const ViewConfiguration(size: _kTestViewSize),
4040
);
4141

4242
@override

packages/flutter/test/widgets/keep_alive_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ void main() {
218218
' │ debug mode enabled - ${Platform.operatingSystem}\n'
219219
' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n'
220220
' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
221-
' │ configuration: ViewConstraints(w=800.0, h=600.0) at 3.0x (in\n'
222-
' │ logical pixels)\n'
221+
' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n'
223222
' │\n'
224223
' └─child: RenderRepaintBoundary#00000\n'
225224
' │ needs compositing\n'
@@ -393,8 +392,7 @@ void main() {
393392
' │ debug mode enabled - ${Platform.operatingSystem}\n'
394393
' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n'
395394
' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
396-
' │ configuration: ViewConstraints(w=800.0, h=600.0) at 3.0x (in\n'
397-
' │ logical pixels)\n'
395+
' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n'
398396
' │\n'
399397
' └─child: RenderRepaintBoundary#00000\n'
400398
' │ needs compositing\n'

0 commit comments

Comments
 (0)