-
Notifications
You must be signed in to change notification settings - Fork 163
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
Add support for PlatformColors - change colors to use ColorValue as type #694
Conversation
apps/fluent-tester/src/FluentTester/TestComponents/Checkbox/CheckboxTest.tsx
Outdated
Show resolved
Hide resolved
apps/fluent-tester/src/FluentTester/theme/ThemePickers.android.tsx
Outdated
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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..
@@ -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'; |
There was a problem hiding this comment.
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...
Platforms Impacted
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 theColorValue
type instead ofstring
so our color tokens can acceptPlatformColors
.The main hangups on this change are:
react-native-svg
andreact-native-picker
are still on RN 0.61, and thus don't support the use ofColorValue
as the type for their colors. This means we have to passstring
s for those colors to components that use those packages. The main concern for that within the repo is the use of svg-based icons inIcon.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 supportingPlatformColor
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 fromsvgIconProps
which is fixed tostring
type, with some fallback logic.I have to add a decent number of casts to the code due to the fact that ColorValue is of typeWas able to finally get this working, but we have to usestring | unique symbol
and assigning aColorValue
to an object property makes the TS compiler complain, asstring | symbol
is not the same asstring | 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.ColorValue
directly fromreact-native
for things to work. Because of this, I'm removing theColorValue
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 removingColorValue
.theming-utils
package to house some theme-agnostic logic, had to moveAppearanceOptions
andThemeOptions
under thetheme-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):