react-native-navigation 7.33.0-alpha.7 → 7.33.0-alpha.8
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.
|
@@ -3,17 +3,28 @@ package com.reactnativenavigation.views.stack.topbar.titlebar
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.util.Log
|
|
6
|
-
import android.view.View
|
|
7
6
|
import android.view.ViewGroup
|
|
8
7
|
import androidx.core.view.children
|
|
9
8
|
import com.facebook.react.ReactInstanceManager
|
|
10
9
|
import com.reactnativenavigation.react.ReactView
|
|
10
|
+
import com.reactnativenavigation.BuildConfig
|
|
11
11
|
|
|
12
12
|
@SuppressLint("ViewConstructor")
|
|
13
13
|
class TitleBarReactView(context: Context?, reactInstanceManager: ReactInstanceManager?, componentId: String?,
|
|
14
14
|
componentName: String?) : ReactView(context, reactInstanceManager, componentId, componentName) {
|
|
15
|
+
|
|
16
|
+
private var currentLeft = Int.MAX_VALUE
|
|
17
|
+
private var currentRight = 0
|
|
18
|
+
private var currentTop = Int.MAX_VALUE
|
|
19
|
+
private var currentBottom = 0
|
|
20
|
+
private var garbageViews = false
|
|
21
|
+
|
|
15
22
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
16
|
-
|
|
23
|
+
if (currentRight == 0) {
|
|
24
|
+
findSize(rootViewGroup)
|
|
25
|
+
}
|
|
26
|
+
super.onMeasure(interceptReactRootViewMeasureSpecWidth(widthMeasureSpec),
|
|
27
|
+
interceptReactRootViewMeasureSpecHeight(heightMeasureSpec))
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
private fun interceptReactRootViewMeasureSpecWidth(widthMeasureSpec: Int): Int {
|
|
@@ -22,9 +33,8 @@ class TitleBarReactView(context: Context?, reactInstanceManager: ReactInstanceMa
|
|
|
22
33
|
// It's causing infinite measurements, that hung up the UI.
|
|
23
34
|
// Intercepting largest child by width, and use its width as (parent) ReactRootView width fixed that.
|
|
24
35
|
// See for more details https://github.com/wix/react-native-navigation/pull/7096
|
|
25
|
-
val
|
|
26
|
-
|
|
27
|
-
return if (measuredWidth != null) MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY) else
|
|
36
|
+
val width = currentRight - currentLeft
|
|
37
|
+
return if (width > 0) MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY) else
|
|
28
38
|
widthMeasureSpec
|
|
29
39
|
}
|
|
30
40
|
|
|
@@ -34,26 +44,57 @@ class TitleBarReactView(context: Context?, reactInstanceManager: ReactInstanceMa
|
|
|
34
44
|
// It's causing infinite measurements, that hung up the UI.
|
|
35
45
|
// Intercepting largest child by height, and use its height as (parent) ReactRootView width fixed that.
|
|
36
46
|
// See for more details https://github.com/wix/react-native-navigation/pull/7096
|
|
37
|
-
val measuredHeight = this.getLastRootViewChild()?.height
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
val height = currentBottom - currentTop
|
|
49
|
+
return if (height > 0) MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) else
|
|
40
50
|
heightMeasureSpec
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
private fun
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
53
|
+
private fun findSize(viewGroup: ViewGroup) {
|
|
54
|
+
if (garbageViews) {
|
|
55
|
+
return
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
|
|
58
|
+
for (child in viewGroup.children) {
|
|
59
|
+
if (child.isShown) {
|
|
60
|
+
if (child is ViewGroup) {
|
|
61
|
+
findSize(child)
|
|
62
|
+
} else {
|
|
63
|
+
val location = IntArray(2)
|
|
64
|
+
child.getLocationOnScreen(location)
|
|
65
|
+
val childLeft = location[0]
|
|
66
|
+
val childRight = childLeft + child.measuredWidth
|
|
67
|
+
val childTop = location[1]
|
|
68
|
+
val childBottom = childTop + child.measuredHeight
|
|
69
|
+
|
|
70
|
+
if (childTop >= 50 || !BuildConfig.DEBUG) { // To filter garbage views, such as debug warning messages
|
|
71
|
+
currentLeft = currentLeft.coerceAtMost(childLeft)
|
|
72
|
+
currentRight = currentRight.coerceAtLeast(childRight)
|
|
73
|
+
currentTop = currentTop.coerceAtMost(childTop)
|
|
74
|
+
currentBottom = currentBottom.coerceAtLeast(childBottom)
|
|
75
|
+
|
|
76
|
+
Log.d("TitleBarReactView", "current ViewGroup = $viewGroup")
|
|
77
|
+
Log.d("TitleBarReactView", "child.measuredWidth = ${child.measuredWidth}")
|
|
78
|
+
Log.d("TitleBarReactView", "child.measuredHeight = ${child.measuredHeight}")
|
|
79
|
+
Log.d("TitleBarReactView", "currentLeft = $currentLeft")
|
|
80
|
+
Log.d("TitleBarReactView", "currentRight = $currentRight")
|
|
81
|
+
Log.d("TitleBarReactView", "currentWidth = ${currentRight - currentLeft}")
|
|
82
|
+
Log.d("TitleBarReactView", "currentTop = $currentTop")
|
|
83
|
+
Log.d("TitleBarReactView", "currentBottom = $currentBottom")
|
|
84
|
+
Log.d("TitleBarReactView", "currentHeight = ${currentBottom - currentTop}")
|
|
85
|
+
Log.d("TitleBarReactView", "---------------------------------------------")
|
|
86
|
+
} else {
|
|
87
|
+
|
|
88
|
+
Log.d("TitleBarReactView", "current ViewGroup (garbage) = $viewGroup")
|
|
89
|
+
Log.d("TitleBarReactView", "child (garbage) = ${child.toString()}")
|
|
90
|
+
Log.d("TitleBarReactView", "child.type (garbage) = ${child.javaClass.name}")
|
|
91
|
+
Log.d("TitleBarReactView", "child.id (garbage) = ${child.id}")
|
|
92
|
+
|
|
93
|
+
garbageViews = true
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
55
98
|
}
|
|
56
|
-
@Suppress("UNREACHABLE_CODE")
|
|
57
|
-
return rootViewGroupLastChild
|
|
58
99
|
}
|
|
59
|
-
}
|
|
100
|
+
}
|