FAQ
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 features 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 - If you don’t use breakpoints and themes, you still need to somehow initialize the Unistyles code. To do that, add an empty import from
react-native-unistyles
in yourApp.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 auserInterfaceStyle
key with the valueautomatic
- For bare React Native, your
Info.plist
does not have theUIUserInterfaceStyle
key set to a hardcoded value Appearance
fromreact-native
is set tonull
- 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.
Why does my app restart on theme change or font size change (Android)?
This behavior is default in Android. To prevent this, you need to add the following line to your AndroidManifest.xml
file:
Does Unistyles support JSC engine?
Unistyles supports the JSC engine, although it is not recommended.
If you encounter any issues with array.prototype.at
, please consider using a polyfill.
Does Unistyles support desktop platforms?
Yes, Unistyles supports both macOS with react-native-macos
and Windows with react-native-windows
packages.
My release app is crashing on startup (Android) with ProGuard enabled
It’s essential to keep the Unistyles code from being obfuscated. Unistyles is using JNI with reflection, and ProGuard can break it.
To fix this, add the following line to your proguard-rules.pro
file: