Skip to content

Commit

Permalink
MEASURE the coordinator layout before calling layout...
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Dec 16, 2024
1 parent aaecd0d commit 4d66653
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Screen(
* `fitToContents` for formSheets, as this is first entry point where we can acquire
* height of our content.
*/
override fun onLayoutCallback(
override fun onContentWrapperLayout(
changed: Boolean,
left: Int,
top: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScreenContentWrapper(
internal var delegate: OnLayoutCallback? = null

interface OnLayoutCallback {
fun onLayoutCallback(
fun onContentWrapperLayout(
changed: Boolean,
left: Int,
top: Int,
Expand All @@ -35,6 +35,6 @@ class ScreenContentWrapper(
bottom: Int,
) {
Log.i("ScreenContentWrapper", "received layout: ${bottom - top}, ${right - left}")
delegate?.onLayoutCallback(changed, left, top, right, bottom)
delegate?.onContentWrapperLayout(changed, left, top, right, bottom)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class ScreenStackFragment :
dimmingDelegate.value.onBehaviourAttached(screen, screen.sheetBehavior!!)

val container = screen.container!!
coordinatorLayout.measure(View.MeasureSpec.makeMeasureSpec(container.width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(container.height, View.MeasureSpec.EXACTLY))
coordinatorLayout.layout(0, 0, container.width, container.height)
//
// enterTransition =
Expand Down Expand Up @@ -391,7 +392,16 @@ class ScreenStackFragment :
animatedValue?.let { dimmingDelegate.value.dimmingView.alpha = it }
}
}
val customEvaluator = CustomEvaluator({ if (screen.height != 0) screen.height.toFloat() else 0f }, { 0f })
val startValueCallback = {
if (screen.height != 0) {
Log.i("CB", "[StartValue] ${screen.height.toFloat()}")
screen.height.toFloat()
} else {
Log.i("CB", "[StartValue] 0f")
0f
}
}
val customEvaluator = CustomEvaluator(startValueCallback, { 0f })
val slideAnimator = ValueAnimator.ofObject(customEvaluator, screen.height.toFloat(), 0f).apply {
addUpdateListener { anim ->
val animatedValue = anim.animatedValue as? Float
Expand Down Expand Up @@ -809,7 +819,7 @@ class ScreenStackFragment :
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
Log.i(TAG, "[Coordinator] onLayout")
Log.i(TAG, "[Coordinator] onLayout ${b - t}, ${r - l}")
super.onLayout(changed, l, t, r, b)
}

Expand Down

0 comments on commit 4d66653

Please sign in to comment.