react-native-unistyles 3.0.0-alpha.36 → 3.0.0-alpha.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/Unistyles.podspec +1 -1
  2. package/android/CMakeLists.txt +3 -15
  3. package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
  4. package/android/src/main/java/com/unistyles/Equatable.kt +61 -0
  5. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +302 -0
  6. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +148 -0
  7. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +54 -0
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +5 -1
  9. package/cxx/core/UnistyleData.h +1 -1
  10. package/cxx/core/UnistyleWrapper.h +1 -2
  11. package/cxx/core/UnistylesCommitHook.cpp +1 -1
  12. package/cxx/core/UnistylesMountHook.cpp +1 -1
  13. package/cxx/core/UnistylesRegistry.cpp +4 -13
  14. package/cxx/core/UnistylesRegistry.h +1 -2
  15. package/cxx/core/UnistylesState.cpp +10 -7
  16. package/cxx/hybridObjects/HybridStyleSheet.cpp +21 -18
  17. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +0 -4
  18. package/cxx/hybridObjects/HybridUnistylesRuntime.h +0 -1
  19. package/cxx/parser/Parser.cpp +3 -27
  20. package/cxx/parser/Parser.h +2 -3
  21. package/cxx/shadowTree/ShadowTrafficController.h +9 -5
  22. package/cxx/shadowTree/ShadowTreeManager.cpp +10 -5
  23. package/cxx/shadowTree/ShadowTreeManager.h +1 -1
  24. package/lib/commonjs/core/createUnistylesComponent.native.js +1 -1
  25. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  26. package/lib/module/core/createUnistylesComponent.native.js +1 -1
  27. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  28. package/package.json +3 -3
  29. package/plugin/common.js +7 -1
  30. package/src/core/createUnistylesComponent.native.tsx +1 -1
  31. package/android/src/main/java/com/unistyles/NativePlatform.kt +0 -184
  32. package/android/src/main/java/com/unistyles/UnistylesModule+insets.kt +0 -8
@@ -1,184 +0,0 @@
1
- package com.unistyles
2
-
3
- import UnistylesModuleInsets
4
- import android.content.Context
5
- import android.content.res.Configuration
6
- import android.os.Build
7
- import android.util.DisplayMetrics
8
- import android.view.WindowManager
9
- import androidx.core.text.TextUtilsCompat
10
- import androidx.core.view.ViewCompat
11
- import com.facebook.react.bridge.ReactApplicationContext
12
- import com.margelo.nitro.unistyles.ColorScheme
13
- import com.margelo.nitro.unistyles.Dimensions
14
- import com.margelo.nitro.unistyles.HybridNativePlatformSpec
15
- import com.margelo.nitro.unistyles.Insets
16
- import com.margelo.nitro.unistyles.Orientation
17
- import com.margelo.nitro.unistyles.UnistyleDependency
18
- import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
19
- import java.util.Locale
20
-
21
- class NativePlatform(private val reactContext: ReactApplicationContext): HybridNativePlatformSpec() {
22
- private val _insets = UnistylesModuleInsets(reactContext)
23
-
24
- override fun getInsets(): Insets {
25
- return _insets.getInsets()
26
- }
27
-
28
- override fun getColorScheme(): ColorScheme {
29
- val uiMode = reactContext.resources.configuration.uiMode
30
-
31
- val colorScheme = when (uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
32
- Configuration.UI_MODE_NIGHT_YES -> ColorScheme.DARK
33
- Configuration.UI_MODE_NIGHT_NO -> ColorScheme.LIGHT
34
- else -> ColorScheme.UNSPECIFIED
35
- }
36
-
37
- return colorScheme
38
- }
39
-
40
- override fun getFontScale(): Double {
41
- return reactContext.resources.configuration.fontScale.toDouble()
42
- }
43
-
44
- override fun getPixelRatio(): Double {
45
- return reactContext.resources.displayMetrics.density.toDouble()
46
- }
47
-
48
- override fun getOrientation(): Orientation {
49
- val orientation = when (reactContext.resources.configuration.orientation) {
50
- Configuration.ORIENTATION_PORTRAIT -> Orientation.PORTRAIT
51
- Configuration.ORIENTATION_LANDSCAPE -> Orientation.LANDSCAPE
52
- else -> Orientation.PORTRAIT
53
- }
54
-
55
- return orientation
56
- }
57
-
58
- override fun getContentSizeCategory(): String {
59
- val fontScale = reactContext.resources.configuration.fontScale
60
-
61
- val contentSizeCategory = when {
62
- fontScale <= 0.85f -> "Small"
63
- fontScale <= 1.0f -> "Default"
64
- fontScale <= 1.15f -> "Large"
65
- fontScale <= 1.3f -> "ExtraLarge"
66
- fontScale <= 1.5f -> "Huge"
67
- fontScale <= 1.8 -> "ExtraHuge"
68
- else -> "ExtraExtraHuge"
69
- }
70
-
71
- return contentSizeCategory
72
- }
73
-
74
- override fun getScreenDimensions(): Dimensions {
75
- // function takes in count edge-to-edge layout
76
- when {
77
- Build.VERSION.SDK_INT < Build.VERSION_CODES.R -> {
78
- val windowManager = reactContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
79
- val metrics = DisplayMetrics()
80
-
81
- windowManager.defaultDisplay.getRealMetrics(metrics)
82
-
83
- val screenWidth = (metrics.widthPixels / metrics.density).toDouble()
84
- val screenHeight = (metrics.heightPixels / metrics.density).toDouble()
85
-
86
- return Dimensions(screenWidth, screenHeight)
87
- }
88
- else -> {
89
- val displayMetrics = reactContext.resources.displayMetrics
90
-
91
- reactContext.currentActivity?.windowManager?.currentWindowMetrics?.bounds?.let {
92
- val boundsWidth = (it.width() / displayMetrics.density).toDouble()
93
- val boundsHeight = (it.height() / displayMetrics.density).toDouble()
94
-
95
- return Dimensions(boundsWidth, boundsHeight)
96
- } ?: run {
97
- val screenWidth = (displayMetrics.widthPixels / displayMetrics.density).toDouble()
98
- val screenHeight = (displayMetrics.heightPixels / displayMetrics.density).toDouble()
99
-
100
- return Dimensions(screenWidth, screenHeight)
101
- }
102
- }
103
- }
104
- }
105
-
106
- override fun getStatusBarDimensions(): Dimensions {
107
- // todo
108
- return Dimensions(0.0, 0.0)
109
- }
110
-
111
- override fun getNavigationBarDimensions(): Dimensions {
112
- // todo
113
- return Dimensions(0.0, 0.0)
114
- }
115
-
116
- override fun getPrefersRtlDirection(): Boolean {
117
- // forced by React Native
118
- val sharedPrefs = reactContext.getSharedPreferences(
119
- "com.facebook.react.modules.i18nmanager.I18nUtil",
120
- Context.MODE_PRIVATE
121
- )
122
- val hasForcedRtl = sharedPrefs.getBoolean("RCTI18nUtil_forceRTL", false)
123
- // user preferences
124
- val isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
125
-
126
- return hasForcedRtl || isRtl
127
- }
128
-
129
- override fun setRootViewBackgroundColor(color: Double) {
130
- // todo
131
- }
132
-
133
- override fun setNavigationBarBackgroundColor(color: Double) {
134
- // todo
135
- }
136
-
137
- override fun setNavigationBarHidden(isHidden: Boolean) {
138
- // todo
139
- }
140
-
141
- override fun setStatusBarHidden(isHidden: Boolean) {
142
- // todo
143
- }
144
-
145
- override fun setStatusBarBackgroundColor(color: Double) {
146
- // todo
147
- }
148
-
149
- override fun setImmersiveMode(isEnabled: Boolean) {
150
- this.setStatusBarHidden(isEnabled)
151
- this.setNavigationBarHidden(isEnabled)
152
- }
153
-
154
- override fun getMiniRuntime(): UnistylesNativeMiniRuntime {
155
- return UnistylesNativeMiniRuntime(
156
- colorScheme = this.getColorScheme(),
157
- screen = this.getScreenDimensions(),
158
- contentSizeCategory = this.getContentSizeCategory(),
159
- insets = this.getInsets(),
160
- pixelRatio = this.getPixelRatio(),
161
- fontScale = this.getFontScale(),
162
- rtl = this.getPrefersRtlDirection(),
163
- statusBar = this.getStatusBarDimensions(),
164
- navigationBar = this.getNavigationBarDimensions(),
165
- isPortrait = this.getOrientation() == Orientation.PORTRAIT,
166
- isLandscape = this.getOrientation() == Orientation.LANDSCAPE
167
- )
168
- }
169
-
170
- override fun registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>) -> Unit) {
171
- // todo
172
- }
173
-
174
- override fun registerImeListener(callback: () -> Unit) {
175
- // todo
176
- }
177
-
178
- override fun unregisterPlatformListeners() {
179
- // todo
180
- }
181
-
182
- override val memorySize: Long
183
- get() = 0
184
- }
@@ -1,8 +0,0 @@
1
- import com.facebook.react.bridge.ReactApplicationContext
2
- import com.margelo.nitro.unistyles.Insets
3
-
4
- class UnistylesModuleInsets(private val reactContext: ReactApplicationContext) {
5
- fun getInsets(): Insets {
6
- return Insets(top = 0.0, bottom = 0.0, left = 0.0, right = 0.0, ime = 0.0)
7
- }
8
- }