-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
428 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,92 @@ | ||
--- | ||
title: Errors | ||
--- | ||
|
||
import Seo from '../../../components/Seo.astro' | ||
|
||
<Seo | ||
seo={{ | ||
title: 'Errors', | ||
description: 'Errors Unistyles will throw', | ||
}} | ||
> | ||
|
||
Unistyles will only throw errors when it is used incorrectly. | ||
|
||
### RuntimeUnavailable | ||
|
||
*"Unistyles runtime is not available. Make sure you followed the installation instructions"* | ||
|
||
This error will be thrown if you try to use Unistyles before it was initialized. | ||
Make sure you followed the installation [setup](/start/setup/). | ||
|
||
Still getting this error? Check [FAQ](/reference/faq/). | ||
|
||
### ThemeNotFound / ThemeNotRegistered | ||
|
||
*"You are trying to get a theme that is not registered with UnistylesRegistry"* | ||
|
||
and | ||
|
||
*"You are trying to set a theme that was not registered with UnistylesRegistry"* | ||
|
||
These errors occur when you call `UnistylesRuntime.setTheme` with a theme that has not been registered with `UnistylesRegistry`. | ||
This situation can arise if you don't use TypeScript. Confirm that all your themes are registered with `UnistylesRegistry.addThemes` before using them. | ||
|
||
### ThemeNotSelected | ||
|
||
*"Your themes are registered, but you didn't select the initial theme"* | ||
|
||
This error is thrown if you have registered multiple themes but failed to select an initial one. | ||
|
||
Follow theming [guide](/reference/theming/) to learn how to select the initial theme. | ||
|
||
### ThemesCannotBeEmpty | ||
|
||
*"You are trying to register empty themes object"* | ||
|
||
This error occurs if you attempt to register an empty themes object with `UnistylesRegistry.addThemes`. | ||
|
||
The `addThemes` method expects a key-value pair with at least one theme. | ||
|
||
Follow theming [guide](/reference/theming/) to learn how to register your themes. | ||
|
||
If you don't want to use themes, simply don't register them. | ||
|
||
### BreakpointsCannotBeEmpty | ||
|
||
*"You are trying to register empty breakpoints object"* | ||
|
||
This error will be thrown if you try to register empty breakpoints object with `UnistylesRegistry.addBreakpoints`. | ||
|
||
Breakpoints are optional, if you don't want to use them, simply don't register them. | ||
|
||
### BreakpointsMustStartFromZero | ||
|
||
*"You are trying to register breakpoints that don't start from 0"* | ||
|
||
This error occurs when you attempt to register breakpoints that do not start from 0. | ||
Begin your first breakpoint with a value of 0 to mimic CSS cascade. | ||
|
||
### InvalidPluginName | ||
|
||
*"Plugin name can't start from reserved prefix __unistyles"* | ||
|
||
This error is thrown if you attempt to register a plugin with a name that begins with the `__unistyles` prefix. | ||
This prefix is reserved for Unistyles' internal plugins. | ||
|
||
### DuplicatePluginName | ||
|
||
*"You are trying to register a plugin with a name that is already registered"* | ||
|
||
This error occurs when you attempt to register a plugin with a name that has already been registered. | ||
Review your list of plugins. Perhaps you included the same plugin twice? Or, maybe a plugin with the same name has already been created by someone from the community? | ||
|
||
### CantRemoveInternalPlugin | ||
|
||
*"You are trying to remove an internal unistyles plugin"* | ||
|
||
This error is thrown if you attempt to remove an internal Unistyles plugin. | ||
Currently, it's not possible to remove internal plugins as they are essential for Unistyles to function properly. | ||
|
||
</Seo> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,62 @@ | ||
--- | ||
title: FAQ | ||
--- | ||
|
||
import { Card, CardGrid } from '@astrojs/starlight/components' | ||
import Seo from '../../../components/Seo.astro' | ||
|
||
<Seo | ||
seo={{ | ||
title: 'FAQ', | ||
description: 'Frequently asked questions about the Unistyles' | ||
}} | ||
> | ||
|
||
Here, you can find answers to the most frequently asked questions about Unistyles. | ||
|
||
### Why Unistyles runtime is not available? | ||
|
||
This error occurs when you try to use a Unistyles feature without proper installation. | ||
|
||
Possible causes include: | ||
- Running the app in Expo Go, which is not supported. | ||
- Running your Expo project without rebuilding it using the `expo prebuild` command | ||
- Forgetting to execute `pod install` in your bare React Native project | ||
- Omitting the import of the file where you set up your UnistylesRegistry eg. in your `App.tsx` file | ||
|
||
### I'm trying to override library types, but I'm receiving error that react-native-unistyles is not found? | ||
|
||
To override types, you must import something from `react-native-unistyles`, such as `UnistylesRegistry`. | ||
|
||
### Adaptive mode doesn't work for me | ||
|
||
To enable adaptive mode, you need to register two themes named `light` and `dark` and set the `adaptiveThemes` flag to true within `UnistylesRegistry`. | ||
|
||
If your app still doesn't automatically switch themes, ensure that: | ||
- For Expo your `app.json` contains a `userInterfaceStyle` key with the value `automatic` | ||
- For bare React Native, your `Info.plist` does not have the `UIUserInterfaceStyle` key set to a hardcoded value | ||
- `Appearance` from `react-native` is set to `null` | ||
- You have phone with iOS 13+ or Android 10+ | ||
- Your device supports dark mode | ||
|
||
### I'm getting some TypeScript error for my stylesheet | ||
|
||
This should not occur, but if it does, please create a new issue in the GitHub repository. | ||
|
||
Unistyles is built with first-class support for TypeScript, inferring all the types for you. | ||
There should be no need for extra steps. Please include your stylesheet and the error you're encountering in the issue. | ||
|
||
### Does Unistyles support PlatformColor? | ||
|
||
Yes, it does! You can even use PlatformColor in your themes! | ||
|
||
### Are class components supported? | ||
|
||
No, the library only supports functional components. | ||
If you need support for class components, you would need to create a wrapper component. | ||
|
||
### How to use Unistyles with Expo? | ||
|
||
Unistyles supports Expo. However, it can't be used with Expo Go. | ||
|
||
</Seo> |
115 changes: 115 additions & 0 deletions
115
docs/src/content/docs/reference/for-library-authors.mdx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,118 @@ | ||
--- | ||
title: For library authors | ||
--- | ||
|
||
import Seo from '../../../components/Seo.astro' | ||
|
||
<Seo | ||
seo={{ | ||
title: 'For library authors', | ||
description: 'A guide for library authors on how to use Unistyles in their projects.' | ||
}} | ||
> | ||
|
||
Unistyles is highly extensible and can be utilized to build UI Kits and other kinds of projects. | ||
|
||
## Using Unistyles in your library | ||
|
||
`UnistylesRegistry` can be invoked lazily after resolving user-required configurations, such as themes and plugins. | ||
|
||
You can call `UnistylesRegistry` multiple times to override configurations. | ||
However, keep in mind that `UnistylesRegistry` makes a roundtrip to C++, which can add up to **1ms** of additional setup time for Unistyles. | ||
|
||
To manipulate your config without replacing it, you should use [UnistylesRuntime](/reference/unistyles-runtime/). | ||
|
||
## Timing | ||
|
||
Unistyles core does not have an asynchronous API. | ||
This means you can invoke `UnistylesRegistry` right before the first `useStyle` call: | ||
|
||
```tsx | ||
import { UnistylesRegistry, useInitialTheme, useStyles } from 'react-native-unistyles' | ||
|
||
export const App: React.FunctionComponent = () => { | ||
UnistylesRegistry | ||
.addConfig(...) | ||
.addBreakpoints(...) | ||
|
||
useInitialTheme('dark') | ||
|
||
const { styles } = useStyles(stylesheet) | ||
|
||
return ( | ||
// your app | ||
) | ||
} | ||
|
||
// stylesheet | ||
``` | ||
|
||
:::tip | ||
Registering themes at runtime is also possible, although it is not yet implemented in the core. | ||
If you need this feature, please open a discussion. | ||
::: | ||
|
||
## Plugins | ||
|
||
You can extend Unistyles with your plugins that may transform the output to the desired style. | ||
Currently, Unistyles supports one lifecycle hook: [onParsedStyle](/reference/plugins/). | ||
|
||
## When does Unistyles re-render? | ||
|
||
Unistyles only re-renders when it receives an event from C++. This means `useStyles` supports component memoization. | ||
|
||
You should expect re-renders only when: | ||
- The theme changes. | ||
- The device orientation changes. | ||
- The screen size changes (web only). | ||
- A plugin is registered or unregistered. | ||
|
||
:::tip | ||
Storing library config in `UnistylesRuntime` is also a possibility. | ||
If you need this feature, please open a discussion. | ||
::: | ||
|
||
## No React Context | ||
|
||
Unistyles does not use the React Context API. This means that users do not need to wrap their app with a `Provider`, | ||
reducing boilerplate and making your library more user-friendly. | ||
|
||
## New architecture ready | ||
|
||
Unistyles handles all native configurations and supports new architecture, | ||
ensuring you don't need to worry about Fabric or other low-level concepts. | ||
|
||
Your UI Kit can support all React Native apps out of the box. | ||
|
||
## Minimum requirements | ||
|
||
Unistyles is compatible with: | ||
- React Native version >=0.66 | ||
- TypeScript >4.0 | ||
- iOS 13+ | ||
- Android 5+ | ||
|
||
## CSS styles | ||
|
||
There is ongoing work on custom CSS compiler that could | ||
entirely replace the React Native Web StyleSheet API, | ||
offering better Developer Experience (DX) and more predictable re-renders, e.g. with media queries. | ||
|
||
Unistyles 2.0 was developed with this feature in mind. | ||
If you are interested, please open a discussion and share your use case. | ||
|
||
## Why choose Unistyles? | ||
|
||
Unistyles offers a unique architecture not available in any other library. Built on top of the React Native StyleSheet API, it is fully compatible with it. | ||
|
||
Without component abstraction, you have the freedom to build one. Unistyles supports various platforms and is easily extendable, particularly with plugins and variants. | ||
|
||
With its smart architecture, you can maintain the same rendering time as the [core](/start/benchmarks/). | ||
|
||
:::tip | ||
If you need any cool feature to support your UI Kit, please open a discussion. | ||
|
||
I'm happy to help you with your use case! | ||
::: | ||
|
||
</Seo> |
Oops, something went wrong.