Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Add focus support for platform view #33093

Merged

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented May 4, 2022

This PR continues the work to add Focus support for platform view. It mainly contains 2 parts:

  1. detects the platform view focus events and sends "viewFocused" channel message to the framework
  2. handles the "TextInput.setPlatformViewClient" channel message from the framework

I wrote up this proposal to provide more context such as different approaches to detect first responder events.

List which issues are fixed by this PR. You must list at least one issue.

flutter/flutter#34187

The previous PR in framework repo is here

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 Hixie said 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.

@hellohuanlin hellohuanlin force-pushed the huan_platform_view_focus_in_engine branch 3 times, most recently from 0df0bcf to 1519063 Compare May 24, 2022 18:53
@hellohuanlin hellohuanlin changed the title [wip] Support focus for platform view Support focus for platform view May 24, 2022
@hellohuanlin hellohuanlin marked this pull request as ready for review May 24, 2022 19:07
@hellohuanlin hellohuanlin changed the title Support focus for platform view Add focus support for platform view May 24, 2022
@hellohuanlin hellohuanlin requested review from jmagman and cyanglaz May 24, 2022 19:10
@hellohuanlin hellohuanlin force-pushed the huan_platform_view_focus_in_engine branch from 1b606bd to 7372ec3 Compare May 24, 2022 19:57
// Caveat:
// 1. This detection logic does not cover the scenario when a platform view becomes
// first responder without any flutter text input resigning its first responder status
// (e.g. user tapping on platform view first). For now it works fine because there can only be
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious:
Are we expecting an UIKit update that will introduce multiple first responders?

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 should probably rephrase it clearly - I am not expecting UIKit change. What I meant to say is that right now the text input plugin does not need to keep track of the platform view focus state, but in the future we may need to track it (not because of UIKit change, but for potential other unknown reasons)

Comment on lines 2202 to 2212
- (void)setPlatformViewTextInputClient:(long)platformViewID {
// No need to track the platformViewID for now (unlike in Android), because in iOS there can
// only be one single first responder. When a platform view becomes first responder, hide
// this dummy text input view (`_activeView`) for the previously focused widget.
[self removeEnableFlutterTextInputViewAccessibilityTimer];
_activeView.accessibilityEnabled = NO;
[_activeView removeFromSuperview];
[_inputHider removeFromSuperview];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine to me.

cc @justinmc, do you mind take a quick look at this to see if it makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justinmc could you take a quick look? thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im gonna land it first since i've tested it many times, and it's not used just yet (until the framework part is complete), but let me know if any thing comes up

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

@hellohuanlin hellohuanlin force-pushed the huan_platform_view_focus_in_engine branch from e66b307 to 26d1faf Compare May 27, 2022 21:21
@hellohuanlin hellohuanlin added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 28, 2022
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 28, 2022
@hellohuanlin hellohuanlin added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 28, 2022
@fluttergithubbot fluttergithubbot merged commit ce6c38e into flutter:main May 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants