diff --git a/android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetBehaviorExt.kt b/android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetBehaviorExt.kt index 5e1d1b5683..dff322526e 100644 --- a/android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetBehaviorExt.kt +++ b/android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetBehaviorExt.kt @@ -4,7 +4,7 @@ import android.view.View import com.google.android.material.bottomsheet.BottomSheetBehavior internal fun BottomSheetBehavior.useSingleDetent( - height: Int? = null, + maxAllowedHeight: Int? = null, forceExpandedState: Boolean = true, ): BottomSheetBehavior { this.skipCollapsed = true @@ -12,8 +12,8 @@ internal fun BottomSheetBehavior.useSingleDetent( if (forceExpandedState) { this.state = BottomSheetBehavior.STATE_EXPANDED } - height?.let { - maxHeight = height + maxAllowedHeight?.let { + maxHeight = maxAllowedHeight } return this } @@ -21,19 +21,20 @@ internal fun BottomSheetBehavior.useSingleDetent( internal fun BottomSheetBehavior.useTwoDetents( @BottomSheetBehavior.StableState state: Int? = null, firstHeight: Int? = null, - secondHeight: Int? = null, + maxAllowedHeight: Int? = null, ): BottomSheetBehavior { skipCollapsed = false isFitToContents = true state?.let { this.state = state } firstHeight?.let { peekHeight = firstHeight } - secondHeight?.let { maxHeight = secondHeight } + maxAllowedHeight?.let { maxHeight = maxAllowedHeight } return this } internal fun BottomSheetBehavior.useThreeDetents( @BottomSheetBehavior.StableState state: Int? = null, firstHeight: Int? = null, + maxAllowedHeight: Int? = null, halfExpandedRatio: Float? = null, expandedOffsetFromTop: Int? = null, ): BottomSheetBehavior { @@ -43,5 +44,6 @@ internal fun BottomSheetBehavior.useThreeDetents( firstHeight?.let { this.peekHeight = firstHeight } halfExpandedRatio?.let { this.halfExpandedRatio = halfExpandedRatio } expandedOffsetFromTop?.let { this.expandedOffset = expandedOffsetFromTop } + maxAllowedHeight?.let { maxHeight = maxAllowedHeight } return this } diff --git a/android/src/main/java/com/swmansion/rnscreens/bottomsheet/SheetDelegate.kt b/android/src/main/java/com/swmansion/rnscreens/bottomsheet/SheetDelegate.kt index df9b9d6aff..68f6cbf0b4 100644 --- a/android/src/main/java/com/swmansion/rnscreens/bottomsheet/SheetDelegate.kt +++ b/android/src/main/java/com/swmansion/rnscreens/bottomsheet/SheetDelegate.kt @@ -152,9 +152,9 @@ class SheetDelegate( } } } else { - (screen.sheetDetents.first() * containerHeight).toInt() + (screen.sheetDetents[0] * containerHeight).toInt() } - useSingleDetent(height = height) + useSingleDetent(maxAllowedHeight = height) } 2 -> @@ -165,7 +165,7 @@ class SheetDelegate( screen.sheetDetents.count(), ), firstHeight = (screen.sheetDetents[0] * containerHeight).toInt(), - secondHeight = (screen.sheetDetents[1] * containerHeight).toInt(), + maxAllowedHeight = (screen.sheetDetents[1] * containerHeight).toInt(), ) 3 -> @@ -177,6 +177,7 @@ class SheetDelegate( ), firstHeight = (screen.sheetDetents[0] * containerHeight).toInt(), halfExpandedRatio = (screen.sheetDetents[1] / screen.sheetDetents[2]).toFloat(), + maxAllowedHeight = (screen.sheetDetents[2] * containerHeight).toInt(), expandedOffsetFromTop = ((1 - screen.sheetDetents[2]) * containerHeight).toInt(), ) @@ -246,21 +247,22 @@ class SheetDelegate( } } } else { - (screen.sheetDetents.first() * containerHeight).toInt() + (screen.sheetDetents[0] * containerHeight).toInt() } - useSingleDetent(height = height, forceExpandedState = false) + useSingleDetent(maxAllowedHeight = height, forceExpandedState = false) } 2 -> behavior.useTwoDetents( firstHeight = (screen.sheetDetents[0] * containerHeight).toInt(), - secondHeight = (screen.sheetDetents[1] * containerHeight).toInt(), + maxAllowedHeight = (screen.sheetDetents[1] * containerHeight).toInt(), ) 3 -> behavior.useThreeDetents( firstHeight = (screen.sheetDetents[0] * containerHeight).toInt(), halfExpandedRatio = (screen.sheetDetents[1] / screen.sheetDetents[2]).toFloat(), + maxAllowedHeight = (screen.sheetDetents[2] * containerHeight).toInt(), expandedOffsetFromTop = ((1 - screen.sheetDetents[2]) * containerHeight).toInt(), ) diff --git a/apps/src/tests/Test3346.tsx b/apps/src/tests/Test3346.tsx new file mode 100644 index 0000000000..7d8d46616f --- /dev/null +++ b/apps/src/tests/Test3346.tsx @@ -0,0 +1,153 @@ +import React from 'react'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import type { + NativeStackNavigationOptions, + NativeStackNavigationProp, +} from '@react-navigation/native-stack'; +import { NavigationContainer } from '@react-navigation/native'; +import { Button, Text, View } from 'react-native'; +import PressableWithFeedback from '../shared/PressableWithFeedback'; +import Colors from '../shared/styling/Colors'; + +type StackParamList = { + Main: undefined; + FormSheetWithSmallDetent: undefined; + FormSheetWithMediumDetent: undefined; + FormSheetWithLargeDetent: undefined; + FormSheetWithTwoDetents: undefined; + FormSheetWithThreeDetents: undefined; + FormSheetWithMaxDetent: undefined; +}; + +type MainProps = { + navigation: NativeStackNavigationProp; +}; + +const Stack = createNativeStackNavigator(); + +const Main = ({ navigation }: MainProps) => { + return ( + +