Migration from version 1.x
Unistyles 2.0 introduces several breaking changes, most of which are easy to resolve.
Additionally, remember that Unistyles utilizes native modules, so it’s necessary to run pod install
after upgrading.
For more information, visit here.
1. Remove your UnistylesTheme
The library now facilitates C++
with HostObject
eliminating the need for React Context.
Additionally, a simpler API has been introduced to change themes at any time. Therefore, you can now unwrap your app from UnistylesTheme
.
2. Remove createUnistyles
With the power of TypeScript types, you no longer need to use createUnistyles
. There is also a new way to register
necessary configs. You can safely remove these lines of code.
3. Breakpoints
In version 2.0, breakpoints are optional. If your app wasn’t using them, you can delete your breakpoints object. For those who were using breakpoints, there are no breaking changes.
4. Theming
You can use the same themes. You just need to give them unique names, as explained in the later steps.
5. TypeScript types
In step 2, you removed createUnistyles
. This factory was previously used to pass types to the core of the library.
To register your types now, you need to override the library types with the following syntax:
Use your unique theme names to create an AppThemes
type. If you don’t use themes or breakpoints, you can skip this step.
It’s only required if you want to achieve perfect IntelliSense integration across your app.
6. Register your themes and breakpoint with UnistylesRegistry
If you want to learn more about UnistylesRegistry
follow this guide.
7. Change your imports
This is the most tedious part, but it guarantees perfect TypeScript types throughout your app.
You can now import createStyleSheet
and useStyles
directly from the library.
8. createStyleSheet
and useStyles
Both have been improved with additional features and without introducing any breaking changes!
9. Media queries
Media queries in version 1.x were far from perfect. Users had to follow a string-based template to make them work. In version 2.0, old media queries are deprecated and should be updated to the following syntax:
To learn more about mq
utility refer to this guide.