Skip to content
Merged
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
4 changes: 4 additions & 0 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.google.android.material.shape.ShapeAppearanceModel
import com.swmansion.rnscreens.events.HeaderHeightChangeEvent
import com.swmansion.rnscreens.events.SheetDetentChangedEvent
import com.swmansion.rnscreens.ext.isInsideScrollViewWithRemoveClippedSubviews
import java.lang.ref.WeakReference

@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
class Screen(
Expand All @@ -36,6 +37,8 @@ class Screen(
val fragment: Fragment?
get() = fragmentWrapper?.fragment

var contentWrapper = WeakReference<ScreenContentWrapper>(null)

val sheetBehavior: BottomSheetBehavior<Screen>?
get() = (layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? BottomSheetBehavior<Screen>

Expand Down Expand Up @@ -128,6 +131,7 @@ class Screen(

fun registerLayoutCallbackForWrapper(wrapper: ScreenContentWrapper) {
wrapper.delegate = this
this.contentWrapper = WeakReference(wrapper)
}

override fun dispatchSaveInstanceState(container: SparseArray<Parcelable>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,18 @@ class ScreenStackFragment :
) {
if (SheetUtils.isStateStable(newState)) {
lastStableState = newState
screen.notifySheetDetentChange(SheetUtils.detentIndexFromSheetState(lastStableState, screen.sheetDetents.count()), true)
screen.notifySheetDetentChange(
SheetUtils.detentIndexFromSheetState(
lastStableState,
screen.sheetDetents.count()
), true
)
} else if (newState == BottomSheetBehavior.STATE_DRAGGING) {
screen.notifySheetDetentChange(
SheetUtils.detentIndexFromSheetState(lastStableState, screen.sheetDetents.count()),
SheetUtils.detentIndexFromSheetState(
lastStableState,
screen.sheetDetents.count()
),
false,
)
}
Expand Down Expand Up @@ -340,13 +348,23 @@ class ScreenStackFragment :
return when (keyboardState) {
is KeyboardNotVisible -> {
when (screen.sheetDetents.count()) {
1 ->
1 -> if (screen.sheetDetents.first() == Screen.SHEET_FIT_TO_CONTENTS) {
behavior.apply {
state = BottomSheetBehavior.STATE_EXPANDED
screen.contentWrapper.get()?.let {
maxHeight = it.height
}
skipCollapsed = true
isFitToContents = true
}
} else {
behavior.apply {
state = BottomSheetBehavior.STATE_EXPANDED
skipCollapsed = true
isFitToContents = true
maxHeight = (screen.sheetDetents.first() * containerHeight).toInt()
}
}

2 ->
behavior.apply {
Expand All @@ -371,7 +389,8 @@ class ScreenStackFragment :
skipCollapsed = false
isFitToContents = false
peekHeight = (screen.sheetDetents[0] * containerHeight).toInt()
expandedOffset = ((1 - screen.sheetDetents[2]) * containerHeight).toInt()
expandedOffset =
((1 - screen.sheetDetents[2]) * containerHeight).toInt()
halfExpandedRatio =
(screen.sheetDetents[1] / screen.sheetDetents[2]).toFloat()
}
Expand Down Expand Up @@ -450,7 +469,8 @@ class ScreenStackFragment :
skipCollapsed = false
isFitToContents = false
peekHeight = (screen.sheetDetents[0] * containerHeight).toInt()
expandedOffset = ((1 - screen.sheetDetents[2]) * containerHeight).toInt()
expandedOffset =
((1 - screen.sheetDetents[2]) * containerHeight).toInt()
halfExpandedRatio =
(screen.sheetDetents[1] / screen.sheetDetents[2]).toFloat()
}
Expand Down Expand Up @@ -575,7 +595,8 @@ class ScreenStackFragment :
// ) : CoordinatorLayout(context), ReactCompoundViewGroup, ReactHitSlopView {
) : CoordinatorLayout(context),
ReactPointerEventsView {
override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets = super.onApplyWindowInsets(insets)
override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets =
super.onApplyWindowInsets(insets)

private val animationListener: Animation.AnimationListener =
object : Animation.AnimationListener {
Expand Down
Loading