react-native-navigation 7.33.0-alpha.2 → 7.33.0-alpha.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.
@@ -2,6 +2,7 @@ package com.reactnativenavigation.views.stack.topbar.titlebar
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.content.Context
5
+ import android.view.View
5
6
  import android.view.ViewGroup
6
7
  import androidx.core.view.children
7
8
  import com.facebook.react.ReactInstanceManager
@@ -11,22 +12,44 @@ import com.reactnativenavigation.react.ReactView
11
12
  class TitleBarReactView(context: Context?, reactInstanceManager: ReactInstanceManager?, componentId: String?,
12
13
  componentName: String?) : ReactView(context, reactInstanceManager, componentId, componentName) {
13
14
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
14
- super.onMeasure(interceptReactRootViewMeasureSpec(widthMeasureSpec), heightMeasureSpec)
15
+ super.onMeasure(interceptReactRootViewMeasureSpecWidth(widthMeasureSpec), interceptReactRootViewMeasureSpecHeight(heightMeasureSpec))
15
16
  }
16
17
 
17
- private fun interceptReactRootViewMeasureSpec(widthMeasureSpec: Int): Int {
18
+ private fun interceptReactRootViewMeasureSpecWidth(widthMeasureSpec: Int): Int {
18
19
  // This is a HACK.
19
20
  // ReactRootView has problematic behavior when setting width to WRAP_CONTENT,
20
21
  // It's causing infinite measurements, that hung up the UI.
21
22
  // Intercepting largest child by width, and use its width as (parent) ReactRootView width fixed that.
22
23
  // See for more details https://github.com/wix/react-native-navigation/pull/7096
23
- var measuredWidth = 0
24
+ val measuredWidth = this.getRootViewFirstChild()?.width
24
25
 
26
+ return if (measuredWidth != null) MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY) else
27
+ widthMeasureSpec
28
+ }
29
+
30
+ private fun interceptReactRootViewMeasureSpecHeight(heightMeasureSpec: Int): Int {
31
+ // This is a HACK.
32
+ // ReactRootView has problematic behavior when setting width to WRAP_CONTENT,
33
+ // It's causing infinite measurements, that hung up the UI.
34
+ // Intercepting largest child by height, and use its height as (parent) ReactRootView width fixed that.
35
+ // See for more details https://github.com/wix/react-native-navigation/pull/7096
36
+ val measuredHeight = this.getRootViewFirstChild()?.height
37
+
38
+ return if (measuredHeight != null) MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY) else
39
+ heightMeasureSpec
40
+ }
41
+
42
+ private fun getRootViewFirstChild(): View? {
25
43
  if (rootViewGroup.children.count() > 0) {
26
- measuredWidth = (((rootViewGroup.children.first() as ViewGroup).children.first() as ViewGroup).children.first() as ViewGroup).width
44
+ return null
27
45
  }
28
-
29
- return if (measuredWidth > 0) MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY) else
30
- widthMeasureSpec
46
+ var rootViewGroupFirstChild: View = rootViewGroup.children.first()
47
+ while(true) try {
48
+ (rootViewGroupFirstChild as ViewGroup).children.first().also { rootViewGroupFirstChild = it }
49
+ } catch (e: Exception) {
50
+ //
51
+ }
52
+ @Suppress("UNREACHABLE_CODE")
53
+ return rootViewGroupFirstChild
31
54
  }
32
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-navigation",
3
- "version": "7.33.0-alpha.2",
3
+ "version": "7.33.0-alpha.4",
4
4
  "description": "React Native Navigation - truly native navigation for iOS and Android",
5
5
  "license": "MIT",
6
6
  "nativePackage": true,