Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,21 @@ class Screen(

if (usesFormSheetPresentation()) {
if (isSheetFitToContents()) {
sheetBehavior?.useSingleDetent(height)
sheetBehavior?.useSingleDetent(height, screen = this)
}

if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// On old architecture we delay enter transition in order to wait for initial frame.
shouldTriggerPostponedTransitionAfterLayout = true
}

println("onContentWrapperLayout $height, ${sheetBehavior?.maxHeight}, ${sheetBehavior?.peekHeight}")
if (height > (sheetBehavior?.peekHeight ?: Int.MAX_VALUE)) {
val parent = parentAsViewGroup()
if (parent != null && !parent.isInLayout) {
// There are reported cases (irreproducible) when Screen is not laid out after
// maxHeight is set on behaviour.
println("request")
parent.requestLayout()
}
}
Expand Down Expand Up @@ -200,6 +205,11 @@ class Screen(
// glitchy. *This seems to not be needed on Fabric*.
triggerPostponedEnterTransitionIfNeeded()
}
println("onBottomSheetBehaviorDidLayout $height, ${sheetBehavior?.maxHeight}, ${sheetBehavior?.peekHeight}")
if (sheetBehavior!!.peekHeight < sheetBehavior!!.maxHeight) {
sheetBehavior?.setPeekHeight(height, true)
}
sheetBehavior?.isDraggable = true
}

private fun triggerPostponedEnterTransitionIfNeeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,53 @@ package com.swmansion.rnscreens.bottomsheet

import android.view.View
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
import com.swmansion.rnscreens.Screen
import com.swmansion.rnscreens.ext.parentAsViewGroup
import kotlin.math.max

internal fun <T : View> BottomSheetBehavior<T>.useSingleDetent(
height: Int? = null,
forceExpandedState: Boolean = true,
screen: Screen? = null
): BottomSheetBehavior<T> {
this.skipCollapsed = true
this.skipCollapsed = false
this.isFitToContents = true
if (forceExpandedState) {
this.state = BottomSheetBehavior.STATE_EXPANDED
this.state = BottomSheetBehavior.STATE_COLLAPSED
}
isDraggable = false
println("useSingleDetent $height $maxHeight $peekHeight")
height?.let {
maxHeight = height
this.state = BottomSheetBehavior.STATE_COLLAPSED
if (height > maxHeight) {
maxHeight = height
} else if (height < maxHeight) {
println("height <= maxHeight, adding callback")
addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
println(newState)
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
removeBottomSheetCallback(this)
maxHeight = height
screen?.apply {
val parent = parentAsViewGroup()
if (parent != null && !parent.isInLayout) {
// There are reported cases (irreproducible) when Screen is not laid out after
// maxHeight is set on behaviour.
println("request inner")
parent.requestLayout()
}
}
}
}

override fun onSlide(bottomSheet: View, slideOffset: Float) {
}

})
setPeekHeight(height, true)
}
}
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object SheetUtils {
1 ->
when (state) {
STATE_HIDDEN -> -1
STATE_EXPANDED -> 0
STATE_COLLAPSED, STATE_EXPANDED -> 0
else -> throw IllegalArgumentException("[RNScreens] Invalid state $state for detentCount $detentCount")
}

Expand Down
Loading