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

Add ColorWithSystemEffectMacOS API to react-native-macos #751

Merged
merged 24 commits into from
Apr 1, 2021

Conversation

Saadnajmi
Copy link
Collaborator

@Saadnajmi Saadnajmi commented Mar 25, 2021

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

This PR addresses #750.

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. We do this by extending the NativeColorValue object to take in a colorWithSystemEffect object with two keys: baseColor (itself a ColorValue), and systemEffect (a string representing the system effect. The type of baseColor is ColorValue, meaning it can be a number, string, semantic color, or dynamic color. We also add the appropriate stubs so this API error out on other platforms (like DynamicColorMacOS). We then extend [RCTConvert UIColor:] to handle the new case on the native side.

Changelog

[macOS] [Added] - Added ColorWithSystemEffectMacOS API

Test Plan

I added a new section to the PlatformColor test in RNTester, and checked passing in strings, semantic colors, and dynamic colors to ColorWithSystemEffectMacOS and made sure they rendered correctly in light and dark mode
Screen Shot 2021-03-25 at 1 20 53 AM
Screen Shot 2021-03-25 at 1 20 58 AM

Microsoft Reviewers: Open in CodeFlow

@Saadnajmi Saadnajmi requested a review from alloy as a code owner March 25, 2021 07:01
@Saadnajmi Saadnajmi requested a review from tom-un March 25, 2021 07:04
@Saadnajmi Saadnajmi merged commit 5a3ee83 into microsoft:master Apr 1, 2021
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Apr 4, 2021
* add pull yml

* remove yml

* Getting there..

* Closer..

* Remove commented out code

* More simplification

* remove typo

* Make ColorWithSystemEffect it's own sub-object

* It works!

* Add examples of DynamicColorMacOS with a SystemEffect (currently broken)

* Add None Effect too

* Fix typo

* Essentially feature complete

* Rename API

* Missed a file

* Fix the bug where we call processColor too many times

* Replace blah with the issue number

* Change one more title

* Stub out test on other platforms

* Add ifdef macos check, some null checks, and fix up a bunch of the tags

* Fix more of the tags

* Fix lint errors

* ifdef around colorWithEffect method
@Saadnajmi Saadnajmi deleted the colorwitheffect branch April 4, 2021 02:26
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Jun 1, 2021
* add pull yml

* remove yml

* Getting there..

* Closer..

* Remove commented out code

* More simplification

* remove typo

* Make ColorWithSystemEffect it's own sub-object

* It works!

* Add examples of DynamicColorMacOS with a SystemEffect (currently broken)

* Add None Effect too

* Fix typo

* Essentially feature complete

* Rename API

* Missed a file

* Fix the bug where we call processColor too many times

* Replace blah with the issue number

* Change one more title

* Stub out test on other platforms

* Add ifdef macos check, some null checks, and fix up a bunch of the tags

* Fix more of the tags

* Fix lint errors

* ifdef around colorWithEffect method
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

Successfully merging this pull request may close these issues.

2 participants