react-native-unistyles 2.5.1 → 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(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)
@@ -21,7 +21,7 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
21
21
  private var runnable: Runnable? = null
22
22
 
23
23
  private var isCxxReady: Boolean = false
24
- private val platform: Platform = Platform(reactContext)
24
+ private lateinit var platform: Platform
25
25
  private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
26
26
  if (this.isCxxReady) {
27
27
  runnable?.let { drawHandler.removeCallbacks(it) }
@@ -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
 
@@ -112,10 +119,12 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
112
119
  fun install(): Boolean {
113
120
  return try {
114
121
  System.loadLibrary("unistyles")
122
+
123
+ this.platform = Platform(reactApplicationContext)
124
+
115
125
  val config = platform.getConfig()
116
126
  val layoutConfig = platform.getLayoutConfig()
117
127
 
118
- this.setupLayoutListener()
119
128
  this.reactApplicationContext.javaScriptContextHolder?.let {
120
129
  this.nativeInstall(
121
130
  it.get(),
@@ -229,11 +238,17 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
229
238
  @ReactMethod
230
239
  fun removeListeners(count: Double) = Unit
231
240
  override fun onHostResume() {
232
- this.onConfigChange()
233
- this.onLayoutConfigChange()
241
+ if (isCxxReady) {
242
+ this.onConfigChange()
243
+ this.onLayoutConfigChange()
244
+ }
245
+
246
+ this.setupLayoutListener()
234
247
  }
235
248
 
236
- override fun onHostPause() {}
249
+ override fun onHostPause() {
250
+ this.stopLayoutListener()
251
+ }
237
252
 
238
253
  override fun onHostDestroy() {}
239
254
  //endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -62,7 +62,7 @@
62
62
  "@release-it/conventional-changelog": "8.0.1",
63
63
  "@testing-library/react-hooks": "8.0.1",
64
64
  "@types/jest": "29.5.11",
65
- "@types/react": "18.2.46",
65
+ "@types/react": "18.2.71",
66
66
  "@typescript-eslint/eslint-plugin": "6.16.0",
67
67
  "@typescript-eslint/eslint-plugin-tslint": "6.16.0",
68
68
  "@typescript-eslint/parser": "6.16.0",
@@ -109,6 +109,9 @@
109
109
  "optional": true
110
110
  }
111
111
  },
112
+ "resolutions": {
113
+ "@types/mime": "3.0.4"
114
+ },
112
115
  "workspaces": [
113
116
  "examples/expo",
114
117
  "examples/macos",