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

[platform_view]Send platform message when platform view is focused #105050

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented May 31, 2022

This PR actually sends message channel to the engine to tell the TextInputPlugin that a platform view is focused.

This PR should wait till the engine roll is done (engine PR here)

We probably want to add integration test too. I am looking into how it's done now.

platform view focus

List which issues are fixed by this PR. You must list at least one issue.
#34187
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label May 31, 2022
@hellohuanlin hellohuanlin force-pushed the huan_platform_view_send_channel_message_in_framework branch from 849fcd0 to 37eba75 Compare May 31, 2022 20:58
@hellohuanlin hellohuanlin marked this pull request as ready for review May 31, 2022 21:04
@jmagman
Copy link
Member

jmagman commented May 31, 2022

This PR should wait till the engine roll is done (engine PR here)

It was rolled into the framework a few days ago #104885

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

I think including integration tests in the same PR is a good idea, while it's fresh how this works.

Code LGTM.

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 % nits

Sorry have one question, see: #105050 (comment)

@@ -660,7 +660,16 @@ class _UiKitViewState extends State<UiKitView> {
}

void _onFocusChange(bool isFocused) {
// TODO(hellohuanlin): send 'TextInput.setPlatformViewClient' channel message to engine after the engine is updated to handle this message.
if (!isFocused) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nits:
Maybe this would be more readable if we check if (isFocused) first?

if (isFocused) {
  SystemChannels.textInput.invokeMethod<void>(
        'TextInput.setPlatformViewClient',
        <String, dynamic>{'platformViewId': _controller!.id},

}

Or we can escape early instead of if-else

if (!isfocused) {
  return;
}
 SystemChannels.textInput.invokeMethod<void>(
        'TextInput.setPlatformViewClient',
        <String, dynamic>{'platformViewId': _controller!.id},

} else {
SystemChannels.textInput.invokeMethod<void>(
'TextInput.setPlatformViewClient',
<String, dynamic>{'platformViewId': _controller!.id},
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we ensure _controller! will not crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh because _controller and _focusNode are set together:

    setState(() {
      _controller = controller;
      _focusNode = FocusNode(debugLabel: 'UiKitView(id: $id)');
    });

And this _onFocusChange function is triggered by the _focusNode, which must be present, so _controller must also be present.

@hellohuanlin
Copy link
Contributor Author

hellohuanlin commented Jun 1, 2022

As discussed since we can't trigger a tap on platform view from the framework integration test (more details here)

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

This LGTM, up to you whether you want to write the integration test in this PR or another, if you can get the native testing working.

@hellohuanlin
Copy link
Contributor Author

hellohuanlin commented Jun 2, 2022

I think i will keep this PR small for now, since the testing may take some time learning

Since it's not stamped yet, I will add integration test to this PR.

@hellohuanlin hellohuanlin requested a review from jmagman June 6, 2022 23:11
@hellohuanlin
Copy link
Contributor Author

@cyanglaz @jmagman I added the XCUITests. it turns out that i may have to create a new flutter project because existing ios_platform_view_test calls enableFlutterDriverExtension in order to support flutter_driver, which disables keyboard for XCUITest.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

ios_platform_view_xcuitests isn't a good name, what if we wanted to add macOS or non-xcuitests to it?
Is there any reason not to add the tests to ios_platform_view_tests and reuse that project? There's so much boilerplate for every new project we add...

GitHub doesn't let us comment on binaries, but we shouldn't check in any of the app icons.

Also the analyzer isn't happy:

dev/integration_tests/ios_platform_view_xcuitests/ios/RunnerUITests/RunnerUITests.m:50: trailing blank line

@@ -0,0 +1,44 @@
# Miscellaneous
Copy link
Member

Choose a reason for hiding this comment

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

It's inconsistent but I think we generally don't check in gitignores for projects in this repo since there's already a top-level gitignore. See if anything unexpected gets tracked if you remove this.

@@ -0,0 +1,49 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

native_ui_platform_view_tests_ios to better match native_ui_tests_macos?

You'll need to add an entry to .ci.yaml to get this to run anywhere:

  - name: Mac_ios native_ui_platform_view_tests_ios
    bringup: true
    recipe: devicelab/devicelab_drone
    presubmit: false
    timeout: 60
    properties:
      tags: >
        ["devicelab", "ios", "mac"]
      task_name: native_ui_platform_view_tests_ios
    scheduler: luci

buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = S8QB4VV633;
Copy link
Member

Choose a reason for hiding this comment

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

Remove the Flutter team.

buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = S8QB4VV633;
Copy link
Member

Choose a reason for hiding this comment

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

Remove

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

Changes for the integration test

@hellohuanlin
Copy link
Contributor Author

Is there any reason not to add the tests to ios_platform_view_tests and reuse that project?

@jmagman The existing ios_platform_view_test calls enableFlutterDriverExtension (code here) in order to support flutter_driver, which disables keyboard for XCUITest.

I can look into if there's a way to host 2 Apps in the same project (maybe that's what a "flavor" can do?)

@jmagman
Copy link
Member

jmagman commented Jun 10, 2022

Is there any reason not to add the tests to ios_platform_view_tests and reuse that project?

@jmagman The existing ios_platform_view_test calls enableFlutterDriverExtension (code here) in order to support flutter_driver, which disables keyboard for XCUITest.

I can look into if there's a way to host 2 Apps in the same project (maybe that's what a "flavor" can do?)

Oh sorry I see your comment about this from above. What if you used dart defines? Does this work?

      await flutter(
        'build',
        options: <String>[
          'ios',
          '-v',
          '--release',
          '--dart-define',
          'SKIP_DRIVER_EXTENSION=true',
          '--config-only',
        ],
      );
void main() {
  if (!bool.fromEnvironment('SKIP_DRIVER_EXTENSION')) {
    enableFlutterDriverExtension();
  }
  runApp(const MyApp());
}

@jmagman
Copy link
Member

jmagman commented Jun 10, 2022

Or avoiding double negatives:

      await flutter(
        'build',
        options: <String>[
          'ios',
          '-v',
          '--release',
          '--dart-define',
          'ENABLE_DRIVER_EXTENSION=false',
          '--config-only',
        ],
      );
void main() {
  if (bool.fromEnvironment('ENABLE_DRIVER_EXTENSION'), defaultValue: true) {
    enableFlutterDriverExtension();
  }
  runApp(const MyApp());
}

@hellohuanlin hellohuanlin force-pushed the huan_platform_view_send_channel_message_in_framework branch from 68758f9 to 79b49e6 Compare June 10, 2022 21:33
Copy link
Contributor

@keyonghan keyonghan left a comment

Choose a reason for hiding this comment

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

Please add an ownership for this test here: https://github.com/flutter/flutter/blob/master/TESTOWNERS#L139

@hellohuanlin hellohuanlin force-pushed the huan_platform_view_send_channel_message_in_framework branch from 81596d5 to 1682d5e Compare June 10, 2022 21:42
@@ -195,7 +195,7 @@
/dev/devicelab/bin/tasks/module_custom_host_app_name_test.dart @zanderso @flutter/tool
/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart @zanderso @flutter/tool
/dev/devicelab/bin/tasks/module_test.dart @zanderso @flutter/tool
/dev/devicelab/bin/tasks/native_ui_tests_ios.dart @jmagman @flutter/engine
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.ci.yaml Outdated
Comment on lines 3663 to 3667
presubmit: false
timeout: 60
properties:
tags: >
["devicelab", "ios", "mac"]
Copy link
Member

Choose a reason for hiding this comment

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

I led you astray, this isn't a devicelab test, which means it has a tethered iOS device, it should be "hostonly" since it only runs in the simulator.

Suggested change
presubmit: false
timeout: 60
properties:
tags: >
["devicelab", "ios", "mac"]
timeout: 60
properties:
tags: >
["devicelab", "hostonly"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean ["hostonly", "ios", "mac"]?

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't think so, I think that will make it require a machine with a tethered iOS device.
Like this:

flutter/.ci.yaml

Line 2394 in 712860d

["devicelab", "hostonly"]

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is a host only test, the target name should be updated as Mac native_platform_view_ui_tests_ios, which controls what test bed to run.

The tags here should also be updated as ["devicelab", "hostonly"] as @jmagman suggested. Though this doesn't control the test bed, it affects performance metrics tags and build stats in bigquery. It would be good to reflect the truth of the test.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @keyonghan!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I don't think any of the functionalities require code signing. (@cyanglaz to confirm).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the device lab testing so I guess it will require code signing for the app to run on devices, but if you just want to test the functionalities on simulator you can bypass code signing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the Mac name before the test name indicates that it is to be tested on the simulator? @keyonghan is it correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here the devicelab means tasks located under dev/devicelab/bin/tasks, which all share the same devicelab_drone recipes. It includes two types: the ones that need a devicelab testbed (which needs a physical phone connected), the other ones that run on a host only bot.

The Mac name will route all tests to the second type, whereas the Mac_ios will route tests to the first type.

The test added in this PR does run on a host only bot. You may want to take a look at the log to see if any findings: https://logs.chromium.org/logs/flutter/led/keyonghan_google.com/943f3399cb63bc7e1dc12ccdfcf310d85888f7de9f910789f46af2ed8a9f93cf/+/u/run_native_platform_view_ui_tests_ios/test_stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the bottom of this link, it looks like the error is in Android:

Task result:
{
  "success": false,
  "reason": "Task failed: DeviceException: The ANDROID_SDK_ROOT environment variable is missing. The variable must point to the Android SDK directory containing platform-tools."
}

It also mention about code signing tho, but not part of the failure reason.

Comment on lines 13 to 14
deviceOperatingSystem = DeviceOperatingSystem.ios;

Copy link
Member

Choose a reason for hiding this comment

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

And since this is "hostonly" and doesn't need a tethered device, you should be able to delete this line.

Suggested change
deviceOperatingSystem = DeviceOperatingSystem.ios;

@@ -54,6 +73,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
E09898E32853E9F000064317 /* Frameworks */ = {
Copy link
Member

Choose a reason for hiding this comment

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

Was this empty frameworks build phase added accidentally? If Xcode did it automatically it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's automatically added by Xcode when I add the test target.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

@jmagman
Copy link
Member

jmagman commented Jun 14, 2022

Re: the test failures, rebase past #105927

@hellohuanlin hellohuanlin force-pushed the huan_platform_view_send_channel_message_in_framework branch from 9fd6451 to fa67e7c Compare June 14, 2022 19:11
@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 16, 2022
@hellohuanlin hellohuanlin force-pushed the huan_platform_view_send_channel_message_in_framework branch from be0e5e1 to d7667a4 Compare June 22, 2022 18:50
@auto-submit auto-submit bot merged commit 0dd0c2e into flutter:master Jun 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
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 framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants