Delay to switch themes #212
-
Hello, how are you? I am using UnistylesRuntime to switch themes, but I noticed there is a small delay when I execute the setTheme function. I followed the documentation, but I couldn't identify if I am doing something wrong or if this delay is actually expected. I recorded a video that demonstrates the behavior. It doesn't appears, but I press to change theme when start to record.. So it take 5s to change theme. Thank you for your time and attention. Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-06-16.at.22.21.50.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It just one big re-render of your app. If eg. your root component has useStyles, entire app will re-render. Same goes if you have mounted FlatList with hundreds of components and each consist of next components with useStyles. This is how React works 🤷♂️ try to limit the number of mounted hooks while switching the themes, otherwise it will look like this. I was debugging such case on discord for someone and it appeared that this dev had mounted FlatList with ~80 components each with ~12 hooks, so app was re-rendering 1000 components while switching themes. That's only FlatList.. and what about headers, tab bars and other screens. |
Beta Was this translation helpful? Give feedback.
It just one big re-render of your app. If eg. your root component has useStyles, entire app will re-render. Same goes if you have mounted FlatList with hundreds of components and each consist of next components with useStyles.
This is how React works 🤷♂️ try to limit the number of mounted hooks while switching the themes, otherwise it will look like this.
I was debugging such case on discord for someone and it appeared that this dev had mounted FlatList with ~80 components each with ~12 hooks, so app was re-rendering 1000 components while switching themes. That's only FlatList.. and what about headers, tab bars and other screens.