@kbach/react-native 1.0.0-beta.25 → 1.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,19 +3,20 @@ import {
3
3
  getDynamicToken,
4
4
  getGlobalDarkMode,
5
5
  getGlobalThemeMode,
6
+ resyncDomWithActiveTheme,
6
7
  seedDefaultMode,
7
8
  setDynamicToken,
8
9
  setGlobalThemeMode,
9
10
  subscribeDynamicTokens,
10
11
  subscribeGlobalDarkMode,
11
12
  toggleGlobalDarkMode
12
- } from "./chunk-JENWPIJT.mjs";
13
+ } from "./chunk-MXIT3EDJ.mjs";
13
14
  import {
14
15
  defaultTheme,
15
16
  getTheme,
16
17
  resolveClassName,
17
18
  setTheme
18
- } from "./chunk-TBDAJIR3.mjs";
19
+ } from "./chunk-BEXNFWW6.mjs";
19
20
 
20
21
  // src/config.ts
21
22
  function parseHexRgb(hex) {
@@ -77,6 +78,7 @@ function resolveKbachConfig(config) {
77
78
  function applyKbachConfig(config) {
78
79
  const theme = resolveKbachConfig(config);
79
80
  setTheme(theme);
81
+ resyncDomWithActiveTheme();
80
82
  return theme;
81
83
  }
82
84
 
@@ -144,6 +146,7 @@ function ThemeProvider({ children, defaultMode = "system", persist = false }) {
144
146
  }
145
147
 
146
148
  // src/useColors.ts
149
+ import { useMemo as useMemo2 } from "react";
147
150
  function parseHexRgb2(hex) {
148
151
  const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
149
152
  if (!m) return null;
@@ -204,7 +207,8 @@ function makeColorsProxy(theme, isDark) {
204
207
  }
205
208
  function useColors() {
206
209
  const { isDark } = useTheme();
207
- return makeColorsProxy(getTheme(), isDark);
210
+ const theme = getTheme();
211
+ return useMemo2(() => makeColorsProxy(theme, isDark), [theme, isDark]);
208
212
  }
209
213
 
210
214
  // src/useDynamicToken.ts
@@ -1938,16 +1938,33 @@ function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, wi
1938
1938
  }
1939
1939
 
1940
1940
  // src/nativeBridge.ts
1941
+ var RESOLVE_STYLE_CACHE_MAX = 500;
1942
+ var resolveStyleCache = /* @__PURE__ */ new Map();
1943
+ var cachedForThemeJson = null;
1941
1944
  function resolveStyle(classString, pressed = false) {
1942
1945
  const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
1943
1946
  const width = import_react_native2.Dimensions.get("window").width;
1947
+ const themeJson = (0, import_theme.getThemeJson)();
1948
+ if (themeJson !== cachedForThemeJson) {
1949
+ resolveStyleCache.clear();
1950
+ cachedForThemeJson = themeJson;
1951
+ }
1952
+ const cacheKey = `${classString}\0${pressed}\0${colorScheme}\0${width}`;
1953
+ const cached = resolveStyleCache.get(cacheKey);
1954
+ if (cached !== void 0) return { ...cached };
1955
+ const style = resolveStyleUncached(classString, pressed, colorScheme, width, themeJson);
1956
+ if (resolveStyleCache.size >= RESOLVE_STYLE_CACHE_MAX) resolveStyleCache.clear();
1957
+ resolveStyleCache.set(cacheKey, style);
1958
+ return { ...style };
1959
+ }
1960
+ function resolveStyleUncached(classString, pressed, colorScheme, width, themeJson) {
1944
1961
  const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
1945
1962
  if (!KbachModule) {
1946
1963
  const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme.getTheme)(), colorScheme, pressed, width);
1947
1964
  warnIfDev(classString, warnings2);
1948
1965
  return style2;
1949
1966
  }
1950
- const json = KbachModule.resolveStyle(classString, (0, import_theme.getThemeJson)(), colorScheme, pressed, width);
1967
+ const json = KbachModule.resolveStyle(classString, themeJson, colorScheme, pressed, width);
1951
1968
  const style = JSON.parse(json);
1952
1969
  const warnings = style.__kbachWarnings;
1953
1970
  if (warnings !== void 0) {