-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Update visual style of CupertinoSwitch to match iOS 13 #36087
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. While there are exceptions to this rule, if this patch modifies code it is probably not an exception. Reviewers: Read the Tree Hygine page and make sure this patch meets those guidelines before LGTMing. /cc @dnfield |
|
Hi @brandondiamond thank you for contributing, the PR looks awesome! However tests are mandatory for PRs like this. Could you add tests to ensure it works as expected? In case you want to add golden tests: https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter |
|
Thanks so much for the quick review! I'll get started on those golden tests right away. Given that this is a visual change, are there any additional tests (beyond the golden tests) that you would suggest? |
|
@brandondiamond thanks for the GIFs! Adding golden images when the switch is inactive/active/somewhere in between should be good enough. |
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks Justin! I added a clip to ensure the thumb shadow doesn't exceed the track. I know clipping can be expensive so wanted to verify that it'd be okay in this case. I also wanted to be mindful of antialiasing (since the clip is curved), so I used saveLayer to group the thumb drawing commands together. There's an additional save() and restore() around the clip because I wasn't certain whether there's an automatic save/restore around each paint() -- particularly for render objects that don't mark repaint boundaries; I don't want subsequent drawing operations to be affected by the clip. I'm very grateful for the opportunity to contribute -- thanks again for reviewing :) |
|
Added golden tests and generated goldens. I followed the instructions here but ran into permission issues when attempting to push my golden assets commit to the repo. What's the correct way to push a change to the goldens repo without special permissions? |
|
Thanks! I tried running this again and now that it's clipped it looks perfect to my eye. Regarding performance and antialiasing, I'm going to track down someone that can confirm. Regarding permissions on the goldens repo, I believe you'll have to fork that repo and open a PR like you did with this PR. I know we tightened up this process recently so I could be wrong, but that's how I did it a few months ago. If you post back with a link to the goldens PR, I can review it really quickly though. |
|
Awesome, thanks Justin :) Here's the goldens PR: Once that goes through, I'll update this PR to reference the commit that includes the new goldens. |
Codecov Report
@@ Coverage Diff @@
## master #36087 +/- ##
==========================================
- Coverage 55.74% 55.36% -0.38%
==========================================
Files 190 188 -2
Lines 17585 17345 -240
==========================================
- Hits 9802 9603 -199
+ Misses 7783 7742 -41
Continue to review full report at Codecov.
|
|
Updated the tests, generated new goldens (ready to go in flutter/goldens#40 -- I'll update the golden hash here once that is merged), and switched to using the PaintingContext to push a clip. |
Co-Authored-By: LongCatIsLooong <[email protected]>
|
Thanks for the review! I'm going to read the style guide today to make sure I don't repeat these formatting mistakes [too often :)] |
|
Goldens merged and bumped the golden version! Should be good to go. |
| )); | ||
| ); | ||
|
|
||
| context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect, (PaintContext innerContext, Offset offset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaintContext => PaintingContext, sorry for the wrong suggestion.
|
No worries! I've made that mistake many times |
Co-Authored-By: LongCatIsLooong <[email protected]>
Co-Authored-By: LongCatIsLooong <[email protected]>
|
Currently blocked by #36690, which will resolve the golden sync issues that are causing the tests to fail here. |
|
Thanks for looking into this. Please let me know if there is anything I can do to help. |
Piinks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#36690 has landed. You may need to update your branch by pulling down the changes from master.
|
@Piinks Thanks! What's the best way to do this without messing up commit history? |
|
You should be able to do a |
|
Thanks so much! Just pushed -- hopefully all looks okay :) |
Piinks
left a comment
There was a problem hiding this 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 contribution! 🎉
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for this! I'll merge soon.




Description
Updates the CupertinoSwitch widget to reflect the revised design of switches in iOS 13. In particular, the border no longer animates in response to user interaction. Instead, the background fades between colors.
After:
https://i.imgur.com/dMV7T5G.gif (slow 5x)
https://i.imgur.com/arKDoNk.gif (normal)
Before:
https://i.imgur.com/SxDYis4.gif (slow 5x)
https://i.imgur.com/k7HCNJU.gif (normal)
Related Issues
Issue #33797
Tests
Added a test to verify golden images of the slider in on and off states.
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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?