Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] Add dynamic view sizing (v2) #50271

Merged
merged 11 commits into from
Feb 15, 2024

Conversation

ditman
Copy link
Member

@ditman ditman commented Feb 2, 2024

Changes

  • Introduces a new viewConstraints JS configuration parameter to configure max/min width/height constraints for a view. Those can have the following values:
    • An integer >= 0: max/min size in pixels
    • Infinity (or Number.POSITIVE_INFINITY): (only for max values) -> unconstrained.
    • When any value is not set, it defaults to "tight to the current size".
  • Computes the correct physicalConstraints of a view off of its physicalSize and its viewConstraints for the framework to use during layout.
    • When no constraints are passed, the current behavior is preserved: the default constraints are "tight" to the physicalSize.
  • Resizes the current view DOM when requested by the framework and updates its internal physicalSize, then continues with the render procedure.

Example

This is how we can configure a view to "take as much vertical space as needed":

flutterApp.addView({
  viewConstraints: {
    minHeight: 0,
    maxHeight: Infinity,
  },
  hostElement: ...,
});

TODO

  • Needs actual unit tests

Issues

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard

This comment was marked as resolved.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Feb 2, 2024
@ditman
Copy link
Member Author

ditman commented Feb 2, 2024

Hey @harryterkelsen, @mdebbar, I came up with a much simpler solution to the previous one as I was updating this. PTAQL!

@@ -156,6 +168,17 @@ base class EngineFlutterView implements ui.FlutterView {
return _physicalSize ??= _computePhysicalSize();
}

void resize(ui.Size newPhysicalSize) {
// The browser wants logical sizes!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really have separate PhysicalSize and LogicalSize classes so we don't confuse the two (with methods to convert from one to the other e.g. PhysicalSize.toLogicalSize(dpr) and LogicalSize.toPhysicalSize(dpr)). Maybe when extension type is a thing we can give this a try!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Size is very generic, but valid most of the time. We really only care about this in the interfaces between systems:

Framework (logical, most of the time) <-> Engine (physical, most of the time) <-> Browser (logical, always?)

This sounds like an error waiting to happen (well, my earlier HTML renderer PR is an example of that exact error, I guess! :P)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't the same as having two separate types, but I've started being very careful documenting the type of size required depending on where in the code we are: if values come from JS/CSS/the browser in general -> logical size; if we're passing things to the framework -> physical size. Also attempted to reflect that in the variable/parameter names.

lib/web_ui/lib/src/engine/window.dart Outdated Show resolved Hide resolved
lib/web_ui/lib/src/engine/window.dart Outdated Show resolved Hide resolved
lib/web_ui/lib/src/engine/window.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ship it!

@ditman ditman force-pushed the web-dynamic-view-sizing-2 branch 3 times, most recently from 1f8fd7f to ae22b2c Compare February 9, 2024 19:53
@ditman ditman requested a review from mdebbar February 10, 2024 02:26
@ditman
Copy link
Member Author

ditman commented Feb 10, 2024

Added a bunch more tests and extended the comments in the Constraints calculation, to reason why things do what they do. PTAL @mdebbar, I think this is ready to land.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM!

lib/web_ui/lib/src/engine/js_interop/js_app.dart Outdated Show resolved Hide resolved
lib/web_ui/lib/src/engine/window.dart Show resolved Hide resolved
lib/web_ui/lib/src/engine/window.dart Outdated Show resolved Hide resolved
@ditman
Copy link
Member Author

ditman commented Feb 14, 2024

All right, I'll autosubmit this today, @harryterkelsen do ping me/create an issue or something if you see anything egregious!

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 14, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 14, 2024

This comment was marked as resolved.

@ditman
Copy link
Member Author

ditman commented Feb 14, 2024

01:45 +173: test/material/date_picker_test.dart: Semantics input mode
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: has semantics with label: Enter Date with value: 01/15/2016 with actions: [tap,
moveCursorBackwardByCharacter, setSelection, copy, cut, paste, moveCursorBackwardByWord, setText]
without actions: [longPress, scrollLeft, scrollRight, scrollUp, scrollDown, increase, decrease,
showOnScreen, moveCursorForwardByCharacter, didGainAccessibilityFocus, didLoseAccessibilityFocus,
dismiss, moveCursorForwardByWord]  with flags: [isTextField, isFocused]  without flags:
[hasCheckedState, isChecked, isCheckStateMixed, isSelected, isButton, isSlider, isKeyboardKey,
isLink, isReadOnly, isFocusable, hasEnabledState, isEnabled, isInMutuallyExclusiveGroup, isHeader,
isObscured, isMultiline, namesRoute, scopesRoute, isHidden, isImage, isLiveRegion, hasToggledState,
isToggled, hasImplicitScrolling, hasExpandedState, isExpanded]
  Actual: SemanticsNode:<SemanticsNode#11(Rect.fromLTRB(176.0, 26.0, 472.0, 82.0), actions: [copy,
cut, moveCursorBackwardByCharacter, moveCursorBackwardByWord, paste, setSelection, setText, tap],
flags: [isTextField, isFocused, hasEnabledState, isEnabled], label: "Enter Date", value:
"01/15/2016", textDirection: ltr, text selection: [0, 10], currentValueLength: 10)>
   Which: missing flags: [] unexpected flags: [hasEnabledState, isEnabled]

Mmmmkay...

@ditman
Copy link
Member Author

ditman commented Feb 15, 2024

I ran the failing test locally, and it seems to pass:

dit@dit:/work/flutter/flutter/packages/flutter$ flutter test --local-web-sdk=wasm_release --platform=chrome --web-renderer=html test/material/date_picker_test.dart 
00:57 +86 ~2: All tests passed!                                                                              

(Maybe related to this revert in the framework?)

I'll set autosubmit again.

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 15, 2024
@auto-submit auto-submit bot merged commit 6a5f306 into flutter:main Feb 15, 2024
28 checks passed
@ditman ditman deleted the web-dynamic-view-sizing-2 branch February 15, 2024 01:00
sealesj pushed a commit to sealesj/engine that referenced this pull request Feb 15, 2024
### Changes

* Introduces a new `viewConstraints` JS configuration parameter to configure max/min width/height constraints for a view. Those can have the following values:
  * An integer `>= 0`: max/min size in pixels
  * `Infinity` (or `Number.POSITIVE_INFINITY`): (only for max values) -> **unconstrained**.
  * When any value is not set, it defaults to "tight to the current size".
    * See [Understanding constraints](https://docs.flutter.dev/ui/layout/constraints).
* Computes the correct `physicalConstraints` of a view off of its `physicalSize` and its `viewConstraints` for the framework to use during layout.
  * When no constraints are passed, the current behavior is preserved: the default constraints are "tight" to the `physicalSize`.
* Resizes the current view DOM when requested by the framework and updates its internal physicalSize, then continues with the render procedure.

### Example

This is how we can configure a view to "take as much vertical space as needed":

```js
flutterApp.addView({
  viewConstraints: {
    minHeight: 0,
    maxHeight: Infinity,
  },
  hostElement: ...,
});
```

### TODO

* Needs actual unit tests

### Issues

* Fixes flutter/flutter#137444
* Closes flutter#48541

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 16, 2024
jason-simmons added a commit to jason-simmons/flutter that referenced this pull request Feb 16, 2024
2024-02-15 [email protected] [Android] Minor refactor: Remove redundant methods. (flutter/engine#50647)
2024-02-15 [email protected] [Impeller] consolidate transforms in PositionUVWriter (flutter/engine#50635)
2024-02-15 [email protected] [web] Add dynamic view sizing (v2) (flutter/engine#50271)
2024-02-14 [email protected] Add useful default options to scenario_app/bin/android_integration_tests.dart (flutter/engine#50667)
2024-02-14 [email protected] Fix github md "Note" and "Tip" blocks in Android shell README (flutter/engine#50664)
2024-02-14 [email protected] [Fuchsia] Run run_with_dart_aot test on fuchsia_profile_x64 (flutter/engine#50613)
2024-02-14 [email protected] Make all Android scenario_app activities full-screen, even on older Android versions. (flutter/engine#50666)
2024-02-14 [email protected] Roll Skia from eae42ea9f7bc to 2d5cf67614d0 (6 revisions) (flutter/engine#50660)
2024-02-14 [email protected] Add a comment explaining the lifecycle of tls_command_pool_map. (flutter/engine#50623)
2024-02-14 [email protected] [web] Increase tolerance for golden diffs on Safari (flutter/engine#50655)
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 16, 2024
2024-02-15 [email protected] [Android] Minor refactor: Remove redundant methods. (flutter/engine#50647)
2024-02-15 [email protected] [Impeller] consolidate transforms in PositionUVWriter (flutter/engine#50635)
2024-02-15 [email protected] [web] Add dynamic view sizing (v2) (flutter/engine#50271)
2024-02-14 [email protected] Add useful default options to scenario_app/bin/android_integration_tests.dart (flutter/engine#50667)
2024-02-14 [email protected] Fix github md "Note" and "Tip" blocks in Android shell README (flutter/engine#50664)
2024-02-14 [email protected] [Fuchsia] Run run_with_dart_aot test on fuchsia_profile_x64 (flutter/engine#50613)
2024-02-14 [email protected] Make all Android scenario_app activities full-screen, even on older Android versions. (flutter/engine#50666)
2024-02-14 [email protected] Roll Skia from eae42ea9f7bc to 2d5cf67614d0 (6 revisions) (flutter/engine#50660)
2024-02-14 [email protected] Add a comment explaining the lifecycle of tls_command_pool_map. (flutter/engine#50623)
2024-02-14 [email protected] [web] Increase tolerance for golden diffs on Safari (flutter/engine#50655)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web:multi-view] define an MVP for FlutterViews participation in host page layout
2 participants