-
Notifications
You must be signed in to change notification settings - Fork 6k
take web_ui to null safety #19027
take web_ui to null safety #19027
Changes from all commits
243a130
c0a0f1f
a36fa30
ac05da8
3f47f96
55456d7
1e96807
f3ecb41
0d5af6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,90 +5,7 @@ | |
// @dart = 2.6 | ||
part of engine; | ||
|
||
/// A registry for factories that create platform views. | ||
class PlatformViewRegistry { | ||
final Map<String, PlatformViewFactory> registeredFactories = | ||
<String, PlatformViewFactory>{}; | ||
|
||
final Map<int, html.Element> _createdViews = <int, html.Element>{}; | ||
|
||
/// Private constructor so this class can be a singleton. | ||
PlatformViewRegistry._(); | ||
|
||
/// Register [viewTypeId] as being creating by the given [factory]. | ||
bool registerViewFactory(String viewTypeId, PlatformViewFactory factory) { | ||
if (registeredFactories.containsKey(viewTypeId)) { | ||
return false; | ||
} | ||
registeredFactories[viewTypeId] = factory; | ||
return true; | ||
} | ||
|
||
/// Returns the view that has been created with the given [id], or `null` if | ||
/// no such view exists. | ||
html.Element getCreatedView(int id) { | ||
return _createdViews[id]; | ||
} | ||
} | ||
|
||
/// A function which takes a unique [id] and creates an HTML element. | ||
typedef PlatformViewFactory = html.Element Function(int viewId); | ||
|
||
/// The platform view registry for this app. | ||
final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry._(); | ||
|
||
/// Handles a platform call to `flutter/platform_views`. | ||
/// | ||
/// Used to create platform views. | ||
void handlePlatformViewCall( | ||
ByteData data, | ||
ui.PlatformMessageResponseCallback callback, | ||
) { | ||
const MethodCodec codec = StandardMethodCodec(); | ||
final MethodCall decoded = codec.decodeMethodCall(data); | ||
|
||
switch (decoded.method) { | ||
case 'create': | ||
_createPlatformView(decoded, callback); | ||
return; | ||
case 'dispose': | ||
_disposePlatformView(decoded, callback); | ||
return; | ||
} | ||
callback(null); | ||
} | ||
|
||
void _createPlatformView( | ||
MethodCall methodCall, ui.PlatformMessageResponseCallback callback) { | ||
final Map<dynamic, dynamic> args = methodCall.arguments; | ||
final int id = args['id']; | ||
final String viewType = args['viewType']; | ||
const MethodCodec codec = StandardMethodCodec(); | ||
|
||
// TODO(het): Use 'direction', 'width', and 'height'. | ||
if (!platformViewRegistry.registeredFactories.containsKey(viewType)) { | ||
callback(codec.encodeErrorEnvelope( | ||
code: 'Unregistered factory', | ||
message: "No factory registered for viewtype '$viewType'", | ||
)); | ||
return; | ||
} | ||
// TODO(het): Use creation parameters. | ||
final html.Element element = | ||
platformViewRegistry.registeredFactories[viewType](id); | ||
|
||
platformViewRegistry._createdViews[id] = element; | ||
callback(codec.encodeSuccessEnvelope(null)); | ||
} | ||
|
||
void _disposePlatformView( | ||
MethodCall methodCall, ui.PlatformMessageResponseCallback callback) { | ||
final int id = methodCall.arguments; | ||
const MethodCodec codec = StandardMethodCodec(); | ||
|
||
// Remove the root element of the view from the DOM. | ||
platformViewRegistry._createdViews[id]?.remove(); | ||
platformViewRegistry._createdViews.remove(id); | ||
|
||
callback(codec.encodeSuccessEnvelope(null)); | ||
} | ||
// TODO(yjbanov): The code in this file was temporarily moved to lib/web_ui/lib/ui.dart | ||
// during the NNBD migration so that `dart:ui` does not have to export | ||
// `dart:_engine`. NNBD does not allow exported non-migrated libraries | ||
// from migrated libraries. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leafpetersen - is this a bug or an intended restriction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was intentional. We could remove the restriction, but I was aiming to have the property that opted in packages had no legacy types in their public interface, so that if you migrated relative to an opted in package you could be confident that you were done. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ typedef Callback<T> = void Function(T result); | |
/// | ||
/// Return value should be null on success, and a string error message on | ||
/// failure. | ||
typedef Callbacker<T> = String Function(Callback<T> callback); | ||
typedef Callbacker<T> = String/*?*/ Function(Callback<T> callback); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to keep comment syntax here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now. This PR only migrates |
||
|
||
/// Converts a method that receives a value-returning callback to a method that | ||
/// returns a Future. | ||
|
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.
Once this file is opted in, can this become
late SkiaFontCollection = skiaFontCollection
? Maybe final if it doesn't get reset?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.
Hopefully. Filed flutter/flutter#59371 to revisit this.