Skip to content

Conversation

@Blquinn
Copy link
Contributor

@Blquinn Blquinn commented Mar 11, 2023

This exposes the toggle to cupertino/material textfield's opacity animation so that users can disable the cursor opacity animation if they choose to.

Sort of fixes #59327

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

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 a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 11, 2023
@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 (don't just cc him here, he won't see it! He's on Discord!).

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.

@google-cla
Copy link

google-cla bot commented Mar 11, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Blquinn Blquinn force-pushed the disable-textfield-opacity-animation branch from 2d1dc0a to 6d78581 Compare March 13, 2023 22:04
@jmagman
Copy link
Member

jmagman commented Mar 14, 2023

Missing documentation for the new params:

dartdoc:stdout: Generating docs for library cupertino from package:flutter/cupertino.dart...
dartdoc:stderr:   error: undefined macro [flutter.widgets.editableText.cursorOpacityAnimates]
dartdoc:stderr:     from cupertino.CupertinoTextField.cursorOpacityAnimates: (file:///tmp/flutter%20sdk/packages/flutter/lib/src/cupertino/text_field.dart:666:14)
...
dartdoc:stderr:   error: undefined macro [flutter.widgets.editableText.cursorOpacityAnimates]
dartdoc:stderr:     from material.TextField.cursorOpacityAnimates: (file:///tmp/flutter%20sdk/packages/flutter/lib/src/material/text_field.dart:586:15)

@Blquinn
Copy link
Contributor Author

Blquinn commented Mar 15, 2023

@jmagman I've updated the docs. Not sure why that macro didn't work, but it's building now.

@gnprice
Copy link
Member

gnprice commented Mar 16, 2023

The macro wasn't working because there wasn't a definition for it. If you'd like to use the handy macro feature in the docs, you can add a @template marker with the same syntax that's used on the neighboring field:

  /// {@template flutter.widgets.editableText.cursorRadius}
  /// How rounded the corners of the cursor should be.
  ///
  /// By default, the cursor has no radius.
  /// {@endtemplate}
  final Radius? cursorRadius;

  /// Whether the cursor will animate from fully transparent to fully opaque
  /// during each cursor blink.
  ///
  /// By default, the cursor opacity will animate on iOS platforms and will not
  /// animate on Android platforms.
  final bool cursorOpacityAnimates;

That {@template etc. syntax is what defines the meaning of {@macro flutter.widgets.editableText.cursorRadius}, and you can do the same thing to make it work the same way for cursorOpacityAnimates.

@Blquinn
Copy link
Contributor Author

Blquinn commented Mar 16, 2023

@gnprice Oh nice, thanks for the tip!

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.

I'm on board with this. Since cursorOpacityAnimates already exists on EditableText, I see no reason why we shouldn't expose it on TextField and CupertinoTextField.

Can you add tests for this? I think you can simply add one for each of TextField and CupertinoTextField, and verify that underlying EditableText has the correct cursorOpacityAnimates value.

Also, have you verified that turning this off does indeed fix the CPU performance issue? I see you commented on the issue with some hard numbers, were those taken from disabling and enabling this on EditableText?

/// during each cursor blink.
///
/// By default, the cursor opacity will animate on iOS platforms and will not
/// animate on Android platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use a macro/template here instead of duplicating this? I see some discussion above about a macro not working before but let me know if you can't get it.

@Blquinn
Copy link
Contributor Author

Blquinn commented Mar 18, 2023

@justinmc I've added the macro for the docs and added tests you suggested for material and cupertino. I have also manually verified that the toggle overrides the default platform value correctly on a linux computer and mac.

Also, have you verified that turning this off does indeed fix the CPU performance issue? I see you commented on the issue with some hard numbers, were those taken from disabling and enabling this on EditableText?

Correct, I tested this by disabling/enabling the parameter in the text field examples. Nothing but the text field is present in the test app.

I have checked the CPU usage on multiple platforms (linux, macOS, iOS, windows) on physical devices, not emulators and in release mode. Each platform shows the same trend -- with the animation enabled I see a constant 10-16% cpu usage and with it disabled I see 0% cpu usage.

On desktop platforms I measured CPU using htop and the systems system monitor program. For iOS I used xCode's profiler/monitor thing.

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 👍. Thank you for the fixes!

@Blquinn
Copy link
Contributor Author

Blquinn commented Mar 20, 2023

@justinmc Sweet, thanks for the review! What exactly is the process for getting this merged?

Copy link
Member

@werainkhatri werainkhatri left a comment

Choose a reason for hiding this comment

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

congrats on your first contribution!

blue flutter

@werainkhatri werainkhatri added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2023
@justinmc
Copy link
Contributor

Sorry @Blquinn, the process was just to find a secondary reviewer, which @werainkhatri has been nice enough to provide. Now this will merge automatically when the tree is green.

@Blquinn
Copy link
Contributor Author

Blquinn commented Mar 22, 2023

Awesome; no problem at all. Thank you both!

@gnprice
Copy link
Member

gnprice commented Mar 22, 2023

The tree is green, but the "Google testing" check for this PR seems to have gotten stuck:

One workaround is to update the PR so the check gets restarted. I'm not sure if there are other workarounds a Googler could apply.

@auto-submit auto-submit bot merged commit 5ef9b84 into flutter:master Mar 23, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2023
tarrinneal pushed a commit to flutter/packages that referenced this pull request Mar 24, 2023
* cbdee52 Roll Flutter Engine from 59acb5362098 to 12c822327825 (3 revisions) (flutter/flutter#123330)

* 897e3db Inject the gstatic CanvasKit CDN URL by default in `flutter build web` (flutter/flutter#122772)

* 5a36bdd Stop serving Observatory by default (flutter/flutter#122419)

* b212e7b implement Iterator and Comparable instead of extending them (flutter/flutter#123282)

* af6029c c0fbe5a53 Roll Dart SDK from 9256fffbd5af to e8e045620234 (1 revision) (flutter/engine#40561) (flutter/flutter#123336)

* 9dec4fb FIX: NavigationDrawer hover/focus/pressed does not use indicatorShape (flutter/flutter#123325)

* 4907464 20ab040cd Roll Skia from ce5ff5cc03ce to c42320d53714 (2 revisions) (flutter/engine#40565) (flutter/flutter#123340)

* 28d40a4 Roll Packages from 75491e9 to 0826798 (5 revisions) (flutter/flutter#123342)

* 674ff15 [macOS] Add platform_channel sample/test (flutter/flutter#123141)

* 7b7af9f roll packages (flutter/flutter#123339)

* 3179875 replace some ._() constructors with class modifiers (flutter/flutter#122765)

* 7f41ab2 Fix (insert|move|remove)RenderObjectChild methods in base class (flutter/flutter#123276)

* fccca49 Refactor buildOverscrollIndicator (flutter/flutter#123246)

* 11bbce1 6b0933e74 [web] Add `dart:js_interop` to `_embedder.yaml`. (flutter/engine#40545) (flutter/flutter#123347)

* 716d252 Remove prefer_const_constructors ignores (flutter/flutter#123284)

* 100cf21 Prefer enum over class. (flutter/flutter#123312)

* 5ef9b84 Expose toggle to textfield's opacity animation. (flutter/flutter#122474)

* d79f3aa Roll Flutter Engine from 6b0933e74965 to bdce896fb64f (2 revisions) (flutter/flutter#123351)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
)

* cbdee52 Roll Flutter Engine from 59acb5362098 to 12c822327825 (3 revisions) (flutter/flutter#123330)

* 897e3db Inject the gstatic CanvasKit CDN URL by default in `flutter build web` (flutter/flutter#122772)

* 5a36bdd Stop serving Observatory by default (flutter/flutter#122419)

* b212e7b implement Iterator and Comparable instead of extending them (flutter/flutter#123282)

* af6029c c0fbe5a53 Roll Dart SDK from 9256fffbd5af to e8e045620234 (1 revision) (flutter/engine#40561) (flutter/flutter#123336)

* 9dec4fb FIX: NavigationDrawer hover/focus/pressed does not use indicatorShape (flutter/flutter#123325)

* 4907464 20ab040cd Roll Skia from ce5ff5cc03ce to c42320d53714 (2 revisions) (flutter/engine#40565) (flutter/flutter#123340)

* 28d40a4 Roll Packages from 75491e9 to 0826798 (5 revisions) (flutter/flutter#123342)

* 674ff15 [macOS] Add platform_channel sample/test (flutter/flutter#123141)

* 7b7af9f roll packages (flutter/flutter#123339)

* 3179875 replace some ._() constructors with class modifiers (flutter/flutter#122765)

* 7f41ab2 Fix (insert|move|remove)RenderObjectChild methods in base class (flutter/flutter#123276)

* fccca49 Refactor buildOverscrollIndicator (flutter/flutter#123246)

* 11bbce1 6b0933e74 [web] Add `dart:js_interop` to `_embedder.yaml`. (flutter/engine#40545) (flutter/flutter#123347)

* 716d252 Remove prefer_const_constructors ignores (flutter/flutter#123284)

* 100cf21 Prefer enum over class. (flutter/flutter#123312)

* 5ef9b84 Expose toggle to textfield's opacity animation. (flutter/flutter#122474)

* d79f3aa Roll Flutter Engine from 6b0933e74965 to bdce896fb64f (2 revisions) (flutter/flutter#123351)
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 autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blinking cursor should use less CPU

5 participants