jpudysz / react-native-unistyles

Level up your React Native StyleSheet
https://unistyl.es
MIT License
1.55k stars 42 forks source link

Request: Get updated theme by name from registry #298

Closed payellodevsupport closed 1 month ago

payellodevsupport commented 1 month ago

Description

Problem:

Currently, there's no public API to retrieve a theme by its name, making it difficult to use a specific theme for styles or to dynamically adjust UI elements based on the active theme.

Proposed Solution:

Implement a new method, UnistylesRuntime.getTheme(name), that returns the theme object associated with the given name. This would allow developers to:

Use Case:

Our application utilizes two main themes (light and dark) and allows for user customization for accessibility needs, such as setting font sizes and high contrasting colors. These customizations are done with updateTheme. We need to pass data from the modified theme to other components (such as when styling monaco code editor), which may require a specific theme to be picked. We're currently using the following workaround, which accesses a private registry variable:

(UnistylesRuntime as any).unistylesRegistry.getTheme(theme || this.currentTheme)

 

We discussed this briefly on Discord, but I'm happy to answer any questions if you need further information!

Steps to reproduce

Looking for something that exposes this: UnistylesRegistry.getTheme(themeName)

Snack or a link to a repository (optional)

No response

Unistyles version

2.9.2

React Native version

0.74.5

Platforms

Android, iOS, React Native Web, SSR

Engine

Hermes

Architecture

Paper (old)