[android] support checkbox tinting#18300
Conversation
Generated by 🚫 dangerJS |
7b95a13 to
0b4325b
Compare
There was a problem hiding this comment.
this is taken from ToolbarAndroid
There was a problem hiding this comment.
would be nice to have only one CompoundButtonCompat.setButtonTintList call instead of two, but I'm afraid it would break the tests (because they are somehow unstable lately), so I'm leaving it as-is for now.
|
@vonovak I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project. |
|
@janicduplessis you mentioned in #18318 (comment) that you were going to review this PR, may I ask you for the review? Thanks. |
There was a problem hiding this comment.
I wonder if we could simplify the logic a bit by moving this to ReactCheckBox.java and saving the colors of the checked / unchecked status as nullable int ivars (null means the theme color). That way we don't have to do to much crazy stuff with the ColorStateList class. We can have a simple updateColorStateList method that reads both of those instance variables to create and set a new ColorStateList. Then we can have two new methods on ReactCheckBox; setCheckedTintColor and setUncheckedTintColor that just update one of the ivar and calls updateColorStateList.
Let me know if that makes sense.
There was a problem hiding this comment.
You can use ColorPropType instead of PropTypes.string
There was a problem hiding this comment.
Maybe we should call it checkedTintColor instead for consistency with other components (I was looking at Switch). Same for unchecked.
There was a problem hiding this comment.
Can we move this to setCheckboxTintList instead of passing it as arguments, seems like we always pass the same values.
There was a problem hiding this comment.
we always pass the same values, but in different order:
setCheckboxTintList(..., defaultColorIdOfUncheckedState, defaultColorIdOfCheckedState);
setCheckboxTintList(..., defaultColorIdOfCheckedState, defaultColorIdOfUncheckedState);
I guess I should rename those vars
Summary: The checkbox components inherits from `android.widget.CheckBox`. `AppCompatCheckBox` offers better appearance and support for advanced features (eg. tinting) on older APIs. ~~However, the build fails for some reason; If somebody could shed some light on this, I'd appreciate it.~~ Thanks for the comment, I was being blind and somehow ignored the BUCK file. I have created a simple app with a checkbox. Screenshot from android 4.1 (current master): <img src="https://user-images.githubusercontent.com/1566403/37357997-2d34bdb8-26ea-11e8-8c77-709a4f96c6bf.png" width="300" /> Screenshot after applying the change, also android 4.1: <img src="https://user-images.githubusercontent.com/1566403/37358016-3c28fb86-26ea-11e8-8dca-3a92e41450c9.png" width="300" /> #18300 (this PR is needed to support tinting on older android api levels) [ANDROID] [ENHANCEMENT] [Checkbox] - Checkbox inherits from AppCompatCheckBox Closes #18318 Differential Revision: D7268393 Pulled By: hramos fbshipit-source-id: 01cb2819f4d56c4e0f94cdd1fb5e1a90667a398a
yes, that would certainly lead to simpler code. The approach I took was using @janicduplessis please let me know if I should keep the logic the way it is or rewrite it as you suggested. Thanks. |
|
@janicduplessis can you please answer to my comment above? Thanks. |
|
@janicduplessis could you please answer to my comment above? Thanks :) |
|
@vonovak Hey! Please go with the suggestion from @janicduplessis to simplify your code a lot, and then we can land this change. |
|
@cpojer thanks for the comment. I have another suggestion: taking a look at the switch, the How about doing it the same way here? That would simplify the code even more, as it would allow to use the |
930a34f to
ea0d12f
Compare
analysis-bot
left a comment
There was a problem hiding this comment.
Code analysis results:
eslintfound some issues.flowfound some issues.
There was a problem hiding this comment.
no-undef: 'getRandomInt' is not defined.
There was a problem hiding this comment.
Cannot get this.state.checked because property checked is missing in undefined [1].
There was a problem hiding this comment.
Cannot call this.setState with object literal bound to partialState because property checked is missing in undefined [1] but exists in object literal [2].
analysis-bot
left a comment
There was a problem hiding this comment.
Code analysis results:
eslintfound some issues.
aa2ff99 to
61814b2
Compare
|
@janicduplessis would you care to do a final review of this? |
janicduplessis
left a comment
There was a problem hiding this comment.
Looks good, just some comments about the flow types.
|
|
||
| type Props = $ReadOnly<{| | ||
| ...CommonProps, | ||
| tintColors?: {|true?: ColorValue, false?: ColorValue|}, |
There was a problem hiding this comment.
Same comments about the type
| style: [styles.rctCheckBox, style], | ||
| }; | ||
|
|
||
| console.warn('render'); |
There was a problem hiding this comment.
oops, thanks, removed
cpojer
left a comment
There was a problem hiding this comment.
Awesome, thank you for your work on this!
facebook-github-bot
left a comment
There was a problem hiding this comment.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Motivation
RN offers checkbox component on android: https://facebook.github.io/react-native/docs/checkbox.html
The Checkbox colors for checked and unchecked states cannot be controlled from JS at the moment; this PR adds support for that.
The essence of changing colors for the states is this:
Because of this, I did it so that both colors have to provided together in an object. This is similar to switch
Test Plan
I have added this to the RN tester.
Related PRs
#11940 Support tintColor and thumbTintColor for Switch on Android
Release Notes
[ANDROID] [FEATURE] [Checkbox] - support custom colors of checked and unchecked states