react-native-unistyles 2.5.2 → 2.5.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -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(
|
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(
|
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
|
-
|
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
|
-
|
236
|
-
|
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
|