Skip to content

Conversation

@blasten
Copy link

@blasten blasten commented Mar 14, 2022

Ensures that Android views are always rendered using a texture layer.

Related issue: #96679

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 14, 2022
@blasten blasten requested a review from cyanglaz March 14, 2022 22:20
@blasten blasten marked this pull request as ready for review March 14, 2022 22:20
/// * [AndroidView] which is a widget that is used to show an Android view.
/// * [PlatformViewsService] which is a service for controlling platform views.
class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
class RenderAndroidView extends PlatformViewRenderBox {
Copy link
Author

Choose a reason for hiding this comment

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

Making RenderAndroidView extend PlatformViewRenderBox allows AndroidViewSurface to continue to extend PlatformViewSurface due to the updateRenderObject override.

(controller as AndroidViewController).removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
controller = viewController;
viewController.addOnPlatformViewCreatedListener(_onPlatformViewCreated);
viewController.pointTransformer = (Offset offset) => globalToLocal(offset);
Copy link
Author

Choose a reason for hiding this comment

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

This seems to be bug currently. pointTransformer is set in the controller during initialization, but it's not set again if the controller is changed.

_viewController = viewController;

(controller as AndroidViewController).removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
controller = viewController;
Copy link
Author

Choose a reason for hiding this comment

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

this calls the setter in the parent class. I don't like this API, but I'm trying to make this PR a non-breaking change.

_viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
_viewController = viewController;

(controller as AndroidViewController).removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is (controller as AndroidViewController) just the getter viewController? (Not the parameter)

Copy link
Author

Choose a reason for hiding this comment

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

I cleaned this up. I removed viewController and overrode controller.

/// Sets a new Android view controller.
///
/// `viewController` must not be null.
set viewController(AndroidViewController viewController) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prob better name this paramter so it doesn't conflict with the getter viewController

Copy link
Author

Choose a reason for hiding this comment

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

I removed viewController and overrode controller instead.


(controller as AndroidViewController).removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
controller = viewController;
viewController.addOnPlatformViewCreatedListener(_onPlatformViewCreated);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks a little confusing changing the property after sets the ivar. How about:

this. viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
controller = viewController
controller.addOnPlatformViewCreatedListener(_onPlatformViewCreated);
controller.pointTransformer = (Offset offset) => globalToLocal(offset);
...

Copy link
Author

Choose a reason for hiding this comment

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

done

@override
Future<void> _sendCreateMessage() async {
assert(!_initialSize.isEmpty, 'trying to create $TextureAndroidViewController without setting a valid size.');
assert(_initialSize != null, 'trying to create $TextureAndroidViewController without setting an initial size.');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we test these 2 asserts?

Copy link
Author

Choose a reason for hiding this comment

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

Done. This is guarded by the create() method, which doesn't call super.create unless _initialSize is set. These are tested in services/platform_views_test.dart.

_viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
_viewController = viewController;

(controller as AndroidViewController).removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be tested? e.g. the listener is removed from the old controller. and added to the new controller

Copy link
Author

Choose a reason for hiding this comment

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

Done in a7eeb3a

@blasten blasten requested a review from cyanglaz March 15, 2022 20:43
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2022
zanderso added a commit that referenced this pull request Mar 16, 2022
zanderso added a commit that referenced this pull request Mar 16, 2022
blasten pushed a commit to blasten/flutter that referenced this pull request Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants