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
Support tintColor and thumbTintColor for Switch on Android #11940
Conversation
By analyzing the blame information on this pull request, we identified @emilsjolander and @bestander to be potential reviewers. |
@ReactProp(name = "thumbTintColor", customType = "Color") | ||
public void setThumbTintColor(ReactSwitch view, Integer color) { | ||
int thumbTintColor = color != null ? color : DEFAULT_THUMB_TINT_COLOR; | ||
view.getThumbDrawable().setColorFilter(thumbTintColor, PorterDuff.Mode.MULTIPLY); |
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.
Does passing setColorFilter(null) works to reset to default instead of having to provide default colors?
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.
My mistake. Result of trying too many different ways to do this. Fixed.
Updated @janicduplessis |
@facebook-github-bot shipit |
@janicduplessis has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Nice! |
@facebook-github-bot shipit |
@janicduplessis has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Correct me if I'm wrong but it looks like this will only color the thumb one color and the track one color. I think for android users it may look a little strange this way, since by default android has 2 colors for the switch (disabled/enabled colors). Btw I actually have a similar PR open for this #11474. |
What do you mean? Are you saying user shouldn't be able to set different colors? Nothing stops the user from using the same color for both thumb and the track. |
@satya164 No I don't think thats an issue. My comment was just when skimming over your changes. I didn't see that you handled the off track color, I see that now though. I was also referring to the switch thumb color not being able to change since there is only one prop for that, but I guess you could just do something like this One issue I did notice when testing was if |
You can still set custom colours when it's disabled |
Waiting for @satya164 to update the screenshot so tests pass. |
Let's see again what failed, if anything. Merging. |
@mkonicek has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook/react-native#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Summary: **Motivation** `Switch` on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors. The PR adds support for the `tintColor`, `onTintColor` and `thumbTintColor` props on Android, which more or less behave the same as iOS. The only difference is `tintColor` styles the border color on iOS, whereas it styles the background color on Android. **Test plan (required)** Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare. ![image](https://cloud.githubusercontent.com/assets/1174278/22018002/b05d6482-dcd2-11e6-9c00-f55a71d6ce29.png) ![image](https://cloud.githubusercontent.com/assets/1174278/22018012/b923e974-dcd2-11e6-8d4e-86994f5a66e6.png) cc brentvatne Closes facebook#11940 Differential Revision: D4427491 fbshipit-source-id: 16c569d2e2261daaea93fffa83198f8f6b59a6c8
Motivation
Switch
on Android doesn't allow changing the colors unlike iOS. Changing the colors is desirable in a lot of cases to match the brand colors.The PR adds support for the
tintColor
,onTintColor
andthumbTintColor
props on Android, which more or less behave the same as iOS. The only difference istintColor
styles the border color on iOS, whereas it styles the background color on Android.Test plan (required)
Run UIExplorer with the changes, and ensure that the switch example works properly. Here are screenshots from iOS and Android to compare.
cc @brentvatne