-
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
Allow PlatformColor to work with RCTView border colors #29728
Allow PlatformColor to work with RCTView border colors #29728
Conversation
Base commit: 36b0f7d |
Base commit: 2d34c22 |
Is there a chance to have it in |
@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! |
Hi @shergin 👋 I would love to move this PR forward. Is there anything missing in order to get it merged? |
The failing circleci test seem to be unrelated:
|
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 |
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. |
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. import React from 'react';
import { Appearance, Platform, PlatformColor, SafeAreaView, StatusBar, StyleSheet, Text, View } from 'react-native';
const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={styles.container}>
<View style={styles.borderTest}>
<Text>Border Color Test</Text>
</View>
<View style={styles.information}>
<Text>Current Color Scheme: {Appearance.getColorScheme()}</Text>
</View>
</SafeAreaView>
</>
);
};
const styles = 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',
},
});
export default App; |
I think I'm a little confused at this point 😅, is this recap correct? Before this diff: After this diff: Is this correct? |
@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 :) |
@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. |
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
946f4a3
Compare
@TheSavior I updated the |
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 ? |
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. |
@p-sun has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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
@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 facebook@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: facebook#33176 Test Plan: Nothing to test. See PR facebook#29728 Reviewed By: javache Differential Revision: D34461141 Pulled By: genkikondo fbshipit-source-id: 51adf39c1cebe8e3b53285961358e4c7f26192db
Summary: facebook@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: facebook#32492 Test Plan: Same test plan as facebook#29728 Reviewed By: sammy-SC Differential Revision: D33819225 Pulled By: cortinico fbshipit-source-id: 2f8024be7ee7b32d1852373b47fa1437cc569391
Summary
Using
PlatformColor
with 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 asUIColor
so 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
PlatformColor
orDynamicColorIOS
to a view border color.