Skip to content

[text_input] prepare for custom text input sources #72803

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

Merged
merged 10 commits into from
Jan 15, 2021

Conversation

jpnurmi
Copy link
Member

@jpnurmi jpnurmi commented Dec 22, 2020

Description

The existing TextInputConnection class has been made abstract and method channel-agnostic. There is now a separate internal class, _TextInputChannelConnection, that implements the default type of text input connection that communicates with platform plugins via the text input system channel.

The main motivation of the separation is to allow custom text input sources that can replace the method channel-based implementation and for example, communicate with an in-app virtual keyboard on (embedded) platforms that do not have a system-provided keyboard.

To be able to eliminate direct method channel calls from the TextInput class, the following new methods have been introduced:

  • TextInput.detach()
  • TextInput.reset()
  • TextInputConnection.hide()
  • TextInputConnection.setClient()
  • TextInputConnection.clearClient()

Consequently, the following methods have been deprecated:

  • TextInputConnection.close() in favor of TextInput.detach()
  • TextInputConnection.connectionClosedReceived() in favor of TextInput.reset()

Related PRs

This PR was split off from #69146.

Related Issues

#68988

Tests

I added the following tests:

  • test/services/text_input_test.dart:
    • TextInput message channels:
      • text input client is requested to hide on detach
      • old client is detached when a new client is attached
      • text input connection is reset

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 22, 2020
@google-cla google-cla bot added the cla: yes label Dec 22, 2020
@jpnurmi jpnurmi force-pushed the text-input-channel-connection branch 2 times, most recently from 855ca1b to 4590fc3 Compare December 30, 2020 14:40
@jpnurmi
Copy link
Member Author

jpnurmi commented Dec 30, 2020

Rebased again in hopes to pass the CI (unrelated git fetch failures on macOS).

The existing TextInputConnection class has been made abstract and
method channel-agnostic. There is now a separate internal class,
_TextInputChannelConnection, that implements the default type of text
input connection that communicates with platform plugins via the text
input system channel.

The main motivation of the separation is to allow custom text input
sources that can replace the method channel-based implementation and
for example, communicate with an in-app virtual keyboard on (embedded)
platforms that do not have a keyboard provided by the system

Ref: flutter#68988
@jpnurmi jpnurmi force-pushed the text-input-channel-connection branch from 4590fc3 to 138e868 Compare December 31, 2020 09:42
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Thanks for splitting this out from #69146, should be easier to review and merge.

It looks like this could hypothetically break someone that was subclassing TextInputConnection. Do we know if anyone might be doing that? I've submitted this PR to have the internal Google tests run on it, and if it passes there then I'm more confident that it's not a problem.

CC @LongCatIsLooong since you reviewed #69146.

@jpnurmi
Copy link
Member Author

jpnurmi commented Jan 5, 2021

Thanks for the review!

It looks like this could hypothetically break someone that was subclassing TextInputConnection. Do we know if anyone might be doing that? I've submitted this PR to have the internal Google tests run on it, and if it passes there then I'm more confident that it's not a problem.

I believe it's not a breaking change because the constructor was private before, so it wasn't possible to create a TextInputConnection instance from the outside of text_input.dart.

@justinmc
Copy link
Contributor

justinmc commented Jan 5, 2021

Ah I missed that, you're right! Should be fine then. I'm on board once all the tests pass.

@goderbauer goderbauer requested a review from justinmc January 6, 2021 22:54
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM but I'll wait for @LongCatIsLooong's final approval.

Later on, _TextInputSource will be made public, abstract and documented
so that it can be used as a base class for custom input sources.
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

static MethodChannel? _channel;

static void setChannel(MethodChannel newChannel) {
_channel = newChannel..setMethodCallHandler(_handleTextInputInvocation);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we call clean up on the previous channel?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is only used in tests for setting up a testable environment via @visibleForTesting TextInput.setChannel(). This will be moved to the upcoming private default implementation of TextInputSource so it won't be visible to the outside.

@jpnurmi
Copy link
Member Author

jpnurmi commented Jan 14, 2021

Is the Google testing failure somehow related to this?

@LongCatIsLooong
Copy link
Contributor

Doesn't seem to be the case. I have restarted the test.

@LongCatIsLooong
Copy link
Contributor

The failure seems to be caused by something irrelevant. Could you rebase the branch to the latest commit and see if the failure goes away?

@jpnurmi
Copy link
Member Author

jpnurmi commented Jan 15, 2021

Unrelated Mac build_tests failure. Let's try again.

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.

4 participants