-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[Fix] Android/ColorProps
: ColorProps with value null should be defaultColor instead of transparent
#29830
Conversation
Base commit: 4246c75 |
Base commit: 4246c75 |
Nice work! @hank121314 I built RNTester to test this out: Working as expected, tagging PR submitted on the issue. |
cc @JoshuaGross |
Thank you so much for help and testing! 😄 |
Android/Text
: Conditionally change <Text /> color cause text invisibleAndroid/ColorProps
: ColorProps with null should be defaultColor instead of transparent
Android/ColorProps
: ColorProps with null should be defaultColor instead of transparentAndroid/ColorProps
: ColorProps with value null should be defaultColor instead of transparent
I think when the color is undefined it should also fallback to the defaultColor. Take this case: |
Yes, this pr is also included undefined in javascript. |
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
@Override | ||
protected @Nullable Object getValueOrDefault(Object value, Context context) { | ||
if (value != null) { | ||
return ColorPropConverter.getColor(value, context); |
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.
google-java-format
suggested changes:
@@ -337 +337 @@
- return ColorPropConverter.getColor(value, context);
+ return ColorPropConverter.getColor(value, context);
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.
apply google-java-format suggested changes.
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 a lot @hank121314. Your pr also fixes #29378 (not linked in your pr summary), I was searching for the solution as explained in #29412 (comment) and then found your PR from another related issue.
I checkout out your branch and as in the below test case, verified that it fixes also #29378
Thanks a lot. 🙏 ☮️
Hi @fabriziobertoglio1987 . |
@fabriziobertoglio1987 @hank121314 Hi. Could you merge it please? |
This did not fix |
Actually, in general, this fix is not working for me on 0.64.2. |
Hi @taylorkline, did you try to patch this pr with Building from source? |
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, sorry this is taking forever to merge, will ping some people at fb.
@hank121314 No, I did not - my apologies, likely user error on my part then. |
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@lunaleaps merged this pull request in 842bcb9. |
…or instead of transparent (#29830) Summary: This pr: - Fixes: #30183 - Fixes: #30056 - Fixes: #29950 - Fixes: #29717 - Fixes: #29495 - Fixes: #29412 - Fixes: #29378 Because most of ReactProps(name = ViewProps.COLOR) accept @ Nullable Integer. For example: https://github.com/facebook/react-native/blob/abb6433f506851430dffb66f0dd34c1e70a223fe/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java#L472-L479 After update to react-native 0.63.2 to make PlatformColor work, there is a new ColorPropSetter. https://github.com/facebook/react-native/blob/abb6433f506851430dffb66f0dd34c1e70a223fe/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java#L194-L215 But ColorPropSetter won't return an nullable value with getValueOrDefault, it will always return it's defaultValue which is 0. And 0 is equal to TRANSPARENT, will cause <Text /> disappear. ## Changelog [Android] [Fixed] - ColorProps with value null should be defaultColor instead of transparent Pull Request resolved: #29830 Test Plan: Please initiated a new project and replaced the app with the following code: ``` import * as React from 'react'; import {Text, View, TouchableOpacity, PlatformColor} from 'react-native'; export default function App() { const [active, setActive] = React.useState(false); return ( <View> <Text style={active ? {color: 'green'} : null}>Example</Text> <Text style={ active ? {color: PlatformColor('android:color/holo_purple')} : null }> Example2 </Text> <TouchableOpacity onPress={() => setActive(!active)}> <Text>Toggle Active</Text> </TouchableOpacity> </View> ); } ``` Thanks you so much for your code review! Reviewed By: JoshuaGross Differential Revision: D30209262 Pulled By: lunaleaps fbshipit-source-id: bc223f84a92f742266cb7b40eb26722551940d76
Summary
This pr:
Because most of @ReactProps(name = ViewProps.COLOR) accept @ Nullable Integer.
For example:
react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java
Lines 472 to 479 in abb6433
After update to react-native 0.63.2 to make PlatformColor work, there is a new ColorPropSetter.
react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java
Lines 194 to 215 in abb6433
But ColorPropSetter won't return an nullable value with getValueOrDefault, it will always return it's defaultValue which is 0.
And 0 is equal to TRANSPARENT, will cause disappear.
Changelog
[Android] [Fixed] - ColorProps with value null should be defaultColor instead of transparent
Test Plan
Please initiated a new project and replaced the app with the following code:
Thanks you so much for your code review!