Skip to content
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

Colors should change depending on light/dark color scheme #290

Closed
MaxDesiatov opened this issue Oct 18, 2020 · 3 comments · Fixed by #291
Closed

Colors should change depending on light/dark color scheme #290

MaxDesiatov opened this issue Oct 18, 2020 · 3 comments · Fixed by #291
Labels
bug Something isn't working

Comments

@MaxDesiatov
Copy link
Collaborator

Thanks to the amazing research done by @Cosmo, it can be seen that multiple colors change based on the current color scheme, not just primary/secondary:

image

@MaxDesiatov MaxDesiatov added the bug Something isn't working label Oct 18, 2020
@MaxDesiatov
Copy link
Collaborator Author

As Devran mentioned, we should pay attention to the var provider: AnyColorBox property on Color.

@Cosmo
Copy link

Cosmo commented Oct 18, 2020

In my research, for OpenSwiftUI, I found out that the type Color doesn't hold any color values -- only another class type of AnyColorBox.
Its the renderes job to figure out what that value of AnyColorBox represents.

By default, in SwiftUI you have SystemColorType: AnyColorBox and DisplayP3: AnyColorBox.
SystemColorType represents values like .red, .blue, .purple, -- so only names.
And DisplayP3 stores values in RGBA channels.

A color of type DisplayP3 is always the same color -- whereas .red of SystemColorType can be different depending on the environment (for instance color scheme).

image

This architecutre gives the possiblity to implement HexColor: AnyColorBox if you want to.
Or go even crazier. You could write Nanometer: AnyColorBox and store the color value in nanometers and draw with UV or infrared light -- all without modifying a thing in Color.

You can find my implementation of Color here:
https://github.com/Cosmo/OpenSwiftUI/blob/master/Sources/OpenSwiftUI/Views/Color.swift

A similar thing is going on with the Font type where font sizes are not stored in the Core implementation. Only the renderer knows how big a .title should be and look like. This architecture is a bit more complex, but its the only way to become compatible with Apple's SwiftUI and remove platform specific dependencies to get fully platform-agnostic.

@carson-katri
Copy link
Member

Image is also a "late-binding token", I assume for SFSymbols and the imageScale/other image-specific environment values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants