Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create DeltaTextInputClient#90205

Merged
Renzo-Olivares merged 23 commits intoflutter:masterfrom
Renzo-Olivares:g_fix
Sep 17, 2021
Merged

Create DeltaTextInputClient#90205
Renzo-Olivares merged 23 commits intoflutter:masterfrom
Renzo-Olivares:g_fix

Conversation

@Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Sep 16, 2021

Description

Fixes b/200138301

Looks like there are some failures for those who implement TextInputClient. They are missing an updateEditingValueWithDeltas implementation. This change aims to fix this by instead of adding updateEditingValueWithDeltas to TextInputClient interface, we extend TextInputClient and add the new method in there. This extension will be called DeltaTextInputClient.

With this change we do not force people who do not want any deltas to implement updateEditingValueWithDeltas.

Related Issues

Fixes b/200138301

Tests

Added tests to verify updateEditingValueWithDeltas method is called.
Adds a text_input_utils.dart for the common FakeTextChannel to be shared.

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 feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 16, 2021
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

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.

Some things to discuss in my comments, but overall I think I like this approach better. We probably shouldn't force implementers of TextInputClient to implement updateEditingValueWithDeltas when most don't care about deltas at all.

}

_currentConnection!._client.updateEditingValueWithDeltas(deltas);
(_currentConnection!._client as DeltaTextInputClient).updateEditingValueWithDeltas(deltas);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any risk that _currentConnection!._client might not be a DeltaTextInputClient? Is updateEditingStateWithDeltas ever called on any platform when enableDeltaModel is false? Even if it's not, maybe we need to make it obvious to users in the docs that if they set enableDeltaModel to true, then they must be using an implementation of DeltaTextInputClient and not TextInputClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the platform side there is no risk. But yes we can add this to the documentation.

Copy link
Contributor

@GaryQian GaryQian Sep 16, 2021

Choose a reason for hiding this comment

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

We should add an assert here as well! This is one of the problems with casting things around, it adds risk of misuse. The assert can also include an error message that makes this clear if it is ever encountered.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can accomplish this same thing without breaking the interface API though, so reluctantly, we may have to proceed with something like this even though it is a bit awkward

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. If a platform implements the delta model, and someone is using a TextInputClient with a TextInputConfiguration with enableDeltaModel set to true then they will be able to reach this case and receive unexpected behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, well let's slap tons of warnings and docs and asserts around this to make sure it is at least obvious exactly how to fix it/make it work. Kind of ugly but the cost of being non-breaking.

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 were not an opt-in feature, im tempted to just break as most developers using this would be advanced anyways and it should be trivial to copy-paste in a snipped already included in the docs, but I don't think we should break people especially if they don't even need it for their code to keep working.

value = delta.apply(value);
}
updateEditingValue(value);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're losing this method, should we include it as an example implementation of updateEditingValueWithDeltas in the docs or something? I want to make sure that users know what to do here when they implement updateEditingValueWithDeltas.

Copy link
Contributor Author

@Renzo-Olivares Renzo-Olivares Sep 16, 2021

Choose a reason for hiding this comment

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

That makes sense to me! Don't see why an example would hurt.


/// An interface to receive information from [TextInput].
///
/// If [TextInputConfiguration.enableDeltaModel] is set to true you should
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit wording: ... is set to true, [DeltaTextInputClient] must be implemented instead of this class.

/// * [TextInput.attach]
/// * [EditableText], a [TextInputClient] implementation.
/// * [DeltaTextInputClient], a [TextInputClient] extension that receives
/// granular information from the platform's text input.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, add indent here

_currentConnection!._client.updateEditingValue(TextEditingValue.fromJSON(args[1] as Map<String, dynamic>));
break;
case 'TextInputClient.updateEditingStateWithDeltas':
assert(_currentConnection!._client is DeltaTextInputClient, 'You should be using a DeltaTextInputClient if you have TextInputConfiguration.enableDeltaModel set to true');
Copy link
Contributor

Choose a reason for hiding this comment

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

should -> must

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 👍 , just two nits.

///
/// Here is an example of what implementation of this method could look like:
///
/// @override
Copy link
Contributor

Choose a reason for hiding this comment

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

This example should probably be a {@tool snippet} so that it's formatted nicely on the docs website.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

TextInputConfiguration get configuration => const TextInputConfiguration(enableDeltaModel: true);
}

class FakeTextChannel implements MethodChannel {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Is this identical to the one in text_input_test.dart? Could the code be shared somehow? Maybe a text_input_utils.dart file or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's shared by autofill_test.dart and text_input_test.dart so i'll make it a common file.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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 with the changes 👍

@Renzo-Olivares Renzo-Olivares merged commit 4b330dd into flutter:master Sep 17, 2021
@Hhine

This comment was marked as off-topic.

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.

5 participants