react-native-unistyles 2.5.2 → 2.5.4

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.
@@ -19,7 +19,7 @@ class UnistylesInsets(private val reactApplicationContext: ReactApplicationConte
19
19
 
20
20
  private fun getCurrentInsets(): Insets {
21
21
  val baseInsets = this.getBaseInsets()
22
- val statusBarTranslucent = this.hasTranslucentStatusBar(baseInsets) ?: return baseInsets
22
+ val statusBarTranslucent = this.hasTranslucentStatusBar() ?: return baseInsets
23
23
  val window = reactApplicationContext.currentActivity?.window ?: return baseInsets
24
24
  val shouldModifyLandscapeInsets = this.forceLandscapeInsets(baseInsets, window)
25
25
 
@@ -48,7 +48,7 @@ class UnistylesInsets(private val reactApplicationContext: ReactApplicationConte
48
48
 
49
49
  // available from Android 6.0
50
50
  val window = reactApplicationContext.currentActivity?.window ?: return Insets(0, 0, 0, 0)
51
- val systemInsets = window.decorView.rootWindowInsets
51
+ val systemInsets = window.decorView.rootWindowInsets ?: return Insets(0, 0, 0, 0)
52
52
 
53
53
  val top = (systemInsets.systemWindowInsetTop / density).roundToInt()
54
54
  val bottom = (systemInsets.systemWindowInsetBottom / density).roundToInt()
@@ -59,7 +59,7 @@ class UnistylesInsets(private val reactApplicationContext: ReactApplicationConte
59
59
  }
60
60
 
61
61
  // this function helps to detect statusBar translucent, as React Native is using weird API instead of windows flags
62
- private fun hasTranslucentStatusBar(baseInsets: Insets): Boolean? {
62
+ private fun hasTranslucentStatusBar(): Boolean? {
63
63
  val window = reactApplicationContext.currentActivity?.window ?: return null
64
64
  val contentView = window.decorView.findViewById<View>(android.R.id.content) ?: return null
65
65
  val decorViewLocation = IntArray(2)
@@ -52,6 +52,7 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
52
52
  //region Lifecycle
53
53
  init {
54
54
  reactApplicationContext.registerReceiver(configurationChangeReceiver, IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED))
55
+ reactApplicationContext.addLifecycleEventListener(this)
55
56
  }
56
57
 
57
58
  private fun setupLayoutListener() {
@@ -59,14 +60,21 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
59
60
  activity.window.decorView.rootView.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
60
61
  }
61
62
 
62
- @Deprecated("Deprecated in Java")
63
- override fun onCatalystInstanceDestroy() {
63
+ private fun stopLayoutListener() {
64
64
  val activity = currentActivity ?: return
65
-
66
65
  activity.window.decorView.rootView.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
66
+ }
67
+
68
+ @Deprecated("Deprecated in Java")
69
+ override fun onCatalystInstanceDestroy() {
70
+ this.stopLayoutListener()
67
71
  reactApplicationContext.unregisterReceiver(configurationChangeReceiver)
68
72
  runnable?.let { drawHandler.removeCallbacks(it) }
69
- this.nativeDestroy()
73
+ reactApplicationContext.removeLifecycleEventListener(this)
74
+
75
+ if (this.isCxxReady) {
76
+ this.nativeDestroy()
77
+ }
70
78
  }
71
79
 
72
80
  //endregion
@@ -118,7 +126,6 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
118
126
  val config = platform.getConfig()
119
127
  val layoutConfig = platform.getLayoutConfig()
120
128
 
121
- this.setupLayoutListener()
122
129
  this.reactApplicationContext.javaScriptContextHolder?.let {
123
130
  this.nativeInstall(
124
131
  it.get(),
@@ -138,7 +145,9 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
138
145
 
139
146
  false
140
147
  } catch (e: Exception) {
141
- false
148
+ this.isCxxReady = false
149
+
150
+ return false
142
151
  }
143
152
  }
144
153
 
@@ -232,11 +241,16 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
232
241
  @ReactMethod
233
242
  fun removeListeners(count: Double) = Unit
234
243
  override fun onHostResume() {
235
- this.onConfigChange()
236
- this.onLayoutConfigChange()
244
+ if (isCxxReady) {
245
+ this.onConfigChange()
246
+ }
247
+
248
+ this.setupLayoutListener()
237
249
  }
238
250
 
239
- override fun onHostPause() {}
251
+ override fun onHostPause() {
252
+ this.stopLayoutListener()
253
+ }
240
254
 
241
255
  override fun onHostDestroy() {}
242
256
  //endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",