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 support for PlatformColors - change colors to use ColorValue as type #694

Merged
merged 38 commits into from
Jun 15, 2021

Conversation

rurikoaraki
Copy link
Collaborator

@rurikoaraki rurikoaraki commented May 13, 2021

Platforms Impacted

  • iOS
  • macOS
  • win32 (Office)
  • windows
  • android

Description of changes

There have been several requests for the color tokens to accept ColorValue, which is the default color type for RN > 0.63 (ex. #642). This PR changes the colors in the repo to use the ColorValue type instead of string so our color tokens can accept PlatformColors.

The main hangups on this change are:

  1. react-native-svg and react-native-picker are still on RN 0.61, and thus don't support the use of ColorValue as the type for their colors. This means we have to pass strings for those colors to components that use those packages. The main concern for that within the repo is the use of svg-based icons in Icon.tsx. For now I've casted the type to force it to be compatible, but if people have other suggestions, I would certainly welcome them. There is an open PR for supporting PlatformColor on the svg repo (Support PlatformColor software-mansion/react-native-svg#1561), and I logged an isue for the picker repo (Support ColorValue type from RN 0.63 react-native-picker/picker#266). In the meantime SvgIcons will take their color from svgIconProps which is fixed to string type, with some fallback logic.
  2. I have to add a decent number of casts to the code due to the fact that ColorValue is of type string | unique symbol and assigning a ColorValue to an object property makes the TS compiler complain, as string | symbol is not the same as string | unique symbol. Casting is the suggested workaround. This issue is tracked at [@types/react-native] Cant assign ColorValue from object DefinitelyTyped/DefinitelyTyped#46864. I'm concerned that this may introduce a build break for people who depend on us, as I've had to add casting to several places to get things to build. Was able to finally get this working, but we have to use ColorValue directly from react-native for things to work. Because of this, I'm removing the ColorValue export, as I think the user experience of fixing that will be better than fixing the break that would happen if we push this change out without removing ColorValue.
  3. Made a new theming-utils package to house some theme-agnostic logic, had to move AppearanceOptions and ThemeOptions under the theme-types package to avoid circular dependency.

Verification

I've run the change through the Fluent UI tester on win32. It seems that the win32 app freezes if you change the Theme or the Brand of the app (this repros without changes, and I'll look into the issue), but toggling between light/dark modes works and colors update accordingly.

Pull request checklist

This PR has considered (when applicable):

  • Automated Tests
  • Documentation and examples
  • Keyboard Accessibility
  • Voiceover
  • Internationalization and Right-to-left Layouts

packages/components/Button/package.json Outdated Show resolved Hide resolved
packages/experimental/Avatar/src/Avatar.tsx Show resolved Hide resolved
@@ -2,44 +2,50 @@ import { buttonName, ButtonTokens, ButtonSlotProps, ButtonProps } from './Button
import { Theme, UseStylingOptions, buildProps } from '@fluentui-react-native/framework';
import { borderStyles, layoutStyles, fontStyles } from '@fluentui-react-native/tokens';
import { buttonStates, defaultButtonTokens } from './ButtonTokens';
import { TextProps } from '@fluentui-react-native/experimental-text';
import { IViewWin32Props } from '@office-iss/react-native-win32';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we import the IViewProps from '@fluentui-react-native/adpaters' so that this works on all platforms a little better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using IViewWin32Props is driven by the root style for this button being defined as using IViewWin32Props in Button.types.ts:

root: React.PropsWithRef<IViewWin32Props>;

I think using IViewProps makes sense, but I think it's out of scope for this change since it's a change to Button and not for supporting ColorValue..

packages/theming/theme-types/package.json Outdated Show resolved Hide resolved
packages/theming/theme-types/src/Color.types.ts Outdated Show resolved Hide resolved
packages/utils/tokens/src/border-tokens.ts Outdated Show resolved Hide resolved
packages/utils/tokens/src/color-tokens.ts Outdated Show resolved Hide resolved
@rurikoaraki rurikoaraki changed the title [WIP] Add support for PlatformColors - change colors to use ColorValue as type Add support for PlatformColors - change colors to use ColorValue as type Jun 9, 2021
@rurikoaraki rurikoaraki marked this pull request as ready for review June 9, 2021 23:55
packages/experimental/Icon/src/Icon.tsx Outdated Show resolved Hide resolved
@@ -1,34 +1,8 @@
import { ThemeReference } from '@fluentui-react-native/theme';
import { defaultFluentDarkTheme, defaultFluentTheme } from './defaultTheme';
import { Appearance } from 'react-native';
import { Theme } from '@fluentui-react-native/theme-types';

export type AppearanceOptions = 'light' | 'dark';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if moving these is a good idea. I can keep them here, but then moving getCurrentAppearance out of the default-theme package feels weird since it feels like a circular dependency...

@rurikoaraki rurikoaraki merged commit 90e0dcb into microsoft:master Jun 15, 2021
@rurikoaraki rurikoaraki deleted the change_colors_to_colorvalue branch July 23, 2021 19:21
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.

4 participants