-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Beta: theme improvements, component specific themes, animations #41
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8f6d2ae
to
e259f27
Compare
dabe600
to
17a585e
Compare
This was referenced Mar 24, 2022
Closed
6c8f3ee
to
cb28d03
Compare
df49676
to
79c95d8
Compare
a20aaf9
to
5490013
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is growing a bit, it started as an experiment with animations, but in doing so I think I've figured out a few problems and solutions within themes. There's a lot of improvements overall, so I've decided to just turn it into a big "beta" PR that once merged should be ready for a beta release.
Along with that, I'll aim to really break as many API's at once here (rip the band-aid, so to speak).
There are big upgrades already in place, and now just want to fix, polish, optimize and finish them:
Themes
Theme's worked, but didn't really give you much flexibility on a component level at all. This is fixed now. Previously I'd just went for each theme having a variety of shades, like
bg
,bg2
, etc, and then letting components use any shade they wanted . There were a variety of problems with this:bg2
for background,bg3
for hover...)The fix comes in two parts. First, instead of shades each theme just represents a single set of colors across all states:
bg
,bg2
Tamagui now just maps to statesbackground
,backgroundHover
,backgroundPress
,backgroundFocus
borderColor
,borderColorHover
, ....)This doesn't really solve either problem beyond giving us much more consistent naming and avoiding the idea of shades within a single theme.
Next, we need a way to have buttons for example be themed differently from inputs.
I explored for a while various ideas on this, the obvious one was something like
buttonBackground
,buttonBackgroundHover
, etc. But this raised tons of issues:buttonBackground
just grabbackground
? We can’t expect themes to define colors for every component (think Separator, where borderColor should be a very reasonable default). But at the same time every component should be customizable.styled(Stack, { backgroundColor: ['$buttonBackgroundColor', '$backgroundColor'] })
. This would be a nightmare to implement in terms of complexity, you'd have to implement it at runtime, compile-time, and in types.It wasn't until playing with animations on a small sandbox project that a much simpler, and solution we already have existing today would work: Sub-themes to the rescue!
Sub-themes already work, and are a hugely helpful feature. You could use them to get around some of the limitation already, but you'd be forced to specify a
theme
prop on every button. So right now you could now define alight
theme and alight-button
theme and theme do:And technically you'd have a nice way of fully controlling themes of buttons. But it's brittle in a few ways. First is that the
theme
prop only works if you wrap a component withthemeable
, it doesn't come out of the box if you just make astyled
component. That's something I'm exploring enabling in this PR as well - it has some complexity that needs accounting for. Luckily, it's not necessary to solve immediately, because...Tamagui will automatically find component themes
Instead of having one giant theme (
background
etc) with all sorts of component specific keys (likebuttonBackground
,separatorBackground
, etc)... instead, have a as many small themes as you want. Something like:This should also work with tinting/shading/sub-themes (whatever you want to call it):
Even better, it lets you set up a bunch of base shaded themes and then just choose/share them across components as needed:
Nice! This is incredibly flexible, giving you full power to override themes for every component, across every shade, all while sharing the same themes so there's no real extra object keys and values.
Typings get some fixes too so
<Theme name="blue">
is accepted as valid, and like it works now, so long as you have a parent<Theme name="light">
you'll automatically get thelight-blue
theme ✨.This is really exciting stuff. I need to finish some component-specific pieces here, but there's nothing major blocking for this to land now most of the hard work is in place.
Animations
Animations! This was supposed to be the big part of this branch, but turns out themes were really the star. I'll write a lot more, but this is also really cool. Tamagui really needed to have animations solved before going deeper into a variety of fixes, improvements and other components up next. For newly landed components like Tooltip, it was clear figuring out animations up front is necessary or else we end up with lots of baggage.
I won't go too deep, but basically
createTamagui
accepts ananimations
key now, and you can swap out your entire animation driver based on the platform 🤯.So your
animations.native.ts
can have:But your
animations.web.ts
instead can do:And we can then have anyone add other drivers, like motion for example.
More to come!