Uh oh!
There was an error while loading. Please reload this page.
Allow PlatformColor to work with RCTView border colors - #29728
Allow PlatformColor to work with RCTView border colors#29728danilobuerger wants to merge 2 commits into
Conversation
Base commit: 36b0f7d |
analysis-bot
commented
Aug 22, 2020
Base commit: 2d34c22 |
rosskhanas
commented
Sep 26, 2020
Is there a chance to have it in |
rosskhanas
commented
Sep 30, 2020
@danilobuerger this PR implements proper border support on iOS, how about the Android support? At the moment border color on Android does not work at all with PlatformColor. Thank you! |
danilobuerger
commented
Oct 5, 2020
Hi @shergin 👋 I would love to move this PR forward. Is there anything missing in order to get it merged? |
danilobuerger
commented
Oct 5, 2020
The failing circleci test seem to be unrelated:
|
elicwhite
commented
Oct 26, 2020
Following up on this, does PlatformColor work on Android for border colors? If things are currently consistent (with it not working on either platform) and this PR will diverge the platforms, we aren't likely to merge this. If they already work on Android and this just fixes iOS then this is fine. Otherwise we will need a PR adding support on Android |
kuasha420
commented
Oct 27, 2020
This PR seems to be focused on Applying PlatformColor to borderColor on color scheme switch via DynamicColorIOS which doesn't exist for Android. However, from my testing, PlatformColor can't be applied to borderColor of a view on Android. This error pops up. |
elicwhite
commented
Oct 27, 2020
On the native side I'd expect any property that can accept PlatformColor would also be able to accept DynamicColorIOS on iOS. So yeah, it sounds like the behavior is currently consistent between iOS and Android and neither of them support using PlatformColor on borders. For this feature to land, there should be an addition to the RNTester PlatformColor screen that exercises setting border colors, and their should be an implementation for Android, either in this PR or a separate PR. |
Not quite. Looks like PlatformColor works just fine as borderColor on IOS. importReactfrom'react';import{Appearance,Platform,PlatformColor,SafeAreaView,StatusBar,StyleSheet,Text,View}from'react-native';constApp=()=>{return(<><StatusBarbarStyle="dark-content"/><SafeAreaViewstyle={styles.container}><Viewstyle={styles.borderTest}><Text>BorderColorTest</Text></View><Viewstyle={styles.information}><Text>CurrentColorScheme: {Appearance.getColorScheme()}</Text></View></SafeAreaView></>);};conststyles=StyleSheet.create({container: {flex: 1,},borderTest: {borderWidth: 5,
...Platform.select({ios: {borderColor: PlatformColor('systemBlue'),},android: {borderColor: PlatformColor('@android:color/holo_blue_bright'),},default: {borderColor: 'red',},}),alignItems: 'center',justifyContent: 'center',flex: 1,},information: {alignItems: 'center',justifyContent: 'center',},});exportdefaultApp; |
I think I'm a little confused at this point 😅, is this recap correct? Before this diff: After this diff: Is this correct? |
kuasha420
commented
Oct 28, 2020
@TheSavior whoops. I think I've confused you more. There's the situation from my testing. Before the diff
After the diff 1, 2 & 3 remains unchanged.
In summery, this PR just fixes dynamicColorIOS to dynamically apply border color on runtime color scheme change. PlatformColor as border color never worked on android anyways. The Title of the PR is misleading, the description is correct. |
@TheSavior PlatformColor as borderColor works on ios. but crashes on android (In both RN63.3 & master with this diff). I don't think it's expected :) |
guyca
commented
Oct 28, 2020
@kuasha420 Any Android error you encounter is not related to this PR and was not caused by it. As you've mentioned, this PR addresses a specific bug on iOS. It was never intended to fix all As no regressions were introduced by this PR, and it does fix the issue described, what's holding us back from merging it and benefiting from it? 💪 |
@guyca Other than the confusing title that tripped off @TheSavior the PR is Good to go imho. The title should be fix: allow DynamicColorIOS to dynamically apply correct borderColor on Color Scheme change. |
elicwhite
commented
Oct 28, 2020
Alright, this extra context makes sense. Thanks for breaking it down for me. I've updated the title. I'm not familiar with the native code backing the colors, but I'm kinda surprised that the native code to support PlatformColor doesn't automatically work for DynamicColorIOS. That seems ripe for other potential issues down the road. cc @tom-un, does this PR look good to you? This PR should also update the RNTester screen for Colors to exercise this use case in order to make sure we don't cause regressions here in the future. It would be an update to this file: https://github.com/facebook/react-native/blob/master/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js |
@kuasha420 thanks for looking into it. However, your assessment of @TheSavior the title was correct. This also fixes a bug with |
This changes border colors to use UIColor instead of CGColor. Only then can dark mode switch to the appropriate color.
dff50e8 to
946f4a3Comparedanilobuerger
commented
Oct 28, 2020
@TheSavior I updated the |
birkir
commented
May 29, 2021
The tests that are failing seem unrelated to this PR. Any chance of getting this PR merged, allowing for cherry pick into 0.64.2 ? |
danilobuerger
commented
Jun 11, 2021
Hi @p-sun since you recently merged another PlatformColor PR, do you mind giving this one some attention? I have been waiting for a review since August 2020 now. |
facebook-github-bot
commented
Jun 21, 2021
@p-sun has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
facebook-github-bot
commented
Jun 23, 2021
Summary: # See PR #29728 # From PR Author Using `PlatformColor` with border colors doesn't work currently when switching dark mode as the information is lost when converting to `CGColor`. This change keeps the border colors around as `UIColor` so switching to dark mode works. ```ts <View style={{ borderColor: DynamicColorIOS({ dark: "yellow", light: "red" }), borderWidth: 1, }} > ... </View> ``` This view will start with a red border (assuming light mode when started), but will not change to a yellow border when switching to dark mode. With this PR, the border color will be correctly set to yellow. ## Changelog [iOS] [Fixed] - Allow PlatformColor to work with border colors Pull Request resolved: #29728 Test Plan: 1. Assign a `PlatformColor` or `DynamicColorIOS` to a view border color. 2. Toggle between dark / light mode. See the colors change. Reviewed By: lunaleaps Differential Revision: D29268376 Pulled By: p-sun fbshipit-source-id: 586545b05be0beb0e6e5ace6e3f74b304620ad94
a-eid
commented
Jan 21, 2022
@danilobuerger any chance to support android as well #32942 |
Summary: c974cbf changed the border colors to be of UIColor instead of CGColor. This allowed working with dark mode to switch the border colors automatically. However, in certain situation the system can't resolve the current trait collection (see https://stackoverflow.com/a/57177411/2525941). This commit resolves the colors with the current trait collection to ensure the right colors are selected. This matches with the behavior of how the background color is resolved (also in displayLayer:). ## Changelog [iOS] [Fixed] - Resolve border platform color based on current trait collection Pull Request resolved: #32492 Test Plan: Same test plan as #29728 Reviewed By: sammy-SC Differential Revision: D33819225 Pulled By: cortinico fbshipit-source-id: 2f8024be7ee7b32d1852373b47fa1437cc569391
Summary: In c974cbf I changed the borderColor from CGColor to UIColor. I missed this view property which should also be updated to reflect the original change. ## Changelog [iOS] [Fixed] - Set RCTView borderColor to UIColor Pull Request resolved: #33176 Test Plan: Nothing to test. See PR #29728 Reviewed By: javache Differential Revision: D34461141 Pulled By: genkikondo fbshipit-source-id: 51adf39c1cebe8e3b53285961358e4c7f26192db
Summary: In react@c974cbf I changed the borderColor from CGColor to UIColor. I missed this view property which should also be updated to reflect the original change. ## Changelog [iOS] [Fixed] - Set RCTView borderColor to UIColor Pull Request resolved: react#33176 Test Plan: Nothing to test. See PR react#29728 Reviewed By: javache Differential Revision: D34461141 Pulled By: genkikondo fbshipit-source-id: 51adf39c1cebe8e3b53285961358e4c7f26192db


Summary
Using
PlatformColorwith border colors doesn't work currently when switching dark mode as the information is lost when converting toCGColor. This change keeps the border colors around asUIColorso switching to dark mode works.This view will start with a red border (assuming light mode when started), but will not change to a yellow border when switching to dark mode. With this PR, the border color will be correctly set to yellow.
Changelog
[iOS] [Fixed] - Allow PlatformColor to work with border colors
Test Plan
PlatformColororDynamicColorIOSto a view border color.