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

Feature: Add support for NSColorWithSystemEffect to the Color API #750

Closed
Saadnajmi opened this issue Mar 25, 2021 · 2 comments
Closed

Feature: Add support for NSColorWithSystemEffect to the Color API #750

Saadnajmi opened this issue Mar 25, 2021 · 2 comments
Assignees

Comments

@Saadnajmi
Copy link
Collaborator

Proposal: Add support for NSColorWithSystemEffect to the Color API

Summary

Starting from macOS 10.14, Apple introduced the API colorWithSystemEffect, which allows you to add system effects to colors like "pressed", "rollover" (mouse hover), and "disabled". This marks a change where Apple is telling us to use the System API to style our custom component's colors for various states, rather than coming up with the colors ourselves. Currently, this API is not accessible to react-native-macos, meaning our components won't look and feel right on the platform going forward. Let's expose this API in a similar fashion to how we expose PlatformColor and DynamicColorMacOS.

Motivation

The main motivation came from trying to handle convergence in styling between FluentUI Apple and FluentUI React Native .

In FluentUI Apple, we make use of the colorWithSystemEffect API to style our custom button. To achieve the same effect on FluentUI React Native, we need to use a native module to apply the system effect and convert the color to a hex string. This is very cumbersome, ugly, and not future proof (what if Apple decides to use a colorspace that can't be converted to the sRGB colorspace in a future release?). We shouldn't need to do this since we already have a mechanism for exposing system defined color: PlatformColor. I believe this is a perfect example of a platform specific color API that belongs in React Native.

Basic example


const viewBackgroundColor = enabled ? 'blue' : ColorWithSystemEffectMacOS('blue', 'disabled')

...

<View
  style={{
    backgroundColor: color: viewBackgroundColor,
  }}
/>

Open Questions

  1. Should we style Pressable to use the new ColorWithSystemEffect API by default? The current behavior does not match the system colors.
@chrisglein
Copy link
Member

@Saadnajmi looks like you merged the change. Okay to close?

@Saadnajmi
Copy link
Collaborator Author

@chrisglein probably OK. I wanted to ask @HeyImChris if we want to cherry pick this commit into RN 0.63, which is why I hadn't closed it yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants