-
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
[TextInput][iOS] Default color should adapt to Dark Mode #38014
Conversation
Base commit: 0e41ad0 |
I think this change is likely to break existing apps which are not color scheme aware. I think this is more a bug that RNTester changes background colors in response to color scheme but not text color. |
Imagine a scenario where an app has multiple surfaces. Some are color scheme aware and subscribe to that information from RN, but sone are not scheme aware. Would RN need to tell iOS that it is color scheme aware in order to be able to observe these changes? |
When you say, "color scheme aware", do you mean that the RN surface has been designed for both light and dark mode? So in your case an app might have surface 1 and 2 be color scheme aware, but not surface 3? If so, then it sounds like surface 3 has a bug. |
A few more notes:
|
So, say there is some code written before dark mode which sets a background to white, and adds a TextInput. At the time it was written, the TextInput would show black on white. Now later, we have color schemes, and hooks like The place where I think this might fall down a bit is if you are embedding some leaf-node native component, where it would be themed according to color scheme. On the native iOS side, you mentioned an app-wide plist. Is there something more scoped for this sort of thing? I still expect this change is probably too breaking though. |
Every UIView in iOS has a UITraitCollection that tells you its current color scheme. This allows you to force specific views to be light/dark as you wish, I believe. Prior to RN 0.72, there wasn't a way to set that. Now, there's the setColorScheme() hook. Looking at its implementation, it is setting it app wide instead of just the root view, but 🤷🏽♂️. The leaf node native component would follow the OS unless you pass in colors to it, yes. So if you had a light-only experience in dark mode, you didn't call |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Eh... will revisit in new years. I want to do a comparison of native platforms & their dark modes and see what the standard is outside of RN |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
Currently, TextInputs on iOS explicitly default to having black as the text color. This seems wrong: ever since dark mode was introduced, defaults should adapt to the OS (Be it Light/Dark/Increase Contrast / Dark Elevated, etc). That is the benefit of using UIKit system controls, they're tightly coupled to the OS. If the user wanted the TextInput to always be a specific color (because they hardcoded the background color), then they can specify that in the
style
prop. If their app doesn't support dark mode, then their app plist should reflect that.I looked into the commit history, and it seems the change was introduced here. It seems that when Dark Mode was introduced, the "default" text color changing to depend on system theme was seen as an RN regression. This is simply not true, iOS Dark Mode was opt in, and intentionally changed the defaults and asked apps to adapt their style to match. The "breaking change" was not in RN, but in the OS itself. Had the app been purely native, there would still be a change. I don't think it's RN's job to enforce a default when the OS itself has changed it, I think RN should follow the OS.
Changelog:
[IOS] [FIXED] - TextInput default color should adapt to Dark Mode
Test Plan:
Tested the TextInput example page on RNTester in dark mode before and after my change.
Before:
![Screenshot 2023-06-21 at 11 09 26 PM](https://private-user-images.githubusercontent.com/6722175/247841073-5d9b747b-f376-4b4e-bea3-07757278fb30.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NjM0MzQsIm5iZiI6MTczODk2MzEzNCwicGF0aCI6Ii82NzIyMTc1LzI0Nzg0MTA3My01ZDliNzQ3Yi1mMzc2LTRiNGUtYmVhMy0wNzc1NzI3OGZiMzAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMjExODU0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmQ3ZmJiYzMzNjE1ODdlZGU5YjRhYzVhNTdkZWQ5YTgyNWE5Y2ZhN2Q5OTRkZDgwY2MxZTFmZjk0YTQ2YTY1NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.f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