diff --git a/docs/.astro/settings.json b/docs/.astro/settings.json index 89040243..541a66e5 100644 --- a/docs/.astro/settings.json +++ b/docs/.astro/settings.json @@ -1,5 +1,5 @@ { "_variables": { - "lastUpdateCheck": 1725018017706 + "lastUpdateCheck": 1727846556761 } } \ No newline at end of file diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 3ed2ecc5..fd81b4cd 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -101,12 +101,12 @@ export default defineConfig({ }, { label: 'Unistyles Registry', - link: '/reference/unistyles-registry/', - badge: 'Updated' + link: '/reference/unistyles-registry/' }, { label: 'Unistyles Runtime', - link: '/reference/unistyles-runtime/' + link: '/reference/unistyles-runtime/', + badge: 'Updated' }, { label: 'Content size category', diff --git a/docs/src/content/docs/reference/unistyles-runtime.mdx b/docs/src/content/docs/reference/unistyles-runtime.mdx index 67bde30a..21e8b25d 100644 --- a/docs/src/content/docs/reference/unistyles-runtime.mdx +++ b/docs/src/content/docs/reference/unistyles-runtime.mdx @@ -54,6 +54,7 @@ and use it anywhere in your code, even outside a component. | | fontScale | number | Font scale of the device | | | hairlineWidth | number | The thinnest width of the platform | | | rtl | boolean | Indicates if the device is in RTL mode | +| | getTheme | (themeName?: string) => Theme | Get theme by name or current theme if not specified | ## Setters diff --git a/src/core/UnistylesRuntime.ts b/src/core/UnistylesRuntime.ts index 25ff17d0..f6578a97 100644 --- a/src/core/UnistylesRuntime.ts +++ b/src/core/UnistylesRuntime.ts @@ -195,6 +195,19 @@ export class UnistylesRuntime { return nearestPixel / pixelRatio } + /** + * Get theme by name + * @param themeName - The name of the theme to get or current theme if not specified + * @returns - The theme + */ + public getTheme(themeName?: keyof UnistylesThemes) { + if (!themeName) { + return this.unistylesRegistry.getTheme(this.themeName) + } + + return this.unistylesRegistry.getTheme(themeName) + } + /** * Get the immersive mode (both status bar and navigation bar hidden (Android)) * @param isEnabled diff --git a/src/core/mocks/UnistylesMockedRuntime.ts b/src/core/mocks/UnistylesMockedRuntime.ts index 4e887085..8680e2ed 100644 --- a/src/core/mocks/UnistylesMockedRuntime.ts +++ b/src/core/mocks/UnistylesMockedRuntime.ts @@ -126,6 +126,14 @@ export class UnistylesMockedRuntime { return ScreenOrientation.Portrait } + public getTheme = (themeName?: keyof UnistylesThemes) => { + if (!themeName) { + return this.unistylesRegistry.getTheme(this.themeName) + } + + return this.unistylesRegistry.getTheme(themeName) + } + public setTheme = (name: keyof UnistylesThemes) => true public updateTheme = (name: keyof UnistylesThemes, theme: UnistylesThemes[keyof UnistylesThemes]) => {} public setAdaptiveThemes = (enabled: boolean) => {}