-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[Android] Fix ReactSwitch for non RippleDrawable backgrounds #32468
Conversation
Hi @smarki! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
ee41708
to
df8822f
Compare
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.
Code analysis results:
google-java-format
found some issues. See https://github.com/google/google-java-format
ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java
Show resolved
Hide resolved
ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java
Show resolved
Hide resolved
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
df8822f
to
50d2993
Compare
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.
Code analysis results:
google-java-format
found some issues. See https://github.com/google/google-java-format
ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java
Outdated
Show resolved
Hide resolved
PR build artifact for 50d2993 is ready. |
Base commit: 24d4184 |
Base commit: 24d4184 |
50d2993
to
1a26207
Compare
PR build artifact for 1a26207 is ready. |
What is the process to back-port an MR? It would be nice if we can have it on v0.66 given that v0.67 is still RC. |
@cortinico has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
You would have to comment here reactwg/react-native-releases#3 |
@smarki, thanks for submitting this change! |
PR build artifact for 80a643f is ready. |
@cortinico has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@cortinico merged this pull request in 456cf3d. |
Summary
ReactSwitch component is crashing on Android when it is initialised with both a backgroundColor and thumbColor,
style={{ backgroundColor: "anyColor" }} thumbColor="anyColor"
, due to IllegalCastException.When setting a background color, BaseViewManagerDelegate is calling
setBackgroundColor
which replaces the background drawable with a ColorDrawale, hence this line fails.Instead, given the ripple effect needs to be preserved, one should initialise a RippleDrawable using the current background drawable and set it as the background of the switch.
Given the RippleDrawable should be preserved, overriding the
setBackgroundColor
seemed the sensible thing to do.Changelog
[Android] [Fixed] - Fix crash when a Switch is initialised with both backgroundColor and thumbColor.
Test Plan
Setup:
Initialise an empty React Native project. Add a switch component:
<Switch style={{backgroundColor: 'red'}} thumbColor={'#356'} />
Run the project
yarn android
Current state (RN 65+):
Red screen will show highlighting an IllegalCastException.
With fix:
backgroundColor
withthumbColor
:Just

thumbColor
: