react-native-unistyles 2.4.0 → 2.4.1

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 (266) hide show
  1. package/README.md +72 -26
  2. package/android/CMakeLists.txt +18 -2
  3. package/android/build.gradle +5 -1
  4. package/android/src/main/cxx/cpp-adapter.cpp +16 -80
  5. package/android/src/main/cxx/helpers.cpp +61 -0
  6. package/android/src/main/cxx/helpers.h +7 -0
  7. package/android/src/main/cxx/platform.cpp +170 -0
  8. package/android/src/main/cxx/platform.h +20 -0
  9. package/android/src/main/java/com/unistyles/Models.kt +12 -70
  10. package/android/src/main/java/com/unistyles/Platform.kt +311 -10
  11. package/android/src/main/java/com/unistyles/UnistylesModule.kt +145 -153
  12. package/cxx/Macros.h +11 -0
  13. package/cxx/UnistylesImpl.cpp +310 -0
  14. package/cxx/UnistylesModel.cpp +234 -0
  15. package/cxx/UnistylesModel.h +141 -0
  16. package/cxx/UnistylesRuntime.cpp +17 -356
  17. package/cxx/UnistylesRuntime.h +71 -87
  18. package/ios/UnistylesModule.h +13 -0
  19. package/ios/UnistylesModule.mm +20 -90
  20. package/ios/platform/Platform_Shared.h +8 -0
  21. package/ios/platform/Platform_Shared.mm +160 -0
  22. package/ios/platform/Platform_iOS.h +6 -10
  23. package/ios/platform/Platform_iOS.mm +143 -93
  24. package/ios/platform/Platform_macOS.h +3 -7
  25. package/ios/platform/Platform_macOS.mm +52 -34
  26. package/ios/platform/Platform_tvOS.h +17 -0
  27. package/ios/platform/Platform_tvOS.mm +96 -0
  28. package/ios/platform/Platform_visionOS.h +20 -0
  29. package/ios/platform/Platform_visionOS.mm +120 -0
  30. package/lib/commonjs/UnistylesProvider.js +32 -0
  31. package/lib/commonjs/UnistylesProvider.js.map +1 -0
  32. package/lib/commonjs/common.js +3 -2
  33. package/lib/commonjs/common.js.map +1 -1
  34. package/lib/commonjs/core/UnistyleRegistry.js +14 -4
  35. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  36. package/lib/commonjs/core/Unistyles.js +7 -0
  37. package/lib/commonjs/core/Unistyles.js.map +1 -1
  38. package/lib/commonjs/core/UnistylesModule.js +52 -8
  39. package/lib/commonjs/core/UnistylesModule.js.map +1 -1
  40. package/lib/commonjs/core/UnistylesModule.native.js.map +1 -1
  41. package/lib/commonjs/core/UnistylesModule.windows.js.map +1 -1
  42. package/lib/commonjs/core/UnistylesRuntime.js +114 -4
  43. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  44. package/lib/commonjs/core/index.js.map +1 -1
  45. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +36 -0
  46. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -0
  47. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js +46 -0
  48. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  49. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +122 -0
  50. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  51. package/lib/commonjs/core/mocks/index.js +27 -0
  52. package/lib/commonjs/core/mocks/index.js.map +1 -0
  53. package/lib/commonjs/createStyleSheet.js.map +1 -1
  54. package/lib/commonjs/global.js.map +1 -1
  55. package/lib/commonjs/hooks/index.js.map +1 -1
  56. package/lib/commonjs/hooks/useCSS.js.map +1 -1
  57. package/lib/commonjs/hooks/useCSS.native.js.map +1 -1
  58. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -1
  59. package/lib/commonjs/hooks/useSharedContext.js +77 -0
  60. package/lib/commonjs/hooks/useSharedContext.js.map +1 -0
  61. package/lib/commonjs/hooks/useUnistyles.js +18 -65
  62. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  63. package/lib/commonjs/hooks/useVariants.js.map +1 -1
  64. package/lib/commonjs/index.js +7 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/normalizer/index.js.map +1 -1
  67. package/lib/commonjs/normalizer/module.d.js.map +1 -1
  68. package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -1
  69. package/lib/commonjs/normalizer/normalizer.js +1 -1
  70. package/lib/commonjs/normalizer/normalizer.js.map +1 -1
  71. package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -1
  72. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -1
  73. package/lib/commonjs/plugins/index.js.map +1 -1
  74. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -1
  75. package/lib/commonjs/types/breakpoints.js.map +1 -1
  76. package/lib/commonjs/types/color.js +2 -0
  77. package/lib/commonjs/types/color.js.map +1 -0
  78. package/lib/commonjs/types/common.js.map +1 -1
  79. package/lib/commonjs/types/core.js.map +1 -1
  80. package/lib/commonjs/types/index.js +11 -0
  81. package/lib/commonjs/types/index.js.map +1 -1
  82. package/lib/commonjs/types/normalizer.js.map +1 -1
  83. package/lib/commonjs/types/plugin.js.map +1 -1
  84. package/lib/commonjs/types/stylesheet.js.map +1 -1
  85. package/lib/commonjs/types/unistyles.js.map +1 -1
  86. package/lib/commonjs/types/variants.js.map +1 -1
  87. package/lib/commonjs/useStyles.js +1 -1
  88. package/lib/commonjs/useStyles.js.map +1 -1
  89. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  90. package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
  91. package/lib/commonjs/utils/generateId.js.map +1 -1
  92. package/lib/commonjs/utils/hash32.js.map +1 -1
  93. package/lib/commonjs/utils/index.js +7 -0
  94. package/lib/commonjs/utils/index.js.map +1 -1
  95. package/lib/commonjs/utils/mq.js.map +1 -1
  96. package/lib/commonjs/utils/mqParser.js.map +1 -1
  97. package/lib/commonjs/utils/parseColor.js +35 -0
  98. package/lib/commonjs/utils/parseColor.js.map +1 -0
  99. package/lib/commonjs/utils/styles.js +15 -1
  100. package/lib/commonjs/utils/styles.js.map +1 -1
  101. package/lib/commonjs/utils/withPlugins.js.map +1 -1
  102. package/lib/module/UnistylesProvider.js +24 -0
  103. package/lib/module/UnistylesProvider.js.map +1 -0
  104. package/lib/module/common.js +2 -1
  105. package/lib/module/common.js.map +1 -1
  106. package/lib/module/core/UnistyleRegistry.js +15 -5
  107. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  108. package/lib/module/core/Unistyles.js +8 -1
  109. package/lib/module/core/Unistyles.js.map +1 -1
  110. package/lib/module/core/UnistylesModule.js +52 -8
  111. package/lib/module/core/UnistylesModule.js.map +1 -1
  112. package/lib/module/core/UnistylesModule.native.js.map +1 -1
  113. package/lib/module/core/UnistylesModule.windows.js.map +1 -1
  114. package/lib/module/core/UnistylesRuntime.js +115 -4
  115. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  116. package/lib/module/core/index.js +2 -1
  117. package/lib/module/core/index.js.map +1 -1
  118. package/lib/module/core/mocks/UnistylesMockedBridge.js +29 -0
  119. package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -0
  120. package/lib/module/core/mocks/UnistylesMockedRegistry.js +39 -0
  121. package/lib/module/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  122. package/lib/module/core/mocks/UnistylesMockedRuntime.js +114 -0
  123. package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  124. package/lib/module/core/mocks/index.js +4 -0
  125. package/lib/module/core/mocks/index.js.map +1 -0
  126. package/lib/module/createStyleSheet.js.map +1 -1
  127. package/lib/module/global.js.map +1 -1
  128. package/lib/module/hooks/index.js.map +1 -1
  129. package/lib/module/hooks/useCSS.js.map +1 -1
  130. package/lib/module/hooks/useCSS.native.js.map +1 -1
  131. package/lib/module/hooks/useInitialTheme.js.map +1 -1
  132. package/lib/module/hooks/useSharedContext.js +70 -0
  133. package/lib/module/hooks/useSharedContext.js.map +1 -0
  134. package/lib/module/hooks/useUnistyles.js +19 -66
  135. package/lib/module/hooks/useUnistyles.js.map +1 -1
  136. package/lib/module/hooks/useVariants.js.map +1 -1
  137. package/lib/module/index.js +2 -2
  138. package/lib/module/index.js.map +1 -1
  139. package/lib/module/normalizer/index.js.map +1 -1
  140. package/lib/module/normalizer/module.d.js.map +1 -1
  141. package/lib/module/normalizer/normalizeStyle.js.map +1 -1
  142. package/lib/module/normalizer/normalizer.js.map +1 -1
  143. package/lib/module/normalizer/normalizer.macos.js.map +1 -1
  144. package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -1
  145. package/lib/module/plugins/index.js.map +1 -1
  146. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -1
  147. package/lib/module/types/breakpoints.js.map +1 -1
  148. package/lib/module/types/color.js +2 -0
  149. package/lib/module/types/color.js.map +1 -0
  150. package/lib/module/types/common.js.map +1 -1
  151. package/lib/module/types/core.js.map +1 -1
  152. package/lib/module/types/index.js +1 -0
  153. package/lib/module/types/index.js.map +1 -1
  154. package/lib/module/types/normalizer.js.map +1 -1
  155. package/lib/module/types/plugin.js.map +1 -1
  156. package/lib/module/types/stylesheet.js.map +1 -1
  157. package/lib/module/types/unistyles.js.map +1 -1
  158. package/lib/module/types/variants.js.map +1 -1
  159. package/lib/module/useStyles.js +1 -1
  160. package/lib/module/useStyles.js.map +1 -1
  161. package/lib/module/utils/breakpoints.js.map +1 -1
  162. package/lib/module/utils/cssMediaQuery.js.map +1 -1
  163. package/lib/module/utils/generateId.js.map +1 -1
  164. package/lib/module/utils/hash32.js.map +1 -1
  165. package/lib/module/utils/index.js +1 -0
  166. package/lib/module/utils/index.js.map +1 -1
  167. package/lib/module/utils/mq.js.map +1 -1
  168. package/lib/module/utils/mqParser.js.map +1 -1
  169. package/lib/module/utils/parseColor.js +28 -0
  170. package/lib/module/utils/parseColor.js.map +1 -0
  171. package/lib/module/utils/styles.js +15 -1
  172. package/lib/module/utils/styles.js.map +1 -1
  173. package/lib/module/utils/withPlugins.js.map +1 -1
  174. package/lib/typescript/src/UnistylesProvider.d.ts +20 -0
  175. package/lib/typescript/src/UnistylesProvider.d.ts.map +1 -0
  176. package/lib/typescript/src/common.d.ts +3 -2
  177. package/lib/typescript/src/common.d.ts.map +1 -1
  178. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  179. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -1
  180. package/lib/typescript/src/core/UnistylesModule.d.ts +1 -0
  181. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
  182. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -1
  183. package/lib/typescript/src/core/UnistylesModule.windows.d.ts.map +1 -1
  184. package/lib/typescript/src/core/UnistylesRuntime.d.ts +84 -8
  185. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
  186. package/lib/typescript/src/core/index.d.ts +3 -1
  187. package/lib/typescript/src/core/index.d.ts.map +1 -1
  188. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +28 -0
  189. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -0
  190. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts +21 -0
  191. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts.map +1 -0
  192. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +79 -0
  193. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -0
  194. package/lib/typescript/src/core/mocks/index.d.ts +4 -0
  195. package/lib/typescript/src/core/mocks/index.d.ts.map +1 -0
  196. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  197. package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
  198. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -1
  199. package/lib/typescript/src/hooks/useSharedContext.d.ts +33 -0
  200. package/lib/typescript/src/hooks/useSharedContext.d.ts.map +1 -0
  201. package/lib/typescript/src/hooks/useUnistyles.d.ts +4 -19
  202. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  203. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
  204. package/lib/typescript/src/index.d.ts +7 -15
  205. package/lib/typescript/src/index.d.ts.map +1 -1
  206. package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -1
  207. package/lib/typescript/src/types/breakpoints.d.ts +9 -8
  208. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  209. package/lib/typescript/src/types/color.d.ts +4 -0
  210. package/lib/typescript/src/types/color.d.ts.map +1 -0
  211. package/lib/typescript/src/types/core.d.ts +2 -2
  212. package/lib/typescript/src/types/core.d.ts.map +1 -1
  213. package/lib/typescript/src/types/index.d.ts +2 -1
  214. package/lib/typescript/src/types/index.d.ts.map +1 -1
  215. package/lib/typescript/src/types/normalizer.d.ts +1 -1
  216. package/lib/typescript/src/types/normalizer.d.ts.map +1 -1
  217. package/lib/typescript/src/types/stylesheet.d.ts +9 -6
  218. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  219. package/lib/typescript/src/types/unistyles.d.ts +20 -9
  220. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  221. package/lib/typescript/src/useStyles.d.ts +1 -1
  222. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  223. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  224. package/lib/typescript/src/utils/index.d.ts +1 -0
  225. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  226. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
  227. package/lib/typescript/src/utils/parseColor.d.ts +3 -0
  228. package/lib/typescript/src/utils/parseColor.d.ts.map +1 -0
  229. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  230. package/package.json +38 -25
  231. package/react-native-unistyles.podspec +4 -1
  232. package/src/UnistylesProvider.tsx +33 -0
  233. package/src/common.ts +3 -2
  234. package/src/core/UnistyleRegistry.ts +19 -5
  235. package/src/core/Unistyles.ts +10 -1
  236. package/src/core/UnistylesModule.ts +61 -14
  237. package/src/core/UnistylesRuntime.ts +120 -5
  238. package/src/core/index.ts +7 -1
  239. package/src/core/mocks/UnistylesMockedBridge.ts +30 -0
  240. package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
  241. package/src/core/mocks/UnistylesMockedRuntime.ts +144 -0
  242. package/src/core/mocks/index.ts +3 -0
  243. package/src/hooks/useSharedContext.ts +83 -0
  244. package/src/hooks/useUnistyles.ts +15 -71
  245. package/src/index.ts +10 -4
  246. package/src/types/breakpoints.ts +19 -9
  247. package/src/types/color.ts +26 -0
  248. package/src/types/core.ts +2 -2
  249. package/src/types/index.ts +5 -1
  250. package/src/types/normalizer.ts +1 -1
  251. package/src/types/stylesheet.ts +10 -7
  252. package/src/types/unistyles.ts +28 -12
  253. package/src/useStyles.ts +1 -1
  254. package/src/utils/index.ts +1 -0
  255. package/src/utils/parseColor.ts +33 -0
  256. package/src/utils/styles.ts +24 -1
  257. package/windows/ExperimentalFeatures.props +4 -4
  258. package/windows/NuGet.Config +0 -1
  259. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +42 -118
  260. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj +7 -2
  261. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj.filters +6 -1
  262. package/windows/ReactNativeUnistyles/packages.lock.json +31 -31
  263. package/android/src/main/java/com/unistyles/Config.kt +0 -116
  264. package/android/src/main/java/com/unistyles/Insets.kt +0 -138
  265. package/ios/UnistylesHelpers.h +0 -3
  266. package/ios/UnistylesHelpers.mm +0 -5
@@ -0,0 +1,33 @@
1
+ import type { Color } from '../types'
2
+ import { isIOS } from '../common'
3
+
4
+ const parseAlpha = (alpha: number) => {
5
+ if (alpha > 1 || alpha < 0) {
6
+ return 1
7
+ }
8
+
9
+ return alpha
10
+ }
11
+
12
+ export const parseColor = (color?: Color, alpha: number = 1): [string, number] => {
13
+ if (!color) {
14
+ return ['', 1]
15
+ }
16
+
17
+ // ignore alpha for 8 digit hex colors
18
+ if (color.startsWith('#') && color.length === 9) {
19
+ return [color, 1]
20
+ }
21
+
22
+ if (color.startsWith('#') && color.length === 7) {
23
+ return [color, parseAlpha(alpha)]
24
+ }
25
+
26
+ if (isIOS && color === 'transparent') {
27
+ return ['#000000', 0]
28
+ }
29
+
30
+ // todo remove this with Unistyles 3.0
31
+ // named colors
32
+ return [color, 1]
33
+ }
@@ -35,7 +35,30 @@ export const parseStyle = <T extends RNStyle>(
35
35
 
36
36
  // transforms
37
37
  if (key === 'transform' && Array.isArray(value)) {
38
- acc[key] = value.map(value => parseStyle(value, variant))
38
+ acc[key] = value
39
+ .map(value => parseStyle(value, variant))
40
+ .filter(value => {
41
+ // remove undefined values
42
+ if (typeof value === 'object') {
43
+ return Object.values(value).at(0) !== undefined
44
+ }
45
+
46
+ return true
47
+ })
48
+
49
+ return acc
50
+ }
51
+
52
+ if ((key === 'boxShadow' || key === 'filter') && Array.isArray(value)) {
53
+ acc[key] = value
54
+ .map(value => parseStyle(value, variant, false))
55
+ .filter(value => Object.keys(value).length === 1)
56
+
57
+ return acc
58
+ }
59
+
60
+ if (key === 'fontVariant' && Array.isArray(value)) {
61
+ acc[key] = value
39
62
 
40
63
  return acc
41
64
  }
@@ -2,10 +2,10 @@
2
2
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
 
4
4
  <!--
5
- Application projects contain a file with this name to specify some important settings
6
- that will apply globally for the app and *all* native modules the app consumes. These
7
- values are set by the app developer. However you can also set them here to test building
8
- the library solution without an app.
5
+ This file contains some important settings that will apply globally for
6
+ your app and *all* native modules your app consumes. These values were
7
+ set when you created the app project, and in some cases cannot be
8
+ simply changed here without recreating a new project.
9
9
  -->
10
10
 
11
11
  <PropertyGroup Label="Microsoft.ReactNative Experimental Features">
@@ -5,7 +5,6 @@
5
5
  </config>
6
6
  <packageSources>
7
7
  <clear />
8
- <add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
9
8
  <add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
10
9
  </packageSources>
11
10
  <disabledPackageSources>
@@ -8,21 +8,18 @@
8
8
  #include <winrt/Microsoft.ReactNative.h>
9
9
  #include <winrt/Windows.UI.Xaml.h>
10
10
  #include <winrt/Windows.UI.Core.h>
11
+ #include <winrt/Windows.Graphics.Display.h>
11
12
  #include <winrt/Windows.UI.ViewManagement.h>
12
13
  #include "UnistylesRuntime.h"
14
+ #include <TurboModuleProvider.h>
13
15
 
14
16
  using namespace winrt::Windows::UI::ViewManagement;
17
+ using namespace winrt::Windows::Graphics::Display;
15
18
  using namespace winrt::Microsoft::ReactNative;
16
19
  using namespace winrt::Windows::UI::Xaml;
17
20
  using namespace winrt::Windows::UI::Core;
18
21
  using namespace facebook;
19
22
 
20
- struct UIInitialInfo {
21
- Dimensions screen;
22
- std::string colorScheme;
23
- std::string contentSizeCategory;
24
- };
25
-
26
23
  namespace winrt::ReactNativeUnistyles
27
24
  {
28
25
 
@@ -30,157 +27,86 @@ REACT_MODULE(Unistyles, L"Unistyles")
30
27
  struct Unistyles {
31
28
 
32
29
  REACT_INIT(Initialize)
33
- void Initialize(ReactContext const &reactContext) noexcept {
30
+ void Initialize(ReactContext const& reactContext) noexcept {
34
31
  m_reactContext = reactContext;
35
32
 
36
33
  m_reactContext.UIDispatcher().Post([this]() mutable {
37
34
  this->windowSizeChange = Window::Current().CoreWindow().SizeChanged(TypedEventHandler<CoreWindow, WindowSizeChangedEventArgs>([=](CoreWindow const sender, WindowSizeChangedEventArgs const&) {
38
- auto bounds = Window::Current().Bounds();
39
-
40
35
  if (this->unistylesRuntime != nullptr) {
41
- Dimensions screenDimensions = Dimensions{(int)bounds.Width, (int)bounds.Height};
42
-
43
- ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(screenDimensions, this->getInsets(), this->getStatusBarDimensions(), this->getNavigationBarDimensions());
36
+ ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(getScreenDimensions(), std::nullopt, std::nullopt, std::nullopt);
44
37
  }
45
38
  }));
46
39
 
47
- UISettings settings;
48
-
49
- this->colorValuesChange = settings.ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&){
40
+ this->colorValuesChange = UISettings().ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&) {
50
41
  if (this->unistylesRuntime != nullptr) {
51
42
  ((UnistylesRuntime*)this->unistylesRuntime)->handleAppearanceChange(this->getColorScheme());
52
43
  }
53
44
  }));
54
45
  });
55
46
  }
56
-
47
+
57
48
  REACT_SYNC_METHOD(install)
58
- bool install() noexcept {
49
+ bool install() noexcept {
59
50
  if (m_reactContext == nullptr) {
60
51
  return false;
61
52
  }
62
53
 
63
54
  jsi::Runtime* jsiRuntime = TryGetOrCreateContextRuntime(m_reactContext);
64
-
55
+
65
56
  if (jsiRuntime == nullptr) {
66
57
  return false;
67
58
  }
68
59
 
69
60
  auto& runtime = *jsiRuntime;
61
+ auto callInvoker = MakeAbiCallInvoker(m_reactContext.Handle().JSDispatcher());
70
62
 
71
- registerUnistylesHostObject(runtime);
63
+ registerUnistylesHostObject(runtime, callInvoker);
72
64
 
73
65
  return true;
74
66
  }
75
67
 
76
- void registerUnistylesHostObject(jsi::Runtime& runtime) {
77
- std::promise<UIInitialInfo> uiInfoPromise;
78
- auto uiInfoFuture = uiInfoPromise.get_future();
79
-
80
- m_reactContext.UIDispatcher().Post([this, promise = std::move(uiInfoPromise)]() mutable {
81
- UIInitialInfo uiMetadata;
82
- auto bounds = Window::Current().Bounds();
68
+ void registerUnistylesHostObject(jsi::Runtime& runtime, std::shared_ptr<facebook::react::CallInvoker> callInvoker) {
69
+ auto unistylesRuntime = std::make_shared<UnistylesRuntime>(runtime, callInvoker);
83
70
 
84
- uiMetadata.screen = Dimensions{(int)bounds.Width, (int)bounds.Height};
85
- uiMetadata.colorScheme = this->getColorScheme();
86
- uiMetadata.contentSizeCategory = UnistylesUnspecifiedScheme;
87
-
88
- promise.set_value(std::move(uiMetadata));
89
- });
90
-
91
- UIInitialInfo uiInfo = uiInfoFuture.get();
71
+ this->unistylesRuntime = unistylesRuntime.get();
92
72
 
93
- auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
94
- uiInfo.screen,
95
- uiInfo.colorScheme,
96
- uiInfo.contentSizeCategory,
97
- this->getInsets(),
98
- this->getStatusBarDimensions(),
99
- this->getNavigationBarDimensions()
100
- );
73
+ makeShared((UnistylesRuntime*)unistylesRuntime.get());
101
74
 
102
- unistylesRuntime->onThemeChange([this](std::string theme) {
103
- winrt::hstring themeName = winrt::to_hstring(theme);
75
+ auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
104
76
 
105
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
106
- {"type", "theme"},
107
- {"payload", winrt::Microsoft::ReactNative::JSValueObject{{"themeName", winrt::to_string(themeName)}}}
108
- };
77
+ runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
78
+ }
109
79
 
110
- this->OnThemeChange(payload);
80
+ void makeShared(UnistylesRuntime* unistylesRuntime) {
81
+ unistylesRuntime->setScreenDimensionsCallback([this]() {
82
+ return getScreenDimensions();
111
83
  });
112
84
 
113
- unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation, Dimensions& screen, Dimensions& statusBar, Insets& insets, Dimensions& navigationBar) {
114
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
115
- {"type", "layout"},
116
- {"payload", winrt::Microsoft::ReactNative::JSValueObject{
117
- {"breakpoint", breakpoint},
118
- {"orientation", orientation},
119
- {"screen", winrt::Microsoft::ReactNative::JSValueObject{
120
- {"width", screen.width},
121
- {"height", screen.height}
122
- }},
123
- {"statusBar", winrt::Microsoft::ReactNative::JSValueObject{
124
- {"width", statusBar.width},
125
- {"height", statusBar.height}
126
- }},
127
- {"navigationBar", winrt::Microsoft::ReactNative::JSValueObject{
128
- {"width", navigationBar.width},
129
- {"height", navigationBar.height}
130
- }},
131
- {"insets", winrt::Microsoft::ReactNative::JSValueObject{
132
- {"top", insets.top},
133
- {"bottom", insets.bottom},
134
- {"left", insets.left},
135
- {"right", insets.right}
136
- }},
137
- }}
138
- };
139
-
140
- this->OnLayoutChange(payload);
85
+ unistylesRuntime->setColorSchemeCallback([this]() {
86
+ return getColorScheme();
141
87
  });
142
88
 
143
- unistylesRuntime.get()->onPluginChange([this]() {
144
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
145
- {"type", "plugin"}
146
- };
89
+ m_reactContext.UIDispatcher().Post([this, unistylesRuntime]() {
90
+ auto screen = getScreenDimensions();
147
91
 
148
- this->OnPluginChange(payload);
92
+ unistylesRuntime->screen = Dimensions({ screen.width, screen.height });
93
+ unistylesRuntime->pixelRatio = screen.pixelRatio;
94
+ unistylesRuntime->fontScale = screen.fontScale;
95
+ unistylesRuntime->colorScheme = getColorScheme();
149
96
  });
150
-
151
- unistylesRuntime.get()->onContentSizeCategoryChange([this](std::string contentSizeCategory) {
152
- // not available on windows
153
- });
154
-
155
- this->unistylesRuntime = unistylesRuntime.get();
156
-
157
- auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
158
-
159
- runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
160
97
  }
161
98
 
162
- REACT_EVENT(OnThemeChange, L"__unistylesOnChange")
163
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnThemeChange;
164
-
165
- REACT_EVENT(OnLayoutChange, L"__unistylesOnChange")
166
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnLayoutChange;
167
-
168
- REACT_EVENT(OnPluginChange, L"__unistylesOnChange")
169
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnPluginChange;
170
-
171
99
  ~Unistyles() {
172
100
  if (this->unistylesRuntime != nullptr) {
173
101
  this->unistylesRuntime = nullptr;
174
102
  }
175
103
 
176
104
  if (this->windowSizeChange) {
177
- Window::Current().CoreWindow().SizeChanged(this->windowSizeChange);
105
+ this->windowSizeChange = { NULL };
178
106
  }
179
107
 
180
108
  if (this->colorValuesChange) {
181
- UISettings settings;
182
-
183
- settings.ColorValuesChanged(this->colorValuesChange);
109
+ this->colorValuesChange = { NULL };
184
110
  }
185
111
  }
186
112
 
@@ -191,16 +117,17 @@ struct Unistyles {
191
117
  winrt::event_token colorValuesChange{ NULL };
192
118
 
193
119
  std::string getColorScheme() {
194
- auto uiSettings = UISettings();
195
- auto background = uiSettings.GetColorValue(UIColorType::Background);
120
+ UISettings uiSettings;
121
+
122
+ auto backgroundColor = uiSettings.GetColorValue(UIColorType::Background);
196
123
 
197
- bool isDark = background == winrt::Windows::UI::Colors::Black();
124
+ bool isDark = backgroundColor == Colors::Black();
198
125
 
199
126
  if (isDark) {
200
127
  return UnistylesDarkScheme;
201
128
  }
202
129
 
203
- bool isLight = background == winrt::Windows::UI::Colors::White();
130
+ bool isLight = backgroundColor == Colors::White();
204
131
 
205
132
  if (isLight) {
206
133
  return UnistylesLightScheme;
@@ -209,16 +136,13 @@ struct Unistyles {
209
136
  return UnistylesUnspecifiedScheme;
210
137
  }
211
138
 
212
- Insets getInsets() {
213
- return Insets{ 0, 0, 0, 0 };
214
- }
215
-
216
- Dimensions getStatusBarDimensions() {
217
- return {0, 0};
218
- }
139
+ Screen getScreenDimensions() {
140
+ auto bounds = Window::Current().Bounds();
141
+ auto displayInfo = DisplayInformation::GetForCurrentView();
142
+ auto pixelRatio = displayInfo.LogicalDpi() / 96.0f;
143
+ float fontScale = UISettings().TextScaleFactor();
219
144
 
220
- Dimensions getNavigationBarDimensions() {
221
- return { 0, 0 };
145
+ return Screen({ (int)bounds.Width, (int)bounds.Height, pixelRatio, fontScale });
222
146
  }
223
147
  };
224
148
 
@@ -79,7 +79,7 @@
79
79
  <PropertyGroup Label="UserMacros" />
80
80
  <ItemDefinitionGroup>
81
81
  <ClCompile>
82
- <PrecompiledHeader>Use</PrecompiledHeader>
82
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
83
83
  <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
84
84
  <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
85
85
  <WarningLevel>Level4</WarningLevel>
@@ -112,6 +112,9 @@
112
112
  </ClCompile>
113
113
  </ItemDefinitionGroup>
114
114
  <ItemGroup>
115
+ <ClInclude Include="..\..\cxx\Macros.h" />
116
+ <ClInclude Include="..\..\cxx\UnistylesModel.h" />
117
+ <ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
115
118
  <ClInclude Include="ReactPackageProvider.h">
116
119
  <DependentUpon>ReactPackageProvider.idl</DependentUpon>
117
120
  </ClInclude>
@@ -119,6 +122,8 @@
119
122
  <ClInclude Include="pch.h" />
120
123
  </ItemGroup>
121
124
  <ItemGroup>
125
+ <ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
126
+ <ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
122
127
  <ClCompile Include="..\..\cxx\UnistylesRuntime.cpp">
123
128
  <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
124
129
  <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
@@ -154,4 +159,4 @@
154
159
  <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
155
160
  <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
156
161
  </Target>
157
- </Project>
162
+ </Project>
@@ -8,13 +8,18 @@
8
8
  <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
9
9
  <ClCompile Include="ReactPackageProvider.cpp" />
10
10
  <ClCompile Include="..\..\cxx\UnistylesRuntime.cpp" />
11
+ <ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
12
+ <ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
11
13
  </ItemGroup>
12
14
  <ItemGroup>
13
15
  <ClInclude Include="pch.h" />
14
16
  <ClInclude Include="ReactPackageProvider.h" />
15
17
  <ClInclude Include="ReactNativeUnistyles.h" />
18
+ <ClInclude Include="..\..\cxx\Macros.h" />
19
+ <ClInclude Include="..\..\cxx\UnistylesModel.h" />
20
+ <ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
16
21
  </ItemGroup>
17
22
  <ItemGroup>
18
23
  <None Include="PropertySheet.props" />
19
24
  </ItemGroup>
20
- </Project>
25
+ </Project>
@@ -4,17 +4,17 @@
4
4
  "native,Version=v0.0": {
5
5
  "Microsoft.ReactNative": {
6
6
  "type": "Direct",
7
- "requested": "[0.73.4, )",
8
- "resolved": "0.73.4",
9
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
7
+ "requested": "[0.74.9, )",
8
+ "resolved": "0.74.9",
9
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
10
10
  },
11
11
  "Microsoft.ReactNative.Cxx": {
12
12
  "type": "Direct",
13
- "requested": "[0.73.4, )",
14
- "resolved": "0.73.4",
15
- "contentHash": "wAXa85oSqbf46YRw+00NxWyGv4ABGTwNtutJG+Nfz3C1WzrovMI6kviGoOh2yY2cWeYYcHfuvvw6eKf1RsNCGw==",
13
+ "requested": "[0.74.9, )",
14
+ "resolved": "0.74.9",
15
+ "contentHash": "C+Z2fmjDc7SJXeOWyD/9ImqooU7yX3ALB1Yno2UNYo+Li2SImeG6DdEfcNfSCS2fek1R3znpd6yNEkar/t1n5w==",
16
16
  "dependencies": {
17
- "Microsoft.ReactNative": "0.73.4"
17
+ "Microsoft.ReactNative": "0.74.9"
18
18
  }
19
19
  },
20
20
  "Microsoft.UI.Xaml": {
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "Microsoft.Windows.CppWinRT": {
30
30
  "type": "Direct",
31
- "requested": "[2.0.211028.7, )",
32
- "resolved": "2.0.211028.7",
33
- "contentHash": "JBGI0c3WLoU6aYJRy9Qo0MLDQfObEp+d4nrhR95iyzf7+HOgjRunHDp/6eGFREd7xq3OI1mll9ecJrMfzBvlyg=="
31
+ "requested": "[2.0.230706.1, )",
32
+ "resolved": "2.0.230706.1",
33
+ "contentHash": "l0D7oCw/5X+xIKHqZTi62TtV+1qeSz7KVluNFdrJ9hXsst4ghvqQ/Yhura7JqRdZWBXAuDS0G0KwALptdoxweQ=="
34
34
  },
35
35
  "Microsoft.Web.WebView2": {
36
36
  "type": "Transitive",
@@ -41,9 +41,9 @@
41
41
  "native,Version=v0.0/win10-arm": {
42
42
  "Microsoft.ReactNative": {
43
43
  "type": "Direct",
44
- "requested": "[0.73.4, )",
45
- "resolved": "0.73.4",
46
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
44
+ "requested": "[0.74.9, )",
45
+ "resolved": "0.74.9",
46
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
47
47
  },
48
48
  "Microsoft.Web.WebView2": {
49
49
  "type": "Transitive",
@@ -54,9 +54,9 @@
54
54
  "native,Version=v0.0/win10-arm-aot": {
55
55
  "Microsoft.ReactNative": {
56
56
  "type": "Direct",
57
- "requested": "[0.73.4, )",
58
- "resolved": "0.73.4",
59
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
57
+ "requested": "[0.74.9, )",
58
+ "resolved": "0.74.9",
59
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
60
60
  },
61
61
  "Microsoft.Web.WebView2": {
62
62
  "type": "Transitive",
@@ -67,9 +67,9 @@
67
67
  "native,Version=v0.0/win10-arm64-aot": {
68
68
  "Microsoft.ReactNative": {
69
69
  "type": "Direct",
70
- "requested": "[0.73.4, )",
71
- "resolved": "0.73.4",
72
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
70
+ "requested": "[0.74.9, )",
71
+ "resolved": "0.74.9",
72
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
73
73
  },
74
74
  "Microsoft.Web.WebView2": {
75
75
  "type": "Transitive",
@@ -80,9 +80,9 @@
80
80
  "native,Version=v0.0/win10-x64": {
81
81
  "Microsoft.ReactNative": {
82
82
  "type": "Direct",
83
- "requested": "[0.73.4, )",
84
- "resolved": "0.73.4",
85
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
83
+ "requested": "[0.74.9, )",
84
+ "resolved": "0.74.9",
85
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
86
86
  },
87
87
  "Microsoft.Web.WebView2": {
88
88
  "type": "Transitive",
@@ -93,9 +93,9 @@
93
93
  "native,Version=v0.0/win10-x64-aot": {
94
94
  "Microsoft.ReactNative": {
95
95
  "type": "Direct",
96
- "requested": "[0.73.4, )",
97
- "resolved": "0.73.4",
98
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
96
+ "requested": "[0.74.9, )",
97
+ "resolved": "0.74.9",
98
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
99
99
  },
100
100
  "Microsoft.Web.WebView2": {
101
101
  "type": "Transitive",
@@ -106,9 +106,9 @@
106
106
  "native,Version=v0.0/win10-x86": {
107
107
  "Microsoft.ReactNative": {
108
108
  "type": "Direct",
109
- "requested": "[0.73.4, )",
110
- "resolved": "0.73.4",
111
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
109
+ "requested": "[0.74.9, )",
110
+ "resolved": "0.74.9",
111
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
112
112
  },
113
113
  "Microsoft.Web.WebView2": {
114
114
  "type": "Transitive",
@@ -119,9 +119,9 @@
119
119
  "native,Version=v0.0/win10-x86-aot": {
120
120
  "Microsoft.ReactNative": {
121
121
  "type": "Direct",
122
- "requested": "[0.73.4, )",
123
- "resolved": "0.73.4",
124
- "contentHash": "F/ttB+b+/Hfpedp9FRQSWJdVExkhdTqcc3VohGez+lOPpdXQeZzNPpqQlO8G4LzK3XlcSs2hZO7WkWEoaxrgOQ=="
122
+ "requested": "[0.74.9, )",
123
+ "resolved": "0.74.9",
124
+ "contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
125
125
  },
126
126
  "Microsoft.Web.WebView2": {
127
127
  "type": "Transitive",
@@ -1,116 +0,0 @@
1
- package com.unistyles
2
-
3
- import android.annotation.SuppressLint
4
- import android.content.res.Configuration
5
- import com.facebook.react.bridge.ReactApplicationContext
6
-
7
- class UnistylesConfig(private val reactApplicationContext: ReactApplicationContext) {
8
- private val insets: UnistylesInsets = UnistylesInsets(reactApplicationContext)
9
- private val density: Float = reactApplicationContext.resources.displayMetrics.density
10
- private var lastConfig: Config = this.getAppConfig()
11
- private var lastLayoutConfig: LayoutConfig = this.getAppLayoutConfig()
12
-
13
- fun hasNewConfig(): Boolean {
14
- val newConfig = this.getAppConfig()
15
- val newContentSizeCategory = newConfig.contentSizeCategory != lastConfig.contentSizeCategory
16
- val newColorScheme = newConfig.colorScheme != lastConfig.colorScheme
17
-
18
- if (!newContentSizeCategory && !newColorScheme) {
19
- return false
20
- }
21
-
22
- lastConfig = newConfig
23
- lastConfig.hasNewContentSizeCategory = newContentSizeCategory
24
- lastConfig.hasNewColorScheme = newColorScheme
25
-
26
- return true
27
- }
28
-
29
- fun hasNewLayoutConfig(): Boolean {
30
- val newConfig = this.getAppLayoutConfig()
31
-
32
- if (newConfig.isEqual(lastLayoutConfig)) {
33
- return false
34
- }
35
-
36
- lastLayoutConfig = newConfig
37
-
38
- return true
39
- }
40
-
41
- fun getConfig(): Config {
42
- return this.lastConfig
43
- }
44
-
45
- fun getLayoutConfig(): LayoutConfig {
46
- return this.lastLayoutConfig
47
- }
48
-
49
- private fun getAppConfig(): Config {
50
- val fontScale = reactApplicationContext.resources.configuration.fontScale
51
-
52
- return Config(
53
- this.getColorScheme(),
54
- this.getContentSizeCategory(fontScale),
55
- )
56
- }
57
-
58
- private fun getAppLayoutConfig(): LayoutConfig {
59
- val displayMetrics = reactApplicationContext.resources.displayMetrics
60
- val screenWidth = (displayMetrics.widthPixels / density).toInt()
61
- val screenHeight = (displayMetrics.heightPixels / density).toInt()
62
-
63
- return LayoutConfig(
64
- Dimensions(screenWidth, screenHeight),
65
- this.insets.get(),
66
- Dimensions(screenWidth, getStatusBarHeight()),
67
- Dimensions(screenWidth, getNavigationBarHeight())
68
- )
69
- }
70
-
71
- private fun getContentSizeCategory(fontScale: Float): String {
72
- val contentSizeCategory = when {
73
- fontScale <= 0.85f -> "Small"
74
- fontScale <= 1.0f -> "Default"
75
- fontScale <= 1.15f -> "Large"
76
- fontScale <= 1.3f -> "ExtraLarge"
77
- fontScale <= 1.5f -> "Huge"
78
- fontScale <= 1.8 -> "ExtraHuge"
79
- else -> "ExtraExtraHuge"
80
- }
81
-
82
- return contentSizeCategory
83
- }
84
-
85
- private fun getColorScheme(): String {
86
- val colorScheme = when (reactApplicationContext.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
87
- Configuration.UI_MODE_NIGHT_YES -> "dark"
88
- Configuration.UI_MODE_NIGHT_NO -> "light"
89
- else -> "unspecified"
90
- }
91
-
92
- return colorScheme
93
- }
94
-
95
- @SuppressLint("InternalInsetResource", "DiscouragedApi")
96
- private fun getStatusBarHeight(): Int {
97
- val heightResId = reactApplicationContext.resources.getIdentifier("status_bar_height", "dimen", "android")
98
-
99
- if (heightResId > 0) {
100
- return (reactApplicationContext.resources.getDimensionPixelSize(heightResId) / density).toInt()
101
- }
102
-
103
- return 0
104
- }
105
-
106
- @SuppressLint("InternalInsetResource", "DiscouragedApi")
107
- private fun getNavigationBarHeight(): Int {
108
- val heightResId = reactApplicationContext.resources.getIdentifier("navigation_bar_height", "dimen", "android")
109
-
110
- if (heightResId > 0) {
111
- return (reactApplicationContext.resources.getDimensionPixelSize(heightResId) / density).toInt()
112
- }
113
-
114
- return 0
115
- }
116
- }