-
Notifications
You must be signed in to change notification settings - Fork 6k
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 views
proxy and getInitialData
.
#49320
[web] Add views
proxy and getInitialData
.
#49320
Conversation
b400ae2
to
bc1bdce
Compare
views
proxy and getInitialData
.
beside web, other platform should also need to get the initData, can we add a property to FlutterView? |
@wanjm please, create a new issue with a feature request so @goderbauer knows you want this too for other platforms (what other platforms?). If the framework ever supports |
This comment was marked as off-topic.
This comment was marked as off-topic.
Object? getInitialData(int viewId) { | ||
return _viewManager.getOptions(viewId)?.initialData; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we add official APIs for initial data, I still would like us to explore without it. Here's an example of how I could see this done:
Let's have a getViewOptions
API:
// Of course, we would need to make `JsFlutterViewOptions` public thru `dart:ui_web`.
JsFlutterViewOptions? getViewOptions(int viewId) {
return _viewManager.getOptions(viewId);
}
And then users can define their custom JsFlutterViewOptions
implementation:
import 'dart:js_interop';
import 'dart:ui_web' as ui_web;
// The JS-interop definition of the view options object passed when creating a flutter view.
@JS()
@staticInterop
// I'm not sure if `extends` or `implements` is better here.
class MyJsFlutterViewOptions implements ui_web.JsFlutterViewOptions {}
extension MyJsFlutterViewOptionsExtension on MyJsFlutterViewOptions {
// Users can put properties directly here
external String? get randomUUID;
// or package everything into an `initialData` property
external MyJsInitialData get initialData;
}
This way, users also get access to the view's hostElement
, sizeConstraints
, etc.
1769a6a
to
624c481
Compare
This comment was marked as outdated.
This comment was marked as outdated.
After giving it some more thought, I'm not opposed to having an API for |
23c5fcf
to
02046d3
Compare
Adding some unit tests and prepping to land this. |
This reverts commit 624c481.
02046d3
to
436e813
Compare
I think this is ready to go, PTAL @mdebbar! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
/// can add their own custom HTML elements (for example: file inputs for the | ||
/// file_selector plugin). | ||
JSAny? getHostElement(int viewId) { | ||
return _viewManager.getOptions(viewId)?.hostElement as JSAny?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is as JSAny?
necessary? I would expect this to work:
return _viewManager.getOptions(viewId)?.hostElement as JSAny?; | |
return _viewManager.getOptions(viewId)?.hostElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
analyzer is not happy without the cast:
A value of type 'DomElement?' can't be returned from the method
'getHostElement' because it has a return type of 'JSAny?'.
(return_of_invalid_type)
(It's the same if I make the return a JSObject?
)
…142290) flutter/engine@9142fc4...8a81e53 2024-01-26 skia-flutter-autoroll@skia.org Roll Dart SDK from 00784f1f22b5 to 6f8bcd5b48ab (1 revision) (flutter/engine#50074) 2024-01-26 ditman@gmail.com [web] Add `views` proxy and `getInitialData`. (flutter/engine#49320) 2024-01-26 ditman@gmail.com [web] Prevent re-rendering disposed views when the engine hot restarts. (flutter/engine#49958) 2024-01-26 skia-flutter-autoroll@skia.org Roll Dart SDK from 2fb950853f06 to 00784f1f22b5 (3 revisions) (flutter/engine#50068) 2024-01-26 matanlurey@users.noreply.github.com Avoid sizing `ImageReaderSurfaceProducer` smaller than 1x1 (flutter/engine#50066) 2024-01-26 jonahwilliams@google.com Use clamp sampling mode in external texture. (flutter/engine#50063) 2024-01-26 john@johnmccutchan.com Reland Optimizations for TLHC frame rate and jank (flutter/engine#50065) 2024-01-25 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Igt2rE-R6rgfmTRaF... to WHlwlOwznFknNm5IS... (flutter/engine#50059) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from Igt2rE-R6rgf to WHlwlOwznFkn If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jacksongardner@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Hello! Is this feature already live? I can't seem to find any docs on it. Thanks |
@albertolina It's been pushed to flutter |
Thank you for clarifying @ditman! Much appreciated |
Adds a Dart API so Application/Plugin programmers can retrieve the
initialData
configuration value that may be passed when adding a view from JS in a multiViewEnabled app.When adding a view to an app like this:
initialData
can be accessed from Dart by defining a JS-interop class like:And then, from the code of the application:
Testing
Will add unit tests once naming is sorted out :)
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.