Skip to content

Conversation

justinmc
Copy link
Contributor

@justinmc justinmc commented May 20, 2022

This PR makes TextInputClient a mixin instead of an abstract class. It does the same for DeltaTextInputClient.

The reason for this is to discourage users from using implements on these abstract classes, which causes a breaking change when changes are made to the abstract class. This is a common occurrence on these classes related to platform APIs.

Migration guide

Users of TextInputClient and DeltaTextInputClient should mix them into their own classes via the with keyword, similar to how this PR changes EditableTextState to use TextInputClient via with.

✔️

class MyEditorState extends State<MyEditor> with TextInputClient {
  // ...
}

If users were using TextInputClient or DeltaTextInputClient via the implements keyword, they will not be broken by this change, but the above approach with with is still recommended. The advantage of with is that implements requires implementations of all methods, even if the mixin has one, so future additions to the mixin will be a breaking change.

⚠️

class MyEditorState extends State<MyEditor> implements TextInputClient {
  // ...
}

If any user were using TextInputClient or DeltaTextInputClient via the extends keyword, they would be broken, and should use the with keyword instead as above.

class MyEditor extends TextInputClient {
  // ...
}

See also

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels May 20, 2022
@justinmc justinmc mentioned this pull request May 20, 2022
@justinmc justinmc marked this pull request as ready for review June 1, 2022 20:50
@@ -1192,7 +1188,7 @@ class SelectionRect {
/// * [TextInputConfiguration], to opt-in to receive [TextEditingDelta]'s from
/// the platforms [TextInput] you must set [TextInputConfiguration.enableDeltaModel]
/// to true.
abstract class DeltaTextInputClient extends TextInputClient {
mixin DeltaTextInputClient implements TextInputClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to provide a default implementation for void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas);, since this implements TextInputClient thus has access to updateEditingValue?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe not? Since that would need to set the TextInputClient's current text editing value which I don't believe we access to here. Or maybe i'm misunderstanding how the default implementation would look.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is. https://master-api.flutter.dev/flutter/services/TextInputClient/currentTextEditingValue.html

We can even deprecate DeltaTextInputClient if we move the update method to TextInputClient and provide a default implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could open up opportunities for EditableText to use deltas since it would only require the TextInputConfiguration to set enableDeltaModel to true, maybe through a flag thats piped through TextField?. Another option could also be that EditableText mixins both TextInputClient and DeltaTextInputClient. I'm leaning towards the former since deltas seem like a core function of text input. Though the latter would avoid any breakages.

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 exciting, I'll move forward with this PR and we can go from there in another PR. Deltas would be pretty core especially if we were using it in EditableText.

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM though I do wonder in what cases we would provide a default implementation since this is usually used/implemented by some type of Editable widget which extends State. And the methods in this TextInputClient sometimes act on this state like the TextEditingValue.

@Piinks
Copy link
Contributor

Piinks commented Jun 22, 2022

(Triage) @justinmc is this ready to merge?

@justinmc
Copy link
Contributor Author

I think Google testing is stuck, I'll push a merge commit. Otherwise this is ready to go, thanks for the reminder.

@justinmc justinmc force-pushed the text-input-client-mixin branch from bdc182d to 6afd3f1 Compare June 27, 2022 18:59
@justinmc justinmc merged commit 1fd3d6c into flutter:master Jun 28, 2022
@justinmc justinmc deleted the text-input-client-mixin branch June 28, 2022 17:14
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 29, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
TextInputClient and DeltaTextInputClient are now mixins, which helps with breaking changes and future deltas work
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
a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants