react-native-unistyles 3.5.1 → 3.5.3

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.
Files changed (143) hide show
  1. package/Unistyles.podspec +1 -0
  2. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +44 -7
  3. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +1 -1
  4. package/cxx/core/UnistylesRegistry.cpp +5 -5
  5. package/cxx/core/UnistylesRegistry.h +3 -3
  6. package/cxx/hybridObjects/HybridShadowRegistry.cpp +48 -14
  7. package/cxx/hybridObjects/HybridShadowRegistry.h +3 -2
  8. package/cxx/hybridObjects/HybridStyleSheet.cpp +3 -3
  9. package/cxx/parser/Parser.cpp +18 -2
  10. package/cxx/shadowTree/ShadowTreeManager.cpp +5 -5
  11. package/cxx/shadowTree/ShadowTreeManager.h +1 -1
  12. package/ios/NativePlatform+ios.swift +6 -4
  13. package/lib/commonjs/components/AdaptiveTheme.js +9 -1
  14. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -1
  15. package/lib/commonjs/components/NamedTheme.js +9 -1
  16. package/lib/commonjs/components/NamedTheme.js.map +1 -1
  17. package/lib/commonjs/components/ScopedThemeContext.js +9 -0
  18. package/lib/commonjs/components/ScopedThemeContext.js.map +1 -0
  19. package/lib/commonjs/components/native/Pressable.native.js +6 -5
  20. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  21. package/lib/commonjs/components/scopeChildren.js +29 -0
  22. package/lib/commonjs/components/scopeChildren.js.map +1 -0
  23. package/lib/commonjs/components/scopeChildren.native.js +9 -0
  24. package/lib/commonjs/components/scopeChildren.native.js.map +1 -0
  25. package/lib/commonjs/core/createUnistylesActivityIndicator.js +5 -3
  26. package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
  27. package/lib/commonjs/core/createUnistylesElement.native.js +3 -1
  28. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  29. package/lib/commonjs/core/createUnistylesImageBackground.js +7 -4
  30. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  31. package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -8
  32. package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
  33. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +20 -5
  34. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  35. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +28 -17
  36. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  37. package/lib/commonjs/reanimated/useAnimatedTheme.js +8 -5
  38. package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -1
  39. package/lib/commonjs/reanimated/useAnimatedTheme.native.js +8 -5
  40. package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -1
  41. package/lib/commonjs/specs/ShadowRegistry/index.js +76 -74
  42. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  43. package/lib/commonjs/web/css/core.js +30 -5
  44. package/lib/commonjs/web/css/core.js.map +1 -1
  45. package/lib/commonjs/web/css/state.js +9 -3
  46. package/lib/commonjs/web/css/state.js.map +1 -1
  47. package/lib/commonjs/web/registry.js +1 -1
  48. package/lib/commonjs/web/registry.js.map +1 -1
  49. package/lib/commonjs/web/shadowRegistry.js +3 -1
  50. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  51. package/lib/module/components/AdaptiveTheme.js +10 -2
  52. package/lib/module/components/AdaptiveTheme.js.map +1 -1
  53. package/lib/module/components/NamedTheme.js +10 -2
  54. package/lib/module/components/NamedTheme.js.map +1 -1
  55. package/lib/module/components/ScopedThemeContext.js +5 -0
  56. package/lib/module/components/ScopedThemeContext.js.map +1 -0
  57. package/lib/module/components/native/Pressable.native.js +7 -6
  58. package/lib/module/components/native/Pressable.native.js.map +1 -1
  59. package/lib/module/components/scopeChildren.js +23 -0
  60. package/lib/module/components/scopeChildren.js.map +1 -0
  61. package/lib/module/components/scopeChildren.native.js +4 -0
  62. package/lib/module/components/scopeChildren.native.js.map +1 -0
  63. package/lib/module/core/createUnistylesActivityIndicator.js +4 -2
  64. package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
  65. package/lib/module/core/createUnistylesElement.native.js +4 -2
  66. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  67. package/lib/module/core/createUnistylesImageBackground.js +6 -3
  68. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  69. package/lib/module/core/createUnistylesTouchableHighlight.js +7 -9
  70. package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
  71. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +22 -7
  72. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  73. package/lib/module/core/withUnistyles/withUnistyles.native.js +27 -17
  74. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  75. package/lib/module/reanimated/useAnimatedTheme.js +10 -7
  76. package/lib/module/reanimated/useAnimatedTheme.js.map +1 -1
  77. package/lib/module/reanimated/useAnimatedTheme.native.js +10 -7
  78. package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -1
  79. package/lib/module/specs/ShadowRegistry/index.js +76 -74
  80. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  81. package/lib/module/web/css/core.js +28 -4
  82. package/lib/module/web/css/core.js.map +1 -1
  83. package/lib/module/web/css/state.js +10 -4
  84. package/lib/module/web/css/state.js.map +1 -1
  85. package/lib/module/web/registry.js +1 -1
  86. package/lib/module/web/registry.js.map +1 -1
  87. package/lib/module/web/shadowRegistry.js +3 -1
  88. package/lib/module/web/shadowRegistry.js.map +1 -1
  89. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +2 -0
  90. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +1 -0
  91. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +2 -0
  92. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +1 -0
  93. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts +2 -0
  94. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts.map +1 -0
  95. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts +2 -0
  96. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts.map +1 -0
  97. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts +2 -0
  98. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts.map +1 -0
  99. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -1
  100. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -1
  101. package/lib/typescript/src/components/ScopedThemeContext.d.ts +6 -0
  102. package/lib/typescript/src/components/ScopedThemeContext.d.ts.map +1 -0
  103. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  104. package/lib/typescript/src/components/scopeChildren.d.ts +4 -0
  105. package/lib/typescript/src/components/scopeChildren.d.ts.map +1 -0
  106. package/lib/typescript/src/components/scopeChildren.native.d.ts +4 -0
  107. package/lib/typescript/src/components/scopeChildren.native.d.ts.map +1 -0
  108. package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
  109. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  110. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  111. package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
  112. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +1 -2
  113. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  114. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +6 -0
  115. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  116. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -1
  117. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -1
  118. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +4 -3
  119. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  120. package/lib/typescript/src/web/css/core.d.ts +1 -0
  121. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  122. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  123. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  124. package/package.json +1 -1
  125. package/src/components/AdaptiveTheme.tsx +8 -2
  126. package/src/components/NamedTheme.tsx +8 -2
  127. package/src/components/ScopedThemeContext.ts +9 -0
  128. package/src/components/native/Pressable.native.tsx +8 -7
  129. package/src/components/scopeChildren.native.ts +5 -0
  130. package/src/components/scopeChildren.tsx +19 -0
  131. package/src/core/createUnistylesActivityIndicator.tsx +5 -2
  132. package/src/core/createUnistylesElement.native.tsx +4 -2
  133. package/src/core/createUnistylesImageBackground.tsx +6 -3
  134. package/src/core/createUnistylesTouchableHighlight.tsx +7 -11
  135. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +22 -10
  136. package/src/core/withUnistyles/withUnistyles.native.tsx +46 -30
  137. package/src/reanimated/useAnimatedTheme.native.ts +9 -9
  138. package/src/reanimated/useAnimatedTheme.ts +9 -9
  139. package/src/specs/ShadowRegistry/index.ts +93 -91
  140. package/src/web/css/core.ts +29 -4
  141. package/src/web/css/state.ts +16 -4
  142. package/src/web/registry.ts +1 -1
  143. package/src/web/shadowRegistry.ts +3 -1
@@ -1,7 +1,6 @@
1
- import type { UnistylesTheme } from '../../types';
2
1
  import { type UnistylesMiniRuntime } from '../../specs';
3
2
  import { UnistyleDependency } from '../../specs/NativePlatform';
4
- export declare const useProxifiedUnistyles: (forcedTheme?: UnistylesTheme) => {
3
+ export declare const useProxifiedUnistyles: () => {
5
4
  proxifiedTheme: never;
6
5
  proxifiedRuntime: UnistylesMiniRuntime;
7
6
  addDependencies: (newDependencies: Array<UnistyleDependency>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useProxifiedUnistyles.d.ts","sourceRoot":"","sources":["../../../../../src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,KAAK,oBAAoB,EAA6C,MAAM,aAAa,CAAA;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAyB/D,eAAO,MAAM,qBAAqB,GAAI,cAAc,cAAc;;;uCAmGvB,KAAK,CAAC,kBAAkB,CAAC;CAgBnE,CAAA"}
1
+ {"version":3,"file":"useProxifiedUnistyles.d.ts","sourceRoot":"","sources":["../../../../../src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,oBAAoB,EAAoB,MAAM,aAAa,CAAA;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAyB/D,eAAO,MAAM,qBAAqB;;;uCA8GS,KAAK,CAAC,kBAAkB,CAAC;CAgBnE,CAAA"}
@@ -1,6 +1,12 @@
1
1
  import React, { type ComponentProps } from 'react';
2
2
  import type { Mappings } from './types';
3
+ import { type UnistyleDependency } from '../../specs';
3
4
  type GenericComponentProps<P> = ComponentProps<P>;
5
+ type MappedSecrets = {
6
+ styles: Record<string, any>;
7
+ dependencies: Array<UnistyleDependency>;
8
+ };
9
+ export declare const getSecrets: (styleProps?: Record<string, any>) => MappedSecrets;
4
10
  export declare const withUnistyles: <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Partial<React.ComponentProps<TComponent>> & {
5
11
  uniProps?: Mappings<React.ComponentProps<TComponent>>;
6
12
  }> & React.RefAttributes<React.ComponentRef<TComponent>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"withUnistyles.native.d.ts","sourceRoot":"","sources":["../../../../../src/core/withUnistyles/withUnistyles.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiC,KAAK,cAAc,EAAyC,MAAM,OAAO,CAAA;AAGxH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQvC,KAAK,qBAAqB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAA;AAcjD,eAAO,MAAM,aAAa,GAAI,UAAU,EAAE,SAAS,SAAS,qBAAqB,CAAC,UAAU,CAAC,EACzF,WAAW,UAAU,EACrB,WAAW,QAAQ,CAAC,SAAS,CAAC;eAIf,QAAQ,kCAAQ;yDAmFlC,CAAA"}
1
+ {"version":3,"file":"withUnistyles.native.d.ts","sourceRoot":"","sources":["../../../../../src/core/withUnistyles/withUnistyles.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAIV,KAAK,cAAc,EAGtB,MAAM,OAAO,CAAA;AAGd,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,OAAO,EAAE,KAAK,kBAAkB,EAA2B,MAAM,aAAa,CAAA;AAM9E,KAAK,qBAAqB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAA;AASjD,KAAK,aAAa,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,YAAY,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;CAC1C,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,aAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,KAAG,aAoBjE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,UAAU,EAAE,SAAS,SAAS,qBAAqB,CAAC,UAAU,CAAC,EACzF,WAAW,UAAU,EACrB,WAAW,QAAQ,CAAC,SAAS,CAAC;eAIf,QAAQ,kCAAQ;yDAqElC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAnimatedTheme.d.ts","sourceRoot":"","sources":["../../../../src/reanimated/useAnimatedTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,yBAAyB,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAK9C,eAAO,MAAM,gBAAgB,QA0BT,WAAW,CAAC,cAAc,CAC7C,CAAA"}
1
+ {"version":3,"file":"useAnimatedTheme.d.ts","sourceRoot":"","sources":["../../../../src/reanimated/useAnimatedTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,yBAAyB,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAM9C,eAAO,MAAM,gBAAgB,QAyBT,WAAW,CAAC,cAAc,CAC7C,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAnimatedTheme.native.d.ts","sourceRoot":"","sources":["../../../../src/reanimated/useAnimatedTheme.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,yBAAyB,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAI9C,eAAO,MAAM,gBAAgB,QA4BT,WAAW,CAAC,cAAc,CAC7C,CAAA"}
1
+ {"version":3,"file":"useAnimatedTheme.native.d.ts","sourceRoot":"","sources":["../../../../src/reanimated/useAnimatedTheme.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,yBAAyB,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAK9C,eAAO,MAAM,gBAAgB,QA2BT,WAAW,CAAC,cAAc,CAC7C,CAAA"}
@@ -1,8 +1,9 @@
1
+ import type { Scope } from '../../components/ScopedThemeContext';
1
2
  import type { VerifyReport } from '../../diagnostics/types';
2
3
  import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro';
3
4
  import type { ShadowNode, Unistyle, ViewHandle } from './types';
4
5
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
5
- add(handle?: ViewHandle, styles?: Array<Unistyle>): void;
6
+ add(handle?: ViewHandle, styles?: Array<Unistyle>, scope?: Scope | null): void;
6
7
  remove(handle?: ViewHandle): void;
7
8
  link(node: ShadowNode, styles?: Array<Unistyle>): void;
8
9
  unlink(node: ShadowNode): void;
@@ -11,10 +12,10 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
11
12
  setScopedTheme(themeName?: string): void;
12
13
  getScopedTheme(): string | undefined;
13
14
  verify(): VerifyReport;
14
- takeCommittedTags(): Array<number>;
15
+ takeCommittedInstanceHandles(): Array<any>;
15
16
  refreshReactNodes(nodes: Array<ShadowNode>): void;
16
17
  }
17
- type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink' | 'suspend' | 'takeCommittedTags' | 'refreshReactNodes';
18
+ type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink' | 'suspend' | 'takeCommittedInstanceHandles' | 'refreshReactNodes';
18
19
  export declare const UnistylesShadowRegistry: Omit<ShadowRegistry, PrivateMethods>;
19
20
  export {};
20
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;IACxD,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAEjC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IAC9B,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IAC/B,KAAK,IAAI,IAAI,CAAA;IACb,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxC,cAAc,IAAI,MAAM,GAAG,SAAS,CAAA;IACpC,MAAM,IAAI,YAAY,CAAA;IACtB,iBAAiB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAA;IAClC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;CACpD;AAyND,KAAK,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,mBAAmB,GAAG,mBAAmB,CAAA;AAElH,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAA;IAC9E,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAEjC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IAC9B,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IAC/B,KAAK,IAAI,IAAI,CAAA;IACb,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxC,cAAc,IAAI,MAAM,GAAG,SAAS,CAAA;IACpC,MAAM,IAAI,YAAY,CAAA;IACtB,4BAA4B,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1C,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;CACpD;AAmND,KAAK,cAAc,GACb,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,SAAS,GACT,8BAA8B,GAC9B,mBAAmB,CAAA;AAEzB,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
@@ -1,3 +1,4 @@
1
1
  import type { CSSState } from './state';
2
+ export declare const getChildrenClassName: (className: string) => string;
2
3
  export declare const convertToCSS: (hash: string, value: Record<string, any>, state: CSSState) => void;
3
4
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../src/web/css/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,QAAQ,SA+DrF,CAAA"}
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../src/web/css/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAavC,eAAO,MAAM,oBAAoB,GAAI,WAAW,MAAM,WAA8B,CAAA;AAiBpF,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,QAAQ,SA+DrF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../src/web/css/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAMjD,KAAK,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;AACzD,KAAK,QAAQ,GAAG;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;CACb,CAAA;AACD,KAAK,YAAY,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAgB1E,qBAAa,QAAQ;IAML,OAAO,CAAC,QAAQ;IAL5B,OAAO,EAAE,OAAO,CAAY;IAC5B,KAAK,EAAE,OAAO,CAAY;IAC1B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAA4B;gBAEzB,QAAQ,EAAE,iBAAiB;IAkB/C,GAAG,GAAI,qDAA0D,QAAQ,UAMxE;IAED,GAAG,GAAI,MAAM,MAAM,EAAE,QAAQ,eAAe,UAG3C;IAED,QAAQ,aAIP;IAED,QAAQ,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,UAsBrD;IAED,MAAM,GAAI,MAAM,MAAM,UAQrB;IAED,SAAS,eAsCR;IAED,QAAQ;;;;MAsBP;IAED,OAAO,GAAI,wBAAwB,UAAU,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,UAmBlE;IAED,KAAK,aAGJ;CACJ"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../src/web/css/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAMjD,KAAK,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;AACzD,KAAK,QAAQ,GAAG;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;CACb,CAAA;AACD,KAAK,YAAY,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAgB1E,qBAAa,QAAQ;IAML,OAAO,CAAC,QAAQ;IAL5B,OAAO,EAAE,OAAO,CAAY;IAC5B,KAAK,EAAE,OAAO,CAAY;IAC1B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAA4B;gBAEzB,QAAQ,EAAE,iBAAiB;IAkB/C,GAAG,GAAI,qDAA0D,QAAQ,UAMxE;IAED,GAAG,GAAI,MAAM,MAAM,EAAE,QAAQ,eAAe,UAG3C;IAED,QAAQ,aAIP;IAED,QAAQ,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,UA8BrD;IAED,MAAM,GAAI,MAAM,MAAM,UAYrB;IAED,SAAS,eAsCR;IAED,QAAQ;;;;MAsBP;IAED,OAAO,GAAI,wBAAwB,UAAU,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,UAmBlE;IAED,KAAK,aAGJ;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"shadowRegistry.d.ts","sourceRoot":"","sources":["../../../../src/web/shadowRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOnE,qBAAa,uBAAuB;IAYpB,OAAO,CAAC,QAAQ;IAV5B,IAAI,SAA4B;IAChC,MAAM,SAAQ;IACd,MAAM,gBAAa;IACnB,QAAQ,eAAkC;IAC1C,OAAO,aAAW;IAGlB,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,UAAU,CAAkC;gBAEhC,QAAQ,EAAE,iBAAiB;IAE/C,GAAG,GAAI,KAAK,GAAG,EAAE,OAAO,MAAM,UAM7B;IAED,SAAS,GAAI,WAAW,KAAK,CAAC,eAAe,CAAC,EAAE,WAAW,OAAO;;;;MAsEjE;IAED,cAAc,GAAI,QAAQ,cAAc,UAEvC;IAED,cAAc,kBAAyB;IAEvC,MAAM,GAAI,KAAK,GAAG,EAAE,OAAO,MAAM,UAahC;IAED,KAAK,aAGJ;IAED,KAAK,aAAW;CACnB"}
1
+ {"version":3,"file":"shadowRegistry.d.ts","sourceRoot":"","sources":["../../../../src/web/shadowRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOnE,qBAAa,uBAAuB;IAYpB,OAAO,CAAC,QAAQ;IAV5B,IAAI,SAA4B;IAChC,MAAM,SAAQ;IACd,MAAM,gBAAa;IACnB,QAAQ,eAAkC;IAC1C,OAAO,aAAW;IAGlB,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,UAAU,CAAkC;gBAEhC,QAAQ,EAAE,iBAAiB;IAE/C,GAAG,GAAI,KAAK,GAAG,EAAE,OAAO,MAAM,UAM7B;IAED,SAAS,GAAI,WAAW,KAAK,CAAC,eAAe,CAAC,EAAE,WAAW,OAAO;;;;MAsEjE;IAED,cAAc,GAAI,QAAQ,cAAc,UAIvC;IAED,cAAc,kBAAyB;IAEvC,MAAM,GAAI,KAAK,GAAG,EAAE,OAAO,MAAM,UAahC;IAED,KAAK,aAGJ;IAED,KAAK,aAAW;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin ./src/__tests__",
@@ -1,12 +1,14 @@
1
1
  import type { PropsWithChildren } from 'react'
2
2
 
3
- import React, { useLayoutEffect } from 'react'
3
+ import React, { useLayoutEffect, useMemo } from 'react'
4
4
 
5
5
  import type { UnistylesThemes } from '../global'
6
6
 
7
7
  import { useUnistyles } from '../core'
8
8
  import { UnistylesShadowRegistry } from '../specs'
9
9
  import { ApplyScopedTheme } from './ApplyScopedTheme'
10
+ import { scopeChildren } from './scopeChildren'
11
+ import { ScopedThemeContext } from './ScopedThemeContext'
10
12
 
11
13
  interface AdaptiveThemeProps extends PropsWithChildren {
12
14
  previousScopedTheme?: string
@@ -15,9 +17,13 @@ interface AdaptiveThemeProps extends PropsWithChildren {
15
17
  export const AdaptiveTheme: React.FunctionComponent<AdaptiveThemeProps> = ({ children, previousScopedTheme }) => {
16
18
  const { rt } = useUnistyles()
17
19
  const name = (rt.colorScheme === 'dark' ? 'light' : 'dark') as keyof UnistylesThemes
20
+ const scope = useMemo(() => ({ name }), [name])
21
+
18
22
  const mappedChildren = [
19
23
  <ApplyScopedTheme key={name} name={name} />,
20
- children,
24
+ <ScopedThemeContext.Provider key="scope" value={scope}>
25
+ {scopeChildren(name, children)}
26
+ </ScopedThemeContext.Provider>,
21
27
  <ApplyScopedTheme key="dispose" name={previousScopedTheme as keyof UnistylesThemes | undefined} />,
22
28
  ]
23
29
 
@@ -1,11 +1,13 @@
1
1
  import type { PropsWithChildren } from 'react'
2
2
 
3
- import React, { useLayoutEffect } from 'react'
3
+ import React, { useLayoutEffect, useMemo } from 'react'
4
4
 
5
5
  import type { UnistylesThemes } from '../global'
6
6
 
7
7
  import { UnistylesShadowRegistry } from '../specs'
8
8
  import { ApplyScopedTheme } from './ApplyScopedTheme'
9
+ import { scopeChildren } from './scopeChildren'
10
+ import { ScopedThemeContext } from './ScopedThemeContext'
9
11
 
10
12
  interface NamedThemeProps extends PropsWithChildren {
11
13
  name: keyof UnistylesThemes | undefined
@@ -13,9 +15,13 @@ interface NamedThemeProps extends PropsWithChildren {
13
15
  }
14
16
 
15
17
  export const NamedTheme: React.FunctionComponent<NamedThemeProps> = ({ name, children, previousScopedTheme }) => {
18
+ const scope = useMemo(() => ({ name }), [name])
19
+
16
20
  const mappedChildren = [
17
21
  <ApplyScopedTheme key="apply" name={name} />,
18
- children,
22
+ <ScopedThemeContext.Provider key="scope" value={scope}>
23
+ {scopeChildren(name, children)}
24
+ </ScopedThemeContext.Provider>,
19
25
  <ApplyScopedTheme key="dispose" name={previousScopedTheme as keyof UnistylesThemes | undefined} />,
20
26
  ]
21
27
 
@@ -0,0 +1,9 @@
1
+ import { createContext } from 'react'
2
+
3
+ import type { UnistylesThemes } from '../global'
4
+
5
+ export type Scope = {
6
+ name: keyof UnistylesThemes | undefined
7
+ }
8
+
9
+ export const ScopedThemeContext = createContext<Scope | null>(null)
@@ -1,12 +1,13 @@
1
1
  import type { PressableProps as Props, View } from 'react-native'
2
2
 
3
- import React, { forwardRef, useLayoutEffect, useRef } from 'react'
3
+ import React, { forwardRef, useContext, useLayoutEffect, useRef } from 'react'
4
4
  import { Pressable as NativePressableReactNative } from 'react-native'
5
5
 
6
6
  import type { Nullable } from '../../types'
7
7
 
8
8
  import { passForwardedRef } from '../../core'
9
9
  import { UnistylesShadowRegistry } from '../../specs'
10
+ import { ScopedThemeContext } from '../ScopedThemeContext'
10
11
 
11
12
  // instance type of View for both legacy and Strict TypeScript API (RN 0.87+)
12
13
  type ViewRef = React.ComponentRef<typeof View>
@@ -34,7 +35,7 @@ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.R
34
35
  PressableProps
35
36
  >(({ variants, style, ...props }, forwardedRef) => {
36
37
  const storedRef = useRef<Nullable<ViewRef>>(null)
37
- const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
38
+ const scope = useContext(ScopedThemeContext)
38
39
 
39
40
  useLayoutEffect(() => {
40
41
  return () => {
@@ -63,7 +64,7 @@ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.R
63
64
  forwardedRef,
64
65
  () => {
65
66
  // @ts-expect-error - this is hidden from TS
66
- UnistylesShadowRegistry.add(ref, unistyles)
67
+ UnistylesShadowRegistry.add(ref, unistyles, scope)
67
68
  },
68
69
  () => {
69
70
  // @ts-expect-error - this is hidden from TS
@@ -75,12 +76,14 @@ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.R
75
76
  const isPropStyleAFunction = typeof style === 'function'
76
77
  const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
77
78
 
78
- UnistylesShadowRegistry.setScopedTheme(scopedTheme)
79
+ UnistylesShadowRegistry.setScopedTheme(scope?.name)
79
80
 
80
81
  const unistyles = isPropStyleAFunction
81
82
  ? style.call(style, state)
82
83
  : getStyles(style as unknown as Record<string, any>)
83
84
 
85
+ UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
86
+
84
87
  if (!storedRef.current) {
85
88
  return unistyles
86
89
  }
@@ -89,9 +92,7 @@ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.R
89
92
  UnistylesShadowRegistry.remove(storedRef.current)
90
93
 
91
94
  // @ts-expect-error - this is hidden from TS
92
- UnistylesShadowRegistry.add(storedRef.current, unistyles)
93
-
94
- UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
95
+ UnistylesShadowRegistry.add(storedRef.current, unistyles, scope)
95
96
 
96
97
  return unistyles
97
98
  }}
@@ -0,0 +1,5 @@
1
+ import type React from 'react'
2
+
3
+ import type { UnistylesThemes } from '../global'
4
+
5
+ export const scopeChildren = (_name: keyof UnistylesThemes | undefined, children: React.ReactNode) => children
@@ -0,0 +1,19 @@
1
+ import React from 'react'
2
+
3
+ import type { UnistylesThemes } from '../global'
4
+
5
+ import { services } from '../web/services'
6
+
7
+ export const scopeChildren = (name: keyof UnistylesThemes | undefined, children: React.ReactNode) => {
8
+ if (!services.state.CSSVars) {
9
+ return children
10
+ }
11
+
12
+ const scopeProps = name ? { 'data-unistyles-theme': name } : { 'data-unistyles-reset': '' }
13
+
14
+ return (
15
+ <div style={{ display: 'contents' }} {...scopeProps}>
16
+ {children}
17
+ </div>
18
+ )
19
+ }
@@ -1,8 +1,9 @@
1
1
  import type { ActivityIndicator } from 'react-native'
2
2
 
3
- import React from 'react'
3
+ import React, { useContext } from 'react'
4
4
 
5
5
  import { isAndroid } from '../common'
6
+ import { ScopedThemeContext } from '../components/ScopedThemeContext'
6
7
  import { UnistylesShadowRegistry } from '../specs'
7
8
  import { copyComponentProperties } from '../utils'
8
9
  import { passForwardedRef } from './passForwardRef'
@@ -18,6 +19,8 @@ const getWrapperHandle = (ref: any) => {
18
19
 
19
20
  export const createUnistylesActivityIndicator = (Component: typeof ActivityIndicator) => {
20
21
  const UnistylesActivityIndicator = (props: any) => {
22
+ const scope = useContext(ScopedThemeContext)
23
+
21
24
  return (
22
25
  <Component
23
26
  {...props}
@@ -31,7 +34,7 @@ export const createUnistylesActivityIndicator = (Component: typeof ActivityIndic
31
34
  props.ref,
32
35
  () => {
33
36
  // @ts-ignore this is hidden from TS
34
- UnistylesShadowRegistry.add(wrapperHandle, props.style)
37
+ UnistylesShadowRegistry.add(wrapperHandle, props.style, scope)
35
38
  },
36
39
  () => {
37
40
  // @ts-ignore this is hidden from TS
@@ -1,7 +1,8 @@
1
1
  import type { ScrollView } from 'react-native'
2
2
 
3
- import React, { useRef } from 'react'
3
+ import React, { useContext, useRef } from 'react'
4
4
 
5
+ import { ScopedThemeContext } from '../components/ScopedThemeContext'
5
6
  import { UnistylesShadowRegistry } from '../specs'
6
7
  import { copyComponentProperties } from '../utils'
7
8
  import { passForwardedRef } from './passForwardRef'
@@ -10,6 +11,7 @@ import { maybeWarnAboutMultipleUnistyles } from './warn'
10
11
  export const createUnistylesElement = (Component: any) => {
11
12
  const UnistylesComponent = (props: any) => {
12
13
  const scrollViewRef = useRef<ScrollView>(null)
14
+ const scope = useContext(ScopedThemeContext)
13
15
 
14
16
  return (
15
17
  <Component
@@ -38,7 +40,7 @@ export const createUnistylesElement = (Component: any) => {
38
40
  props.ref,
39
41
  () => {
40
42
  // @ts-ignore this is hidden from TS
41
- UnistylesShadowRegistry.add(ref, props.style)
43
+ UnistylesShadowRegistry.add(ref, props.style, scope)
42
44
  },
43
45
  () => {
44
46
  // @ts-ignore this is hidden from TS
@@ -1,7 +1,8 @@
1
1
  import type { ImageBackground, ImageBackgroundProps } from 'react-native'
2
2
 
3
- import React from 'react'
3
+ import React, { useContext } from 'react'
4
4
 
5
+ import { ScopedThemeContext } from '../components/ScopedThemeContext'
5
6
  import { UnistylesShadowRegistry } from '../specs'
6
7
  import { copyComponentProperties } from '../utils'
7
8
  import { passForwardedRef } from './passForwardRef'
@@ -9,6 +10,8 @@ import { maybeWarnAboutMultipleUnistyles } from './warn'
9
10
 
10
11
  export const createUnistylesImageBackground = (Component: typeof ImageBackground) => {
11
12
  const UnistylesImageBackground = React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
13
+ const scope = useContext(ScopedThemeContext)
14
+
12
15
  // @ts-expect-error we don't know the type of the component
13
16
  maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
14
17
  // @ts-ignore we don't know the type of the component
@@ -23,7 +26,7 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
23
26
  forwardedRef,
24
27
  () => {
25
28
  // @ts-expect-error - this is hidden from TS
26
- UnistylesShadowRegistry.add(ref, props.style)
29
+ UnistylesShadowRegistry.add(ref, props.style, scope)
27
30
  },
28
31
  () => {
29
32
  // @ts-expect-error - this is hidden from TS
@@ -33,7 +36,7 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
33
36
  }}
34
37
  imageRef={(ref) => {
35
38
  // @ts-expect-error web types are not compatible with RN styles
36
- UnistylesShadowRegistry.add(ref, props.imageStyle)
39
+ UnistylesShadowRegistry.add(ref, props.imageStyle, scope)
37
40
 
38
41
  return () => {
39
42
  // @ts-ignore this is hidden from TS
@@ -1,7 +1,8 @@
1
1
  import type { TouchableHighlight } from 'react-native'
2
2
 
3
- import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'
3
+ import React, { useCallback, useContext, useLayoutEffect, useRef, useState } from 'react'
4
4
 
5
+ import { ScopedThemeContext } from '../components/ScopedThemeContext'
5
6
  import { UnistylesShadowRegistry } from '../specs'
6
7
  import { copyComponentProperties } from '../utils'
7
8
  import { passForwardedRef } from './passForwardRef'
@@ -9,6 +10,7 @@ import { maybeWarnAboutMultipleUnistyles } from './warn'
9
10
 
10
11
  export const createUnistylesTouchableHighlight = (Component: typeof TouchableHighlight) => {
11
12
  const UnistylesTouchableHighlight = (props: any) => {
13
+ const scope = useContext(ScopedThemeContext)
12
14
  const relinkRef = useRef<() => void>(undefined)
13
15
  const [hiddenUnderlays, setHiddenUnderlays] = useState(0)
14
16
 
@@ -18,22 +20,16 @@ export const createUnistylesTouchableHighlight = (Component: typeof TouchableHig
18
20
  }
19
21
  }, [hiddenUnderlays])
20
22
 
21
- // new props come with a parent render, re-renders for the underlay keep the ref and the scoped theme it captured
23
+ // new props come with a parent render, re-renders for the underlay keep the ref
22
24
  const ref = useCallback(
23
25
  (ref: unknown) => {
24
26
  maybeWarnAboutMultipleUnistyles(props.style, 'TouchableHighlight')
25
27
 
26
- const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
27
-
28
28
  relinkRef.current = () => {
29
- const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
30
-
31
- UnistylesShadowRegistry.setScopedTheme(scopedTheme)
32
29
  // @ts-ignore this is hidden from TS
33
30
  UnistylesShadowRegistry.remove(ref)
34
31
  // @ts-ignore this is hidden from TS
35
- UnistylesShadowRegistry.add(ref, props.style)
36
- UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
32
+ UnistylesShadowRegistry.add(ref, props.style, scope)
37
33
  }
38
34
 
39
35
  return passForwardedRef(
@@ -41,7 +37,7 @@ export const createUnistylesTouchableHighlight = (Component: typeof TouchableHig
41
37
  props.ref,
42
38
  () => {
43
39
  // @ts-ignore this is hidden from TS
44
- UnistylesShadowRegistry.add(ref, props.style)
40
+ UnistylesShadowRegistry.add(ref, props.style, scope)
45
41
  },
46
42
  () => {
47
43
  relinkRef.current = undefined
@@ -50,7 +46,7 @@ export const createUnistylesTouchableHighlight = (Component: typeof TouchableHig
50
46
  },
51
47
  )
52
48
  },
53
- [props],
49
+ [props, scope],
54
50
  )
55
51
 
56
52
  return (
@@ -1,8 +1,9 @@
1
- import { useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react'
1
+ import { useContext, useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react'
2
2
 
3
3
  import type { UnistylesTheme } from '../../types'
4
4
 
5
- import { type UnistylesMiniRuntime, UnistylesRuntime, UnistylesShadowRegistry } from '../../specs'
5
+ import { ScopedThemeContext } from '../../components/ScopedThemeContext'
6
+ import { type UnistylesMiniRuntime, UnistylesRuntime } from '../../specs'
6
7
  // It's imported that way because of circular dependency
7
8
  import { UnistyleDependency } from '../../specs/NativePlatform'
8
9
  import { listener } from './listener'
@@ -29,16 +30,16 @@ const RTDependencyMap = {
29
30
  rtl: UnistyleDependency.Rtl,
30
31
  } satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
31
32
 
32
- export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
33
- const [scopedTheme, setScopedTheme] = useState(
34
- forcedTheme ?? (UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme),
35
- )
33
+ export const useProxifiedUnistyles = () => {
34
+ const scope = useContext(ScopedThemeContext)
35
+ const [scopedTheme, setScopedTheme] = useState(scope?.name as UnistylesTheme)
36
36
  const [dependencies] = useState(() => new Set<number>())
37
37
  const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
38
38
  const [_, runtimeChanged] = useReducer(() => ({}), {})
39
39
  const disposeRef = useRef<VoidFunction>(undefined)
40
40
  const syncedDependenciesSizeRef = useRef(-1)
41
41
  const syncedScopedThemeRef = useRef<UnistylesTheme | undefined>(undefined)
42
+ const wasDisposedRef = useRef(false)
42
43
 
43
44
  const reinitListener = () => {
44
45
  disposeRef.current?.()
@@ -59,19 +60,30 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
59
60
  runtimeChanged()
60
61
  },
61
62
  })
63
+
64
+ // <Activity> cleans up effects, a theme change made while hidden was missed (#1297)
65
+ if (wasDisposedRef.current) {
66
+ wasDisposedRef.current = false
67
+
68
+ if (!scopedTheme) {
69
+ setTheme(UnistylesRuntime.getTheme())
70
+ }
71
+ }
62
72
  }
63
73
 
64
74
  useEffect(() => {
65
75
  return () => {
66
76
  disposeRef.current?.()
67
77
  syncedDependenciesSizeRef.current = -1
78
+ wasDisposedRef.current = true
68
79
  }
69
80
  }, [disposeRef])
70
81
 
71
- const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
72
-
73
- if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
74
- setScopedTheme(maybeNewScopedTheme)
82
+ // Follow the closest ScopedTheme, `reset` included. Every ScopedTheme provides the context, so the registry isn't read:
83
+ // a suspended ScopedTheme can leave its theme there
84
+ if (scope && scopedTheme !== scope.name) {
85
+ setScopedTheme(scope.name as UnistylesTheme)
86
+ setTheme(UnistylesRuntime.getTheme(scope.name as UnistylesTheme))
75
87
  }
76
88
 
77
89
  const proxifiedTheme = new Proxy(theme, {
@@ -1,8 +1,16 @@
1
- import React, { forwardRef, useEffect, useRef, type ComponentProps, type ComponentRef, type ComponentType } from 'react'
2
-
3
- import type { UnistylesTheme, UnistylesValues } from '../../types'
1
+ import React, {
2
+ forwardRef,
3
+ useContext,
4
+ useEffect,
5
+ type ComponentProps,
6
+ type ComponentRef,
7
+ type ComponentType,
8
+ } from 'react'
9
+
10
+ import type { UnistylesValues } from '../../types'
4
11
  import type { Mappings } from './types'
5
12
 
13
+ import { ScopedThemeContext } from '../../components/ScopedThemeContext'
6
14
  import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
7
15
  import { deepMergeObjects } from '../../utils'
8
16
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
@@ -23,6 +31,28 @@ type MappedSecrets = {
23
31
  dependencies: Array<UnistyleDependency>
24
32
  }
25
33
 
34
+ export const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
35
+ const styles = Array.isArray(styleProps) ? styleProps.flat(Infinity) : [styleProps]
36
+
37
+ const secrets: Array<UnistylesSecrets> = styles.filter(Boolean).reduce((acc, style) => {
38
+ const unistyleKey = Object.keys(style).find((key) => key.startsWith('unistyles_'))
39
+
40
+ return acc.concat([
41
+ unistyleKey
42
+ ? style[unistyleKey]
43
+ : {
44
+ uni__getStyles: () => style,
45
+ uni__dependencies: [],
46
+ },
47
+ ])
48
+ }, [])
49
+
50
+ return {
51
+ styles: secrets.reduce((acc, secret) => Object.assign(acc, secret.uni__getStyles()), {} as Record<string, any>),
52
+ dependencies: secrets.flatMap((secret) => secret.uni__dependencies),
53
+ }
54
+ }
55
+
26
56
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(
27
57
  Component: TComponent,
28
58
  mappings?: Mappings<TMappings>,
@@ -36,31 +66,6 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
36
66
  contentContainerStyle?: UnistylesValues
37
67
  }
38
68
 
39
- const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
40
- const styles = Array.isArray(styleProps) ? styleProps.flat() : [styleProps]
41
-
42
- const secrets: Array<UnistylesSecrets> = styles.filter(Boolean).reduce((acc, style) => {
43
- const unistyleKey = Object.keys(style).find((key) => key.startsWith('unistyles_'))
44
-
45
- return acc.concat([
46
- unistyleKey
47
- ? style[unistyleKey]
48
- : {
49
- uni__getStyles: () => style,
50
- uni__dependencies: [],
51
- },
52
- ])
53
- }, [])
54
-
55
- return {
56
- styles: secrets.reduce(
57
- (acc, secret) => Object.assign(acc, secret.uni__getStyles()),
58
- {} as Record<string, any>,
59
- ),
60
- dependencies: secrets.flatMap((secret) => secret.uni__dependencies),
61
- }
62
- }
63
-
64
69
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
65
70
  const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
66
71
  const NativeComponent = Component as ComponentType
@@ -72,8 +77,8 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
72
77
  // prettier-ignore
73
78
  maybeWarnAboutMultipleUnistyles(narrowedProps.contentContainerStyle, `withUnistyles(${Component.displayName ?? Component.name ?? 'Unknown'})`)
74
79
 
75
- const scopedTheme = useRef(UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme)
76
- const { proxifiedRuntime, proxifiedTheme, addDependencies } = useProxifiedUnistyles(scopedTheme.current)
80
+ const scope = useContext(ScopedThemeContext)
81
+ const { proxifiedRuntime, proxifiedTheme, addDependencies } = useProxifiedUnistyles()
77
82
 
78
83
  // Always track Theme dependency — accessing any property on proxifiedTheme
79
84
  // triggers the Proxy get trap which adds Theme to the dependency Set
@@ -93,9 +98,20 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
93
98
  ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime)
94
99
  : {}
95
100
 
101
+ // styles resolve in the registry's scoped theme, which is already restored when this re-renders or mounts later
102
+ const previousScopedTheme = scope ? UnistylesShadowRegistry.getScopedTheme() : undefined
103
+
104
+ if (scope) {
105
+ UnistylesShadowRegistry.setScopedTheme(scope.name)
106
+ }
107
+
96
108
  const styleSecrets = getSecrets(narrowedProps.style)
97
109
  const contentContainerStyleSecrets = getSecrets(narrowedProps.contentContainerStyle)
98
110
 
111
+ if (scope) {
112
+ UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
113
+ }
114
+
99
115
  const finalProps = {
100
116
  ...deepMergeObjects(mappingsProps, unistyleProps, props),
101
117
  ...(narrowedProps.style