react-native-unistyles 2.5.2 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
 
@@ -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,13 +60,19 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
59
60
  activity.window.decorView.rootView.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
60
61
  }
61
62
 
63
+ private fun stopLayoutListener() {
64
+ val activity = currentActivity ?: return
65
+ activity.window.decorView.rootView.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
66
+ }
67
+
62
68
  @Deprecated("Deprecated in Java")
63
69
  override fun onCatalystInstanceDestroy() {
64
70
  val activity = currentActivity ?: return
65
71
 
66
- activity.window.decorView.rootView.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
72
+ this.stopLayoutListener()
67
73
  reactApplicationContext.unregisterReceiver(configurationChangeReceiver)
68
74
  runnable?.let { drawHandler.removeCallbacks(it) }
75
+ reactApplicationContext.removeLifecycleEventListener(this)
69
76
  this.nativeDestroy()
70
77
  }
71
78
 
@@ -118,7 +125,6 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
118
125
  val config = platform.getConfig()
119
126
  val layoutConfig = platform.getLayoutConfig()
120
127
 
121
- this.setupLayoutListener()
122
128
  this.reactApplicationContext.javaScriptContextHolder?.let {
123
129
  this.nativeInstall(
124
130
  it.get(),
@@ -232,11 +238,17 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
232
238
  @ReactMethod
233
239
  fun removeListeners(count: Double) = Unit
234
240
  override fun onHostResume() {
235
- this.onConfigChange()
236
- this.onLayoutConfigChange()
241
+ if (isCxxReady) {
242
+ this.onConfigChange()
243
+ this.onLayoutConfigChange()
244
+ }
245
+
246
+ this.setupLayoutListener()
237
247
  }
238
248
 
239
- override fun onHostPause() {}
249
+ override fun onHostPause() {
250
+ this.stopLayoutListener()
251
+ }
240
252
 
241
253
  override fun onHostDestroy() {}
242
254
  //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.3",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",