react-native-unistyles 3.0.0-alpha.35 → 3.0.0-alpha.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. package/Unistyles.podspec +1 -1
  2. package/android/CMakeLists.txt +19 -36
  3. package/android/build.gradle +2 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +71 -0
  5. package/android/src/main/cxx/NativeUnistylesModule.h +42 -0
  6. package/android/src/main/cxx/cpp-adapter.cpp +8 -86
  7. package/android/src/main/java/com/unistyles/Equatable.kt +61 -0
  8. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +302 -0
  9. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +148 -0
  10. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +54 -0
  11. package/android/src/main/java/com/unistyles/UnistylesModule.kt +51 -0
  12. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +16 -14
  13. package/cxx/NativePlatform.h +11 -0
  14. package/cxx/common/Helpers.h +1 -1
  15. package/cxx/core/Unistyle.h +1 -1
  16. package/cxx/core/UnistyleData.h +1 -1
  17. package/cxx/core/UnistyleWrapper.h +1 -2
  18. package/cxx/core/UnistylesCommitHook.cpp +1 -1
  19. package/cxx/core/UnistylesMountHook.cpp +1 -1
  20. package/cxx/core/UnistylesRegistry.cpp +4 -13
  21. package/cxx/core/UnistylesRegistry.h +2 -3
  22. package/cxx/core/UnistylesState.cpp +10 -7
  23. package/cxx/hybridObjects/HybridNavigationBar.h +3 -3
  24. package/cxx/hybridObjects/HybridStatusBar.h +3 -3
  25. package/cxx/hybridObjects/HybridStyleSheet.cpp +21 -18
  26. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +4 -8
  27. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -3
  28. package/cxx/parser/Parser.cpp +3 -27
  29. package/cxx/parser/Parser.h +2 -3
  30. package/cxx/shadowTree/ShadowTrafficController.h +9 -5
  31. package/cxx/shadowTree/ShadowTreeManager.cpp +10 -5
  32. package/cxx/shadowTree/ShadowTreeManager.h +1 -1
  33. package/lib/commonjs/components/useMedia.js.map +1 -1
  34. package/lib/commonjs/components/useMedia.web.js +43 -0
  35. package/lib/commonjs/components/useMedia.web.js.map +1 -0
  36. package/lib/commonjs/core/createUnistylesComponent.js +57 -4
  37. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  38. package/lib/commonjs/core/createUnistylesComponent.native.js +6 -5
  39. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  40. package/lib/commonjs/web/convert/index.js +16 -11
  41. package/lib/commonjs/web/convert/index.js.map +1 -1
  42. package/lib/commonjs/web/convert/object/boxShadow.js +58 -0
  43. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -0
  44. package/lib/commonjs/web/convert/object/filter.js +42 -0
  45. package/lib/commonjs/web/convert/object/filter.js.map +1 -0
  46. package/lib/commonjs/web/convert/object/index.js +39 -0
  47. package/lib/commonjs/web/convert/object/index.js.map +1 -0
  48. package/lib/commonjs/web/convert/object/objectStyle.js +55 -0
  49. package/lib/commonjs/web/convert/object/objectStyle.js.map +1 -0
  50. package/lib/commonjs/web/convert/object/transform.js +27 -0
  51. package/lib/commonjs/web/convert/object/transform.js.map +1 -0
  52. package/lib/commonjs/web/convert/{boxShadow.js → shadow/boxShadow.js} +9 -24
  53. package/lib/commonjs/web/convert/shadow/boxShadow.js.map +1 -0
  54. package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js +38 -0
  55. package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
  56. package/lib/commonjs/web/convert/shadow/index.js +28 -0
  57. package/lib/commonjs/web/convert/shadow/index.js.map +1 -0
  58. package/lib/commonjs/web/convert/{textShadow.js → shadow/textShadow.js} +9 -23
  59. package/lib/commonjs/web/convert/shadow/textShadow.js.map +1 -0
  60. package/lib/commonjs/web/convert/utils.js +7 -3
  61. package/lib/commonjs/web/convert/utils.js.map +1 -1
  62. package/lib/commonjs/web/listener.js +10 -0
  63. package/lib/commonjs/web/listener.js.map +1 -1
  64. package/lib/commonjs/web/registry.js +13 -26
  65. package/lib/commonjs/web/registry.js.map +1 -1
  66. package/lib/commonjs/web/runtime.js +3 -0
  67. package/lib/commonjs/web/runtime.js.map +1 -1
  68. package/lib/commonjs/web/shadowRegistry.js +79 -39
  69. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  70. package/lib/commonjs/web/utils/common.js +3 -33
  71. package/lib/commonjs/web/utils/common.js.map +1 -1
  72. package/lib/commonjs/web/utils/unistyle.js +4 -1
  73. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  74. package/lib/module/components/useMedia.js.map +1 -1
  75. package/lib/module/components/useMedia.web.js +38 -0
  76. package/lib/module/components/useMedia.web.js.map +1 -0
  77. package/lib/module/core/createUnistylesComponent.js +55 -3
  78. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  79. package/lib/module/core/createUnistylesComponent.native.js +6 -5
  80. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  81. package/lib/module/web/convert/index.js +14 -9
  82. package/lib/module/web/convert/index.js.map +1 -1
  83. package/lib/module/web/convert/object/boxShadow.js +53 -0
  84. package/lib/module/web/convert/object/boxShadow.js.map +1 -0
  85. package/lib/module/web/convert/object/filter.js +37 -0
  86. package/lib/module/web/convert/object/filter.js.map +1 -0
  87. package/lib/module/web/convert/object/index.js +6 -0
  88. package/lib/module/web/convert/object/index.js.map +1 -0
  89. package/lib/module/web/convert/object/objectStyle.js +50 -0
  90. package/lib/module/web/convert/object/objectStyle.js.map +1 -0
  91. package/lib/module/web/convert/object/transform.js +22 -0
  92. package/lib/module/web/convert/object/transform.js.map +1 -0
  93. package/lib/module/web/convert/{boxShadow.js → shadow/boxShadow.js} +9 -24
  94. package/lib/module/web/convert/shadow/boxShadow.js.map +1 -0
  95. package/lib/module/web/convert/shadow/getShadowBreakpoints.js +33 -0
  96. package/lib/module/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
  97. package/lib/module/web/convert/shadow/index.js +5 -0
  98. package/lib/module/web/convert/shadow/index.js.map +1 -0
  99. package/lib/module/web/convert/{textShadow.js → shadow/textShadow.js} +9 -23
  100. package/lib/module/web/convert/shadow/textShadow.js.map +1 -0
  101. package/lib/module/web/convert/utils.js +4 -2
  102. package/lib/module/web/convert/utils.js.map +1 -1
  103. package/lib/module/web/listener.js +10 -0
  104. package/lib/module/web/listener.js.map +1 -1
  105. package/lib/module/web/registry.js +14 -27
  106. package/lib/module/web/registry.js.map +1 -1
  107. package/lib/module/web/runtime.js +3 -0
  108. package/lib/module/web/runtime.js.map +1 -1
  109. package/lib/module/web/shadowRegistry.js +80 -40
  110. package/lib/module/web/shadowRegistry.js.map +1 -1
  111. package/lib/module/web/utils/common.js +1 -31
  112. package/lib/module/web/utils/common.js.map +1 -1
  113. package/lib/module/web/utils/unistyle.js +4 -1
  114. package/lib/module/web/utils/unistyle.js.map +1 -1
  115. package/lib/typescript/src/components/useMedia.web.d.ts +6 -0
  116. package/lib/typescript/src/components/useMedia.web.d.ts.map +1 -0
  117. package/lib/typescript/src/core/createUnistylesComponent.d.ts +4 -3
  118. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  119. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +4 -3
  120. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
  121. package/lib/typescript/src/types/common.d.ts +1 -0
  122. package/lib/typescript/src/types/common.d.ts.map +1 -1
  123. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  124. package/lib/typescript/src/web/convert/object/boxShadow.d.ts +9 -0
  125. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -0
  126. package/lib/typescript/src/web/convert/object/filter.d.ts +3 -0
  127. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -0
  128. package/lib/typescript/src/web/convert/object/index.d.ts +4 -0
  129. package/lib/typescript/src/web/convert/object/index.d.ts.map +1 -0
  130. package/lib/typescript/src/web/convert/object/objectStyle.d.ts +5 -0
  131. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -0
  132. package/lib/typescript/src/web/convert/object/transform.d.ts +3 -0
  133. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -0
  134. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -0
  135. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts +2 -0
  136. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -0
  137. package/lib/typescript/src/web/convert/shadow/index.d.ts +3 -0
  138. package/lib/typescript/src/web/convert/shadow/index.d.ts.map +1 -0
  139. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -0
  140. package/lib/typescript/src/web/convert/types.d.ts +7 -1
  141. package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
  142. package/lib/typescript/src/web/convert/utils.d.ts +8 -4
  143. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  144. package/lib/typescript/src/web/create.d.ts +8 -8
  145. package/lib/typescript/src/web/index.d.ts +8 -8
  146. package/lib/typescript/src/web/listener.d.ts +2 -0
  147. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  148. package/lib/typescript/src/web/registry.d.ts +5 -9
  149. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  150. package/lib/typescript/src/web/runtime.d.ts +1 -0
  151. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  152. package/lib/typescript/src/web/shadowRegistry.d.ts +4 -1
  153. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  154. package/lib/typescript/src/web/utils/common.d.ts +1 -6
  155. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  156. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  157. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -0
  158. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +1 -0
  159. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void.kt +1 -0
  160. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency_.kt +1 -0
  161. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +1 -0
  162. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +1 -0
  163. package/nitrogen/generated/android/unistyles+autolinking.gradle +2 -0
  164. package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
  165. package/package.json +3 -3
  166. package/src/components/useMedia.ts +1 -1
  167. package/src/components/useMedia.web.ts +47 -0
  168. package/src/core/createUnistylesComponent.native.tsx +12 -10
  169. package/src/core/createUnistylesComponent.tsx +72 -6
  170. package/src/types/common.ts +1 -0
  171. package/src/web/convert/index.ts +16 -9
  172. package/src/web/convert/object/boxShadow.ts +54 -0
  173. package/src/web/convert/object/filter.ts +39 -0
  174. package/src/web/convert/object/index.ts +3 -0
  175. package/src/web/convert/object/objectStyle.ts +68 -0
  176. package/src/web/convert/object/transform.ts +24 -0
  177. package/src/web/convert/{boxShadow.ts → shadow/boxShadow.ts} +9 -30
  178. package/src/web/convert/shadow/getShadowBreakpoints.ts +34 -0
  179. package/src/web/convert/shadow/index.ts +2 -0
  180. package/src/web/convert/{textShadow.ts → shadow/textShadow.ts} +9 -29
  181. package/src/web/convert/types.ts +8 -1
  182. package/src/web/convert/utils.ts +11 -5
  183. package/src/web/listener.ts +10 -0
  184. package/src/web/registry.ts +10 -31
  185. package/src/web/runtime.ts +4 -0
  186. package/src/web/shadowRegistry.ts +85 -46
  187. package/src/web/utils/common.ts +1 -37
  188. package/src/web/utils/unistyle.ts +5 -1
  189. package/android/src/main/cxx/helpers.cpp +0 -105
  190. package/android/src/main/cxx/helpers.h +0 -16
  191. package/android/src/main/cxx/platform.cpp +0 -170
  192. package/android/src/main/cxx/platform.h +0 -20
  193. package/lib/commonjs/web/convert/boxShadow.js.map +0 -1
  194. package/lib/commonjs/web/convert/shadow.js +0 -68
  195. package/lib/commonjs/web/convert/shadow.js.map +0 -1
  196. package/lib/commonjs/web/convert/textShadow.js.map +0 -1
  197. package/lib/commonjs/web/convert/transform.js +0 -72
  198. package/lib/commonjs/web/convert/transform.js.map +0 -1
  199. package/lib/module/web/convert/boxShadow.js.map +0 -1
  200. package/lib/module/web/convert/shadow.js +0 -63
  201. package/lib/module/web/convert/shadow.js.map +0 -1
  202. package/lib/module/web/convert/textShadow.js.map +0 -1
  203. package/lib/module/web/convert/transform.js +0 -67
  204. package/lib/module/web/convert/transform.js.map +0 -1
  205. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +0 -1
  206. package/lib/typescript/src/web/convert/shadow.d.ts +0 -2
  207. package/lib/typescript/src/web/convert/shadow.d.ts.map +0 -1
  208. package/lib/typescript/src/web/convert/textShadow.d.ts.map +0 -1
  209. package/lib/typescript/src/web/convert/transform.d.ts +0 -4
  210. package/lib/typescript/src/web/convert/transform.d.ts.map +0 -1
  211. package/src/web/convert/shadow.ts +0 -68
  212. package/src/web/convert/transform.ts +0 -88
  213. /package/lib/typescript/src/web/convert/{boxShadow.d.ts → shadow/boxShadow.d.ts} +0 -0
  214. /package/lib/typescript/src/web/convert/{textShadow.d.ts → shadow/textShadow.d.ts} +0 -0
package/Unistyles.podspec CHANGED
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
19
19
  ]
20
20
  s.pod_target_xcconfig = {
21
21
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
22
- "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
22
+ "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES FOLLY_MOBILE"
23
23
  }
24
24
 
25
25
  s.public_header_files = [
@@ -2,28 +2,28 @@ cmake_minimum_required(VERSION 3.9.0)
2
2
 
3
3
  project(unistyles)
4
4
 
5
+ file(GLOB_RECURSE CORE_SRC RELATIVE ${CMAKE_SOURCE_DIR} "../cxx/**/*.cpp")
6
+ file(GLOB_RECURSE PLATFORM_SRC RELATIVE ${CMAKE_SOURCE_DIR} "./src/main/cxx/*.cpp")
7
+
5
8
  add_library(unistyles
6
9
  SHARED
7
- ../cxx/HostStyle.cpp
8
- ../cxx/HybridUnistylesRuntime.cpp
9
- ../cxx/HybridStatusBar.cpp
10
- ../cxx/HybridNavigationBar.cpp
11
- ../cxx/ShadowTreeTraverser.cpp
12
- ../cxx/StyleSheet.cpp
13
- ../cxx/StyleSheetImpl.cpp
14
- ../cxx/StyleSheetRegistry.cpp
15
- ../cxx/UnistylesImpl.cpp
16
- ../cxx/UnistylesModel.cpp
17
- ../cxx/UnistylesRuntime.cpp
18
- ./src/main/cxx/cpp-adapter.cpp
19
- ./src/main/cxx/helpers.cpp
20
- ./src/main/cxx/platform.cpp
10
+ ${CORE_SRC}
11
+ ${PLATFORM_SRC}
21
12
  )
22
13
 
23
- include_directories(../cxx)
24
- include("${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/Unistyles+autolinking.cmake")
14
+ include("${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/unistyles+autolinking.cmake")
15
+
16
+ include_directories(
17
+ ./src/main/cxx
18
+ ../cxx
19
+ ../cxx/common
20
+ ../cxx/core
21
+ ../cxx/hybridObjects
22
+ ../cxx/parser
23
+ ../cxx/shadowTree
24
+ )
25
25
 
26
- string(APPEND CMAKE_CXX_FLAGS " -DFOLLY_NO_CONFIG")
26
+ string(APPEND CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_CFG_NO_COROUTINES=1 -DFOLLY_MOBILE=1")
27
27
 
28
28
  set_target_properties(unistyles PROPERTIES
29
29
  CXX_STANDARD 20
@@ -32,22 +32,5 @@ set_target_properties(unistyles PROPERTIES
32
32
  POSITION_INDEPENDENT_CODE ON
33
33
  )
34
34
 
35
- find_package(ReactAndroid REQUIRED CONFIG)
36
- find_package(fbjni REQUIRED CONFIG)
37
-
38
- # REACTNATIVE_MERGED_SO doesnt work as of RN 0.76.0-rc.3
39
- if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
40
- target_link_libraries(unistyles ReactAndroid::reactnative)
41
- else()
42
- target_link_libraries(unistyles
43
- ReactAndroid::turbomodulejsijni
44
- ReactAndroid::react_nativemodule_core
45
- android
46
- fbjni::fbjni
47
- )
48
- endif()
49
-
50
- target_link_libraries(unistyles
51
- ReactAndroid::jsi
52
- fbjni::fbjni
53
- )
35
+ # For React Native 0.76 and above, we don't need to link anything
36
+ # as NitroModules will automatically add ReactAndroid::reactnative prefab
@@ -14,7 +14,7 @@ buildscript {
14
14
 
15
15
  apply plugin: 'com.android.library'
16
16
  apply plugin: 'org.jetbrains.kotlin.android'
17
- apply from: '../nitrogen/generated/android/Unistyles+autolinking.gradle'
17
+ apply from: '../nitrogen/generated/android/unistyles+autolinking.gradle'
18
18
 
19
19
  def resolveBuildType() {
20
20
  Gradle gradle = getGradle()
@@ -62,6 +62,7 @@ android {
62
62
  "META-INF/**",
63
63
  "**/libjsi.so",
64
64
  "**/libc++_shared.so",
65
+ "**/libreactnative.so",
65
66
  "**/libreact_nativemodule_core.so",
66
67
  "**/libturbomodulejsijni.so",
67
68
  "**/libfbjni.so"
@@ -0,0 +1,71 @@
1
+ #include "NativeUnistylesModule.h"
2
+ #import <NitroModules/HybridObjectRegistry.hpp>
3
+ #import "HybridUnistylesRuntime.h"
4
+ #import "HybridStyleSheet.h"
5
+ #import "HybridShadowRegistry.h"
6
+
7
+ using namespace margelo::nitro::unistyles;
8
+ using namespace facebook::react;
9
+
10
+ UnistylesModule::UnistylesModule(
11
+ jni::alias_ref<UnistylesModule::jhybridobject> jThis,
12
+ jni::alias_ref<react::JRuntimeExecutor::javaobject> runtimeExecutorHolder,
13
+ jni::alias_ref<JFabricUIManager::javaobject> fabricUIManager,
14
+ jni::alias_ref<JHybridNativePlatformSpec::javaobject> nativePlatform
15
+ ): _runtimeExecutor(runtimeExecutorHolder->cthis()->get()),
16
+ _uiManager(fabricUIManager->getBinding()->getScheduler()->getUIManager()),
17
+ _nativePlatform(nativePlatform->cthis()) {}
18
+
19
+ jni::local_ref<UnistylesModule::jhybriddata> UnistylesModule::initHybrid(
20
+ jni::alias_ref<UnistylesModule::jhybridobject> jThis,
21
+ jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
22
+ jni::alias_ref<JFabricUIManager::javaobject> fabricUIManager,
23
+ jni::alias_ref<JHybridNativePlatformSpec::javaobject> nativePlatform
24
+ ) {
25
+ return makeCxxInstance(jThis, runtimeExecutorHolder, fabricUIManager, nativePlatform);
26
+ }
27
+
28
+ void UnistylesModule::registerNatives() {
29
+ javaClassStatic()->registerNatives({
30
+ makeNativeMethod("getBindingsInstaller", UnistylesModule::getBindingsInstaller),
31
+ makeNativeMethod("initHybrid", UnistylesModule::initHybrid)
32
+ });
33
+ }
34
+
35
+ jni::local_ref<BindingsInstallerHolder::javaobject> UnistylesModule::getBindingsInstaller(jni::alias_ref<UnistylesModule::javaobject> jobj) {
36
+ auto& runtimeExecutor = jobj->cthis()->_runtimeExecutor;
37
+ auto& uiManager = jobj->cthis()->_uiManager;
38
+ auto& nativePlatform = *jobj->cthis()->_nativePlatform;
39
+
40
+ return BindingsInstallerHolder::newObjectCxxArgs([&runtimeExecutor, uiManager, nativePlatform](jsi::Runtime& rt) {
41
+ // function is called on: first init and every live reload
42
+ // check if this is live reload, if so let's replace UnistylesRuntime with new runtime
43
+ auto hasUnistylesRuntime = HybridObjectRegistry::hasHybridObject("UnistylesRuntime");
44
+
45
+ if (hasUnistylesRuntime) {
46
+ HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesRuntime");
47
+ HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesStyleSheet");
48
+ HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesShadowRegistry");
49
+ }
50
+
51
+ auto runOnJSThread = [&runtimeExecutor](std::function<void(jsi::Runtime&)>&& callback) {
52
+ runtimeExecutor([callback = std::move(callback)](jsi::Runtime &rt) {
53
+ callback(rt);
54
+ });
55
+ };
56
+
57
+ // init hybrids
58
+ auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, rt, runOnJSThread);
59
+ auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime, uiManager);
60
+
61
+ HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject>{
62
+ return unistylesRuntime;
63
+ });
64
+ HybridObjectRegistry::registerHybridObjectConstructor("UnistylesStyleSheet", [styleSheet]() -> std::shared_ptr<HybridObject>{
65
+ return styleSheet;
66
+ });
67
+ HybridObjectRegistry::registerHybridObjectConstructor("UnistylesShadowRegistry", []() -> std::shared_ptr<HybridObject>{
68
+ return std::make_shared<HybridShadowRegistry>();
69
+ });
70
+ });
71
+ }
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/BindingsInstallerHolder.h>
4
+ #include <react/fabric/JFabricUIManager.h>
5
+ #include <react/jni/JRuntimeExecutor.h>
6
+ #include <react/renderer/scheduler/Scheduler.h>
7
+ #include <fbjni/fbjni.h>
8
+ #include <react/fabric/Binding.h>
9
+ #include "NativePlatform.h"
10
+
11
+ namespace margelo::nitro::unistyles {
12
+
13
+ using namespace facebook;
14
+ using namespace facebook::react;
15
+
16
+ struct UnistylesModule : public jni::HybridClass<UnistylesModule> {
17
+ static constexpr auto kJavaDescriptor = "Lcom/unistyles/UnistylesModule;";
18
+
19
+ explicit UnistylesModule(
20
+ jni::alias_ref<jhybridobject> jThis,
21
+ jni::alias_ref<react::JRuntimeExecutor::javaobject> runtimeExecutorHolder,
22
+ jni::alias_ref<JFabricUIManager::javaobject> fabricUIManager,
23
+ jni::alias_ref<JHybridNativePlatformSpec::javaobject> nativePlatform
24
+ );
25
+
26
+ static void registerNatives();
27
+ static jni::local_ref<jhybriddata> initHybrid(
28
+ jni::alias_ref<jhybridobject> jThis,
29
+ jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
30
+ jni::alias_ref<JFabricUIManager::javaobject>,
31
+ jni::alias_ref<JHybridNativePlatformSpec::javaobject> nativePlatform
32
+ );
33
+
34
+ static jni::local_ref<BindingsInstallerHolder::javaobject> getBindingsInstaller(jni::alias_ref<UnistylesModule::javaobject> jThis);
35
+
36
+ private:
37
+ std::shared_ptr<UIManager> _uiManager;
38
+ RuntimeExecutor _runtimeExecutor;
39
+ Unistyles::HybridNativePlatformSpecCxx* _nativePlatform;
40
+ };
41
+
42
+ }
@@ -1,88 +1,10 @@
1
- #include <jni.h>
2
-
3
- #include <NitroModules/HybridObjectRegistry.hpp>
4
- #include <HybridUnistylesRuntime.h>
5
- #include <HybridStatusBar.h>
6
- #include <HybridNavigationBar.h>
7
-
8
- JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
9
- HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", []() -> std::shared_ptr<HybridObject>{
10
- return std::make_shared<HybridUnistylesRuntime>();
11
- });
12
- HybridObjectRegistry::registerHybridObjectConstructor("StatusBar", []() -> std::shared_ptr<HybridObject>{
13
- return std::make_shared<HybridStatusBar>();
1
+ #include <fbjni/fbjni.h>
2
+ #include "unistylesOnLoad.hpp"
3
+ #include "NativeUnistylesModule.h"
4
+
5
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
6
+ return facebook::jni::initialize(vm, [=] {
7
+ margelo::nitro::unistyles::UnistylesModule::registerNatives();
8
+ margelo::nitro::unistyles::initialize(vm);
14
9
  });
15
- HybridObjectRegistry::registerHybridObjectConstructor("NavigationBar", []() -> std::shared_ptr<HybridObject>{
16
- return std::make_shared<HybridNavigationBar>();
17
- });
18
-
19
- return JNI_VERSION_1_2;
20
10
  }
21
-
22
- //using namespace facebook;
23
- //
24
- //static jobject unistylesModule = nullptr;
25
- //std::shared_ptr<UnistylesRuntime> unistylesRuntime = nullptr;
26
- //
27
- //extern "C"
28
- //JNIEXPORT void JNICALL
29
- //Java_com_unistyles_UnistylesModule_nativeInstall(JNIEnv *env, jobject thiz, jlong jsi, jobject callInvokerHolder) {
30
- // auto runtime = reinterpret_cast<jsi::Runtime *>(jsi);
31
- // auto callInvoker{
32
- // jni::alias_ref<react::CallInvokerHolder::javaobject>{ reinterpret_cast<react::CallInvokerHolder::javaobject>(callInvokerHolder)} -> cthis() ->getCallInvoker()
33
- // };
34
- //
35
- // if (unistylesModule == nullptr) {
36
- // unistylesModule = env->NewGlobalRef(thiz);
37
- // }
38
- //
39
- // if (unistylesModule == nullptr) {
40
- // return throwKotlinException(env, "Something went wrong while initializing UnistylesModule");
41
- // }
42
- //
43
- // unistylesRuntime = std::make_shared<UnistylesRuntime>(*runtime, callInvoker);
44
- // auto styleSheet = std::make_shared<StyleSheet>(*runtime, unistylesRuntime);
45
- //
46
- // makeShared(env, unistylesModule, unistylesRuntime);
47
- //
48
- // jsi::Object hostObject = jsi::Object::createFromHostObject(*runtime, unistylesRuntime);
49
- // jsi::Object styleSheetHostObject = jsi::Object::createFromHostObject(*runtime, styleSheet);
50
- // runtime->global().setProperty(*runtime, "__UNISTYLES__", std::move(hostObject));
51
- // runtime->global().setProperty(*runtime, "__UNISTYLES__STYLESHEET__", std::move(styleSheetHostObject));
52
- //}
53
- //
54
- //extern "C"
55
- //JNIEXPORT void JNICALL
56
- //Java_com_unistyles_UnistylesModule_nativeDestroy(JNIEnv *env, jobject thiz) {
57
- // unistylesRuntime.reset();
58
- // unistylesModule = nullptr;
59
- //}
60
- //
61
- //extern "C"
62
- //JNIEXPORT void JNICALL
63
- //Java_com_unistyles_UnistylesModule_nativeOnOrientationChange(JNIEnv *env, jobject thiz, jobject screen, jobject insets, jobject statusBar, jobject navigationBar) {
64
- // if (unistylesRuntime != nullptr) {
65
- // Screen screenDimensions = jobjectToScreen(env, screen);
66
- // Dimensions statusBarDimensions = jobjectToDimensions(env, statusBar);
67
- // Insets screenInsets = jobjectToInsets(env, insets);
68
- // Dimensions navigationBarDimensions = jobjectToDimensions(env, navigationBar);
69
- //
70
- // unistylesRuntime->handleScreenSizeChange(screenDimensions, screenInsets, statusBarDimensions, navigationBarDimensions);
71
- // }
72
- //}
73
- //
74
- //extern "C"
75
- //JNIEXPORT void JNICALL
76
- //Java_com_unistyles_UnistylesModule_nativeOnAppearanceChange(JNIEnv *env, jobject thiz, jstring colorScheme) {
77
- // if (unistylesRuntime != nullptr) {
78
- // unistylesRuntime->handleAppearanceChange(env->GetStringUTFChars(colorScheme, nullptr));
79
- // }
80
- //}
81
- //
82
- //extern "C"
83
- //JNIEXPORT void JNICALL
84
- //Java_com_unistyles_UnistylesModule_nativeOnContentSizeCategoryChange(JNIEnv *env, jobject thiz, jstring contentSizeCategory) {
85
- // if (unistylesRuntime != nullptr) {
86
- // unistylesRuntime->handleContentSizeCategoryChange(env->GetStringUTFChars(contentSizeCategory, nullptr));
87
- // }
88
- //}
@@ -0,0 +1,61 @@
1
+ package com.unistyles
2
+
3
+ import com.margelo.nitro.unistyles.Dimensions
4
+ import com.margelo.nitro.unistyles.Insets
5
+ import com.margelo.nitro.unistyles.UnistyleDependency
6
+ import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
7
+
8
+ fun Dimensions.isEqualTo(other: Dimensions): Boolean {
9
+ return this.width == other.width && this.height == other.height
10
+ }
11
+
12
+ fun Insets.isEqualTo(other: Insets): Boolean {
13
+ return this.top == other.top && this.bottom == other.bottom &&
14
+ this.left == other.left && this.right == other.right &&
15
+ this.ime == other.ime
16
+ }
17
+
18
+ fun NativePlatformAndroid.diffMiniRuntimes(lhs: UnistylesNativeMiniRuntime, rhs: UnistylesNativeMiniRuntime): Array<UnistyleDependency> {
19
+ val dependencies: MutableList<UnistyleDependency> = mutableListOf()
20
+
21
+ if (lhs.colorScheme != rhs.colorScheme) {
22
+ dependencies.add(UnistyleDependency.COLORSCHEME)
23
+ }
24
+
25
+ if (!lhs.screen.isEqualTo(rhs.screen)) {
26
+ dependencies.add(UnistyleDependency.DIMENSIONS)
27
+ }
28
+
29
+ if (lhs.screen.width != rhs.screen.width) {
30
+ dependencies.add(UnistyleDependency.BREAKPOINTS)
31
+ }
32
+
33
+ // no need to check isLandscape, as it's always opposite
34
+ if (lhs.isPortrait != rhs.isPortrait) {
35
+ dependencies.add(UnistyleDependency.ORIENTATION)
36
+ }
37
+
38
+ if (lhs.contentSizeCategory != rhs.contentSizeCategory) {
39
+ dependencies.add(UnistyleDependency.CONTENTSIZECATEGORY)
40
+ }
41
+
42
+ if (!lhs.insets.isEqualTo(rhs.insets)) {
43
+ dependencies.add(UnistyleDependency.INSETS)
44
+ }
45
+
46
+ if (lhs.fontScale != rhs.fontScale) {
47
+ dependencies.add(UnistyleDependency.FONTSCALE)
48
+ }
49
+
50
+ if (!lhs.statusBar.isEqualTo(rhs.statusBar)) {
51
+ dependencies.add(UnistyleDependency.STATUSBAR)
52
+ }
53
+
54
+ if (!lhs.navigationBar.isEqualTo(rhs.navigationBar)) {
55
+ dependencies.add(UnistyleDependency.NAVIGATIONBAR)
56
+ }
57
+
58
+ // rtl and pixel ratio are not dynamic
59
+
60
+ return dependencies.toTypedArray()
61
+ }
@@ -0,0 +1,302 @@
1
+ package com.unistyles
2
+
3
+ import android.content.Context
4
+ import android.content.res.Configuration
5
+ import android.os.Build
6
+ import android.util.DisplayMetrics
7
+ import android.view.View
8
+ import android.view.WindowManager
9
+ import androidx.core.text.TextUtilsCompat
10
+ import androidx.core.view.ViewCompat
11
+ import androidx.core.view.WindowCompat
12
+ import androidx.core.view.WindowInsetsCompat
13
+ import androidx.core.view.WindowInsetsControllerCompat
14
+ import com.facebook.react.bridge.LifecycleEventListener
15
+ import com.facebook.react.bridge.ReactApplicationContext
16
+ import com.margelo.nitro.unistyles.ColorScheme
17
+ import com.margelo.nitro.unistyles.Dimensions
18
+ import com.margelo.nitro.unistyles.HybridNativePlatformSpec
19
+ import com.margelo.nitro.unistyles.Insets
20
+ import com.margelo.nitro.unistyles.Orientation
21
+ import com.margelo.nitro.unistyles.UnistyleDependency
22
+ import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
23
+ import java.util.Locale
24
+
25
+ class NativePlatformAndroid(private val reactContext: ReactApplicationContext): HybridNativePlatformSpec(), LifecycleEventListener {
26
+ private val _insets = NativePlatformInsets(reactContext) { this.diffMiniRuntime() }
27
+ private var _miniRuntime: UnistylesNativeMiniRuntime = buildMiniRuntime()
28
+ private val _listener = NativePlatformListener(reactContext) { this.diffMiniRuntime() }
29
+
30
+ init {
31
+ reactContext.addLifecycleEventListener(this)
32
+ }
33
+
34
+ fun invalidate() {
35
+ reactContext.removeLifecycleEventListener(this)
36
+ _listener.invalidate()
37
+ }
38
+
39
+ override fun onHostResume() {
40
+ enableEdgeToEdge()
41
+ _insets.startInsetsListener()
42
+ }
43
+
44
+ override fun onHostPause() {
45
+ _insets.stopInsetsListener()
46
+ }
47
+
48
+ override fun onHostDestroy() {}
49
+
50
+ override val memorySize: Long
51
+ get() = 0
52
+
53
+ override fun getInsets(): Insets {
54
+ return _insets.getInsets()
55
+ }
56
+
57
+ override fun getColorScheme(): ColorScheme {
58
+ val uiMode = reactContext.resources.configuration.uiMode
59
+
60
+ val colorScheme = when (uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
61
+ Configuration.UI_MODE_NIGHT_YES -> ColorScheme.DARK
62
+ Configuration.UI_MODE_NIGHT_NO -> ColorScheme.LIGHT
63
+ else -> ColorScheme.UNSPECIFIED
64
+ }
65
+
66
+ return colorScheme
67
+ }
68
+
69
+ override fun getFontScale(): Double {
70
+ return reactContext.resources.configuration.fontScale.toDouble()
71
+ }
72
+
73
+ override fun getPixelRatio(): Double {
74
+ return reactContext.resources.displayMetrics.density.toDouble()
75
+ }
76
+
77
+ override fun getOrientation(): Orientation {
78
+ val orientation = when (reactContext.resources.configuration.orientation) {
79
+ Configuration.ORIENTATION_PORTRAIT -> Orientation.PORTRAIT
80
+ Configuration.ORIENTATION_LANDSCAPE -> Orientation.LANDSCAPE
81
+ else -> Orientation.PORTRAIT
82
+ }
83
+
84
+ return orientation
85
+ }
86
+
87
+ override fun getContentSizeCategory(): String {
88
+ val fontScale = getFontScale()
89
+
90
+ val contentSizeCategory = when {
91
+ fontScale <= 0.85f -> "Small"
92
+ fontScale <= 1.0f -> "Default"
93
+ fontScale <= 1.15f -> "Large"
94
+ fontScale <= 1.3f -> "ExtraLarge"
95
+ fontScale <= 1.5f -> "Huge"
96
+ fontScale <= 1.8 -> "ExtraHuge"
97
+ else -> "ExtraExtraHuge"
98
+ }
99
+
100
+ return contentSizeCategory
101
+ }
102
+
103
+ override fun getScreenDimensions(): Dimensions {
104
+ // function takes in count edge-to-edge layout
105
+ when {
106
+ Build.VERSION.SDK_INT < Build.VERSION_CODES.R -> {
107
+ val windowManager = reactContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
108
+ val metrics = DisplayMetrics()
109
+
110
+ @Suppress("DEPRECATION")
111
+ windowManager.defaultDisplay.getRealMetrics(metrics)
112
+
113
+ val screenWidth = (metrics.widthPixels / metrics.density).toDouble()
114
+ val screenHeight = (metrics.heightPixels / metrics.density).toDouble()
115
+
116
+ return Dimensions(screenWidth, screenHeight)
117
+ }
118
+ else -> {
119
+ val displayMetrics = reactContext.resources.displayMetrics
120
+
121
+ reactContext.currentActivity?.windowManager?.currentWindowMetrics?.bounds?.let {
122
+ val boundsWidth = (it.width() / displayMetrics.density).toDouble()
123
+ val boundsHeight = (it.height() / displayMetrics.density).toDouble()
124
+
125
+ return Dimensions(boundsWidth, boundsHeight)
126
+ } ?: run {
127
+ val screenWidth = (displayMetrics.widthPixels / displayMetrics.density).toDouble()
128
+ val screenHeight = (displayMetrics.heightPixels / displayMetrics.density).toDouble()
129
+
130
+ return Dimensions(screenWidth, screenHeight)
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ override fun getStatusBarDimensions(): Dimensions {
137
+ val screenWidth = getScreenDimensions().width
138
+
139
+ return Dimensions(screenWidth, _insets.getInsets().top)
140
+ }
141
+
142
+ override fun getNavigationBarDimensions(): Dimensions {
143
+ val screenWidth = getScreenDimensions().width
144
+
145
+ return Dimensions(screenWidth, _insets.getInsets().bottom)
146
+ }
147
+
148
+ override fun getPrefersRtlDirection(): Boolean {
149
+ // forced by React Native
150
+ val sharedPrefs = reactContext.getSharedPreferences(
151
+ "com.facebook.react.modules.i18nmanager.I18nUtil",
152
+ Context.MODE_PRIVATE
153
+ )
154
+ val hasForcedRtl = sharedPrefs.getBoolean("RCTI18nUtil_forceRTL", false)
155
+ // user preferences
156
+ val isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
157
+
158
+ return hasForcedRtl || isRtl
159
+ }
160
+
161
+ override fun setRootViewBackgroundColor(color: Double) {
162
+ reactContext.currentActivity?.let { activity ->
163
+ activity.window?.decorView?.let { decorView ->
164
+ activity.runOnUiThread {
165
+ decorView.rootView.setBackgroundColor(color.toInt())
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ @Suppress("DEPRECATION")
172
+ override fun setNavigationBarBackgroundColor(color: Double) {
173
+ reactContext.currentActivity?.let { activity ->
174
+ activity.runOnUiThread {
175
+ activity.window.navigationBarColor = color.toInt()
176
+ }
177
+ }
178
+ }
179
+
180
+ override fun setNavigationBarHidden(isHidden: Boolean) {
181
+ reactContext.currentActivity?.let { activity ->
182
+ WindowInsetsControllerCompat(activity.window, activity.window.decorView).apply {
183
+ activity.window?.decorView?.let { decorView ->
184
+ @Suppress("DEPRECATION")
185
+ activity.runOnUiThread {
186
+ if (isHidden) {
187
+ // below Android 11, we need to use window flags to hide the navigation bar
188
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
189
+ decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
190
+ or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
191
+ } else {
192
+ hide(WindowInsetsCompat.Type.navigationBars())
193
+ systemBarsBehavior =
194
+ WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
195
+ }
196
+
197
+ // dispatch new insets to invoke the insets listener
198
+ val newInsets = WindowInsetsCompat.Builder()
199
+ .setInsets(WindowInsetsCompat.Type.navigationBars(), androidx.core.graphics.Insets.of(0, 0, 0, 0))
200
+ .build()
201
+
202
+ ViewCompat.dispatchApplyWindowInsets(activity.findViewById(android.R.id.content), newInsets)
203
+ } else {
204
+ show(WindowInsetsCompat.Type.navigationBars())
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+
212
+ override fun setStatusBarHidden(isHidden: Boolean) {
213
+ reactContext.currentActivity?.let { activity ->
214
+ WindowInsetsControllerCompat(activity.window, activity.window.decorView).apply {
215
+ activity.window?.let { window ->
216
+ @Suppress("DEPRECATION")
217
+ activity.runOnUiThread {
218
+ if (isHidden) {
219
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
220
+ window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
221
+ window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
222
+ } else {
223
+ hide(WindowInsetsCompat.Type.statusBars())
224
+ }
225
+ } else {
226
+ show(WindowInsetsCompat.Type.statusBars())
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ @Suppress("DEPRECATION")
235
+ override fun setStatusBarBackgroundColor(color: Double) {
236
+ reactContext.currentActivity?.let { activity ->
237
+ activity.runOnUiThread {
238
+ activity.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
239
+ activity.window.statusBarColor = color.toInt()
240
+ }
241
+ }
242
+ }
243
+
244
+ override fun setImmersiveMode(isEnabled: Boolean) {
245
+ this.setStatusBarHidden(isEnabled)
246
+ this.setNavigationBarHidden(isEnabled)
247
+ }
248
+
249
+ override fun getMiniRuntime(): UnistylesNativeMiniRuntime {
250
+ return _miniRuntime
251
+ }
252
+
253
+ private fun buildMiniRuntime(): UnistylesNativeMiniRuntime {
254
+ val orientation = this.getOrientation()
255
+
256
+ return UnistylesNativeMiniRuntime(
257
+ colorScheme = this.getColorScheme(),
258
+ screen = this.getScreenDimensions(),
259
+ contentSizeCategory = this.getContentSizeCategory(),
260
+ insets = this.getInsets(),
261
+ pixelRatio = this.getPixelRatio(),
262
+ fontScale = this.getFontScale(),
263
+ rtl = this.getPrefersRtlDirection(),
264
+ statusBar = this.getStatusBarDimensions(),
265
+ navigationBar = this.getNavigationBarDimensions(),
266
+ isPortrait = orientation == Orientation.PORTRAIT,
267
+ isLandscape = orientation == Orientation.LANDSCAPE
268
+ )
269
+ }
270
+
271
+ private fun diffMiniRuntime(): Array<UnistyleDependency> {
272
+ val newMiniRuntime = this.buildMiniRuntime()
273
+ val changedDependencies = diffMiniRuntimes(this._miniRuntime, newMiniRuntime)
274
+
275
+ if (changedDependencies.isNotEmpty()) {
276
+ this._miniRuntime = newMiniRuntime
277
+ }
278
+
279
+ return changedDependencies
280
+ }
281
+
282
+ override fun registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>) -> Unit) {
283
+ this._listener.addPlatformListener(callback)
284
+ }
285
+
286
+ override fun registerImeListener(callback: () -> Unit) {
287
+ this._insets.addImeListener(callback)
288
+ }
289
+
290
+ override fun unregisterPlatformListeners() {
291
+ this._listener.removePlatformListeners()
292
+ this._insets.removeImeListeners()
293
+ }
294
+
295
+ private fun enableEdgeToEdge() {
296
+ reactContext.currentActivity?.let { activity ->
297
+ activity.runOnUiThread {
298
+ WindowCompat.setDecorFitsSystemWindows(activity.window, false)
299
+ }
300
+ }
301
+ }
302
+ }