### Offset vs Height Configuration Example Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Illustrates the equivalence between defining a state by its offset from the top and by its height. Both examples result in the same sheet position and size. ```kotlin // These are equivalent for a 500px screen: SheetValue.State1 at offset(percent = 60) // 300px from top = 200px sheet height SheetValue.State2 at height(percent = 40) // 200px sheet height = 300px from top ``` -------------------------------- ### Setup Checklist for Bottom Sheet Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md This snippet demonstrates the complete setup process for a basic bottom sheet, including defining states, creating the sheet state, initializing the scaffold state, and rendering the BottomSheetScaffold. ```kotlin enum class SheetValue { Collapsed, Expanded } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { Text("Bottom sheet") }, content = { paddingValues -> Box(Modifier.padding(paddingValues)) { Text("Main content") } } ) ``` -------------------------------- ### Minimal BottomSheetScaffold Setup in Compose Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/README.md Demonstrates the basic setup for a BottomSheetScaffold in Jetpack Compose, including state management and defining sheet content and main content areas. Ensure necessary imports are present. ```kotlin import androidx.compose.runtime.* import androidx.compose.ui.unit.dp import io.morfly.compose.bottomsheet.material3.* enum class SheetValue { Collapsed, Expanded } @Composable fun MyScreen() { val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { Text("Bottom sheet content") }, content = { paddingValues -> Text("Main content", modifier = Modifier.padding(paddingValues)) } ) } ``` -------------------------------- ### Usage Example for rememberBottomSheetScaffoldState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Demonstrates how to initialize a BottomSheetState and then use it to create a BottomSheetScaffoldState for a Material 3 BottomSheetScaffold. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) ``` -------------------------------- ### Quick Snappy Animation Usage Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Example of using a SpringSpec with high stiffness for a quick, responsive animation. ```kotlin animationSpec = SpringSpec(stiffness = 500f) ``` -------------------------------- ### Configure Scaffold Top Bar Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Optionally provide a top app bar to the scaffold. Examples show how to include a SmallTopAppBar or set it to null for no top bar. ```kotlin // With top bar topBar = { SmallTopAppBar( title = { Text("Title") }, navigationIcon = { /* ... */ } ) } // No top bar topBar = null ``` -------------------------------- ### Complete Minimal Bottom Sheet Example Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md A basic implementation of the BottomSheetScaffold in Jetpack Compose. It demonstrates how to define sheet states, content, and integrate it with the main screen content. Ensure all necessary imports are included. ```kotlin import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import io.morfly.compose.bottomsheet.material3.* enum class SheetValue { Collapsed, Expanded } @Composable fun MyApp() { val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { Column(Modifier.padding(16.dp)) { Text("Bottom Sheet Content") } }, content = { paddingValues -> Box(Modifier.padding(paddingValues)) { Text("Main Screen Content") } } ) } ``` -------------------------------- ### BottomSheetScaffold Usage Example Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Demonstrates how to use BottomSheetScaffold with custom sheet state definitions and content. Ensure you have defined your SheetValue enum and rememberBottomSheetState. ```kotlin enum class SheetValue { Collapsed, Expanded } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { Column { Text("Bottom sheet content") } }, content = { paddingValues -> Box(modifier = Modifier.padding(paddingValues)) { Text("Main screen content") } } ) ``` -------------------------------- ### Initialize BottomSheetState with Defaults Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Create a `rememberBottomSheetState` with custom `defineValues` and utilize default configurations for positional threshold, velocity threshold, and animation specification provided by `BottomSheetDefaults`. This simplifies setup by providing sensible defaults for common behaviors. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, positionalThreshold = BottomSheetDefaults.PositionalThreshold, velocityThreshold = BottomSheetDefaults.VelocityThreshold, animationSpec = BottomSheetDefaults.AnimationSpec ) ``` -------------------------------- ### Implementing confirmValueChange Logic Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md Example of implementing the `confirmValueChange` callback to conditionally allow or veto state transitions based on specific conditions, such as data loading status. ```kotlin confirmValueChange = { when (newValue) { SheetValue.Expanded -> { if (!hasLoadedData) { // Veto expansion Log.d("Sheet", "Expansion blocked - data not ready") false } else { true } } else -> true } } ``` -------------------------------- ### Configure Bottom Sheet Values Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/README.md Configure bottom sheet positions using height or offset. Options include pixel values, dp, percentages of screen height, or content height. This example shows the structure within defineValues. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { SheetValue.Collapsed at height(...) SheetValue.PartiallyExpanded at offset(...) SheetValue.Expanded at contentHeight } ) ``` -------------------------------- ### Configure Animation with SpringSpec Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Define animation behavior using AnimationSpec implementations like SpringSpec. This example configures a spring animation with specific damping ratio and stiffness. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, animationSpec = SpringSpec(dampingRatio = 0.8f, stiffness = 100f) ) ``` -------------------------------- ### Generic Type Parameter Example Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Demonstrates the usage of a generic type parameter 'T' which is typically an enum class representing sheet states. ```kotlin enum class SheetValue { Collapsed, Expanded } // T is SheetValue in rememberBottomSheetState ``` -------------------------------- ### Generic Type Flow Example Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Illustrates how generic type parameters, such as `SheetValue`, are used consistently across `BottomSheetState` and `BottomSheetScaffoldState` for type-safe state management. ```kotlin enum class SheetValue { Collapsed, Expanded } val sheetState: BottomSheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ } ) val scaffoldState: BottomSheetScaffoldState = rememberBottomSheetScaffoldState( sheetState = sheetState ) ``` -------------------------------- ### Detecting Rejected State Transitions Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md This example shows how to detect and display a message when a state transition is rejected by the `confirmValueChange` callback. It uses a `mutableStateOf` to track the last rejected value. ```kotlin val lastRejectedValue = remember { mutableStateOf(null) } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, confirmValueChange = { val allowed = isTransitionAllowed(newValue) if (!allowed) { lastRejectedValue.value = newValue } allowed } ) // Display rejection message if (lastRejectedValue.value != null) { Text("Cannot transition to ${lastRejectedValue.value}") } ``` -------------------------------- ### Dynamic Reconfiguration Confirmation Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Example of using confirmValueChange to trigger reconfiguration logic when the sheet value changes dynamically. Returns true to allow the transition. ```kotlin confirmValueChange = { newValue -> if (!previousValue.hasChanged && newValue != currentValue) { // Trigger reconfiguration refreshValues() } true } ``` -------------------------------- ### Apply Scaffold Modifier Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Chain modifiers to the scaffold's root element. Example shows filling the max size and setting a white background. ```kotlin modifier = Modifier .fillMaxSize() .background(Color.White) ``` -------------------------------- ### Define Bottom Sheet Values Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md Ensure at least two values are defined in the `defineValues` lambda to avoid an empty values error. This example shows the correct way to define collapsed and expanded states. ```kotlin defineValues = { // Empty - no values defined } ``` ```kotlin // ✓ Always define at least 2 values defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ``` -------------------------------- ### Slow Smooth Animation Usage Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Example of using a TweenSpec with a longer duration for a slow, smooth animation. ```kotlin animationSpec = TweenSpec(durationMillis = 500) ``` -------------------------------- ### Import rememberBottomSheetScaffoldState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Import the necessary function for creating the scaffold state. ```kotlin import io.morfly.compose.bottomsheet.material3.rememberBottomSheetScaffoldState ``` -------------------------------- ### AnchoredDraggableState: anchoredDrag with targetValue Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Manages drag logic with a hint for the target value, useful for guiding the drag behavior. ```kotlin suspend fun anchoredDrag( targetValue: T, dragPriority: MutatePriority = MutatePriority.Default, block: suspend AnchoredDragScope.(anchors: DraggableAnchors, targetValue: T) -> Unit ) ``` -------------------------------- ### Monitor BottomSheet Animation Status Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Track when the bottom sheet's animation starts or finishes by observing the isAnimationRunning property. ```kotlin LaunchedEffect(sheetState.draggableState.isAnimationRunning) { if (sheetState.draggableState.isAnimationRunning) { println("Animation started") } else { println("Animation finished") } } ``` -------------------------------- ### Int Range Usage for Percentages Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Demonstrates valid usage of the `offset` and `height` functions with percentage values constrained between 0 and 100. ```kotlin offset(percent = 50) // Valid: 0-100 height(percent = 75) // Valid: 0-100 ``` -------------------------------- ### Check for NaN Offset in BottomSheetState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md The `offset` property can be `Float.NaN` before the first layout. This example demonstrates how to check if the offset has been initialized before using it. ```kotlin // Check if offset is initialized if (!offset.isNaN()) { val validOffset = offset } ``` -------------------------------- ### Get Current Offset of BottomSheetState in Dp Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Retrieves the current offset of the bottom sheet in Dp. Throws an exception if the state is uninitialized. ```kotlin @ExperimentalFoundationApi fun BottomSheetState.requireOffsetDp(): Dp ``` -------------------------------- ### Configure Snackbar Host Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Specify the composable for hosting snackbars. Defaults to a standard SnackbarHost, but can be customized for styling. ```kotlin // Default snackbar host snackbarHost = { SnackbarHost(it) } // Custom snackbar styling snackbarHost = { state -> SnackbarHost( hostState = state, modifier = Modifier.padding(16.dp) ) } ``` -------------------------------- ### Define Main Screen Content Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Implement the main content of the screen, ensuring it receives and applies padding values to avoid overlap with bars. ```kotlin content = { paddingValues -> Box(modifier = Modifier.padding(paddingValues)) { // Your screen content here Column { // Avoid covering by sheet or topBar } } } ``` -------------------------------- ### Get Layout Height of BottomSheetState in Dp Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Retrieves the layout height of the bottom sheet in Dp. Throws an exception if the state is uninitialized. ```kotlin @ExperimentalFoundationApi fun BottomSheetState.requireLayoutHeightDp(): Dp ``` -------------------------------- ### Conditional Collapse Confirmation Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Example of using confirmValueChange to conditionally prevent collapse based on unsaved changes. Returns false to veto the transition. ```kotlin confirmValueChange = { when (newValue) { SheetValue.Collapsed -> { if (hasUnsavedChanges()) { false // Prevent collapse if changes pending } else { true } } SheetValue.Expanded -> { if (networkAvailable && dataLoaded()) { true } else { false } } else -> true } } ``` -------------------------------- ### Prevent Expansion Confirmation Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Example of using confirmValueChange to prevent the bottom sheet from expanding if content is not ready. Returns false to veto the transition. ```kotlin confirmValueChange = { newValue -> if (newValue == SheetValue.Expanded && !isContentReady()) { false // Don't allow expansion } else { true // Allow all other transitions } } ``` -------------------------------- ### BottomSheetDefaults Usage Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Demonstrates how to use default values from BottomSheetDefaults when remembering a BottomSheetState. Ensure the necessary import is included. ```kotlin import io.morfly.compose.bottomsheet.material3.BottomSheetDefaults val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, positionalThreshold = BottomSheetDefaults.PositionalThreshold, velocityThreshold = BottomSheetDefaults.VelocityThreshold, animationSpec = BottomSheetDefaults.AnimationSpec ) ``` -------------------------------- ### Import BottomSheetScaffold Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Import the BottomSheetScaffold component from the material3 library. ```kotlin import io.morfly.compose.bottomsheet.material3.BottomSheetScaffold ``` -------------------------------- ### Prevent Bottom Sheet Transition Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Control whether a state change is allowed by implementing the `confirmValueChange` lambda. This example prevents the sheet from expanding. ```kotlin confirmValueChange = { newValue -> newValue != SheetValue.Expanded // Prevent expansion } ``` -------------------------------- ### Integrate Bottom Sheet Scaffold Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/README.md Use the rememberBottomSheetScaffoldState to create the scaffold state and then integrate BottomSheetScaffold into your composable UI. This sets up the basic structure for your screen with a bottom sheet. ```kotlin val scaffoldState = rememberBottomSheetScaffoldState(sheetState) BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { // Bottom sheet content }, content = { // Screen content } ) ``` -------------------------------- ### Prevent New Animation While Another is Running Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md Check if an animation is currently running before starting a new one to prevent potential interruptions and CancellationExceptions. ```kotlin // Check if animation is running before starting another if (!draggableState.isAnimationRunning) { draggableState.animateTo(nextValue) } ``` -------------------------------- ### Configuration Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/MANIFEST.md Options for configuring the behavior and appearance of the bottom sheet. ```APIDOC ## BottomSheetValuesConfig ### Description A builder class for configuring the different positional values of the bottom sheet. ### Method Builder ### Endpoint N/A (Builder Class) ### Parameters - **offset(px: Int)**: Specifies a position by its exact pixel offset from the top. - **offset(dp: Dp)**: Specifies a position by its exact DP offset from the top. - **offset(percent: Float)**: Specifies a position by its percentage of the screen height from the top. - **height(px: Int)**: Specifies a position by its exact pixel height. - **height(dp: Dp)**: Specifies a position by its exact DP height. - **height(percent: Float)**: Specifies a position by its percentage of the screen height. - **contentHeight()**: Configures the sheet to automatically size to its content height. ### Request Example ```kotlin val config = BottomSheetValuesConfig.Builder() .add("collapsed", BottomSheetValue.Hidden) .add("partiallyExpanded", BottomSheetValue.PartiallyExpanded) .add("expanded", BottomSheetValue.Expanded) .build() val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { config } ) ``` ``` -------------------------------- ### Get Visible Sheet Height of BottomSheetState in Dp Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Retrieves the visible height of the bottom sheet in Dp. Throws an exception if the state is uninitialized. ```kotlin @ExperimentalFoundationApi fun BottomSheetState.requireSheetVisibleHeightDp(): Dp ``` -------------------------------- ### Configure BottomSheet sheetTonalElevation Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Apply tonal elevation to the bottom sheet for Material Design's tonal system. ```kotlin sheetTonalElevation = BottomSheetDefaults.Elevation // Default sheetTonalElevation = 6.dp sheetTonalElevation = 0.dp // No elevation ``` -------------------------------- ### Get Full Sheet Height of BottomSheetState in Dp Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Retrieves the full height of the bottom sheet in Dp. Throws an exception if the state is uninitialized. ```kotlin @ExperimentalFoundationApi fun BottomSheetState.requireSheetFullHeightDp(): Dp ``` -------------------------------- ### Spring Animation Specification Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Configures a spring-like animation for sheet transitions. Adjust dampingRatio for stiffness and stiffness for bounciness. ```kotlin animationSpec = SpringSpec( dampingRatio = 0.8f, // Stiffness of spring stiffness = 100f // How bouncy ) ``` -------------------------------- ### Basic Two-State Sheet Configuration Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Defines a bottom sheet with two distinct states: Collapsed and Expanded. Use this for simple show/hide functionality. ```kotlin enum class SheetValue { Collapsed, Expanded } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) ``` -------------------------------- ### Main Composables Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/MANIFEST.md Core composable functions for implementing the bottom sheet UI and its scaffold. ```APIDOC ## BottomSheetScaffold ### Description A full-fledged scaffold that provides a bottom sheet integrated with Material 3 design principles. ### Method Composable ### Endpoint N/A (Composable Function) ### Parameters - **sheetContent** (Composable) - Required - Content of the bottom sheet. - **scaffoldState** (BottomSheetScaffoldState) - Required - State of the scaffold. - **sheetShape** (Shape) - Optional - Shape of the bottom sheet. - **sheetContainerColor** (Color) - Optional - Background color of the bottom sheet. - **sheetContentColor** (Color) - Optional - Color of the content within the bottom sheet. - **sheetTonalElevation** (Dp) - Optional - Tonal elevation of the bottom sheet. - **sheetShadowElevation** (Dp) - Optional - Shadow elevation of the bottom sheet. - **sheetPeekHeight** (Dp) - Optional - The height of the sheet when it is collapsed. - **sheetDragDropEnabled** (Boolean) - Optional - Whether drag and drop is enabled for the sheet. - **topBar** (Composable?) - Optional - Top app bar. - **snackbarHost** (Composable?) - Optional - Snackbar host. - **containerColor** (Color) - Optional - Background color of the scaffold. - **contentColor** (Color) - Optional - Color of the content within the scaffold. - **contentWindowInsets** (WindowInsets) - Optional - Window insets for the content. - **content** (Composable) - Required - Main content of the screen. ### Response N/A (Composable renders UI) ### Request Example ```kotlin val scaffoldState = rememberBottomSheetScaffoldState() BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { /* Bottom sheet content */ }, content = { /* Main screen content */ } ) ``` ``` ```APIDOC ## rememberBottomSheetScaffoldState ### Description Creates and remembers a `BottomSheetScaffoldState` to manage the state of the `BottomSheetScaffold`. ### Method Composable Function ### Endpoint N/A (Composable Function) ### Parameters - **initialValue** (T) - Optional - The initial value of the bottom sheet state. - **animationSpec** (AnimationSpec) - Optional - The animation specification for state transitions. - **confirmValueChange** ((T) -> Boolean) - Optional - A lambda to confirm or deny value changes. ### Response - **BottomSheetScaffoldState** - The created scaffold state. ### Request Example ```kotlin val scaffoldState = rememberBottomSheetScaffoldState( initialValue = SheetValue.Expanded ) ``` ``` -------------------------------- ### Monitor BottomSheet Progress Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Log the progress of the bottom sheet's drag gesture as a percentage using snapshotFlow. ```kotlin LaunchedEffect(Unit) { snapshotFlow { sheetState.draggableState.progress } .collect { progress -> println("Progress: ${(progress * 100).toInt()}%") } } ``` -------------------------------- ### Conditional Bottom Sheet Transitions Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Prevents certain state transitions based on a condition by implementing the `confirmValueChange` lambda. This example prevents expansion if `dataReady` is false. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight }, confirmValueChange = { newValue -> if (newValue == SheetValue.Expanded && !dataReady) { false // Prevent expansion } else { true } } ) ``` -------------------------------- ### Apply Rounded Corner Shape to BottomSheet Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Use RoundedCornerShape to define the shape of the bottom sheet, specifying corner radii for top start and top end. ```kotlin BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { /* ... */ }, sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), content = { /* ... */ } ) ``` -------------------------------- ### Responsive BottomSheet State Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Configure a BottomSheet to respond to different screen sizes and content heights. Use `offset` for percentage-based positioning and `contentHeight` for automatic expansion. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { SheetValue.PartiallyExpanded at offset(percent = 60) SheetValue.Expanded at contentHeight }, positionalThreshold = { 50f }, // 50px threshold velocityThreshold = { 200f }, // 200px/s to switch animationSpec = SpringSpec(stiffness = 200f) ) ``` -------------------------------- ### Core BottomSheet Compose Imports Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Essential imports for using BottomSheetScaffold, its states, and related configuration. ```kotlin import io.morfly.compose.bottomsheet.material3.BottomSheetScaffold import io.morfly.compose.bottomsheet.material3.BottomSheetScaffoldState import io.morfly.compose.bottomsheet.material3.BottomSheetState import io.morfly.compose.bottomsheet.material3.BottomSheetValuesConfig import io.morfly.compose.bottomsheet.material3.rememberBottomSheetScaffoldState import io.morfly.compose.bottomsheet.material3.rememberBottomSheetState ``` -------------------------------- ### Get Current and Target States Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Access the current state value and the target state value of the bottom sheet using `currentValue` and `targetValue` properties of the `sheetState`. ```kotlin val currentState = sheetState.currentValue val targetState = sheetState.targetValue ``` -------------------------------- ### BottomSheetScaffold Snackbar Host Lambda Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Configure the snackbar host by providing a Composable lambda that accepts a SnackbarHostState. This lambda is responsible for rendering the SnackbarHost. ```kotlin snackbarHost = { snackbarHostState -> SnackbarHost(snackbarHostState) } ``` -------------------------------- ### Handle Empty Bottom Sheet Values Configuration Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md This code demonstrates how to use a try-catch block to handle the `IllegalArgumentException` that occurs when no bottom sheet values are provided in the configuration. ```kotlin val config = BottomSheetValuesConfig( layoutHeight = height, sheetFullHeight = fullHeight, density = density ) try { sheetState.defineValues(config) require(config.values.isNotEmpty()) { "No bottom sheet values provided!" } } catch (e: IllegalArgumentException) { Log.e("BottomSheet", "Invalid configuration", e) } ``` -------------------------------- ### Get Current Sheet Height Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Retrieve the current visible height of the bottom sheet in DP using `requireSheetVisibleHeightDp()`. This method throws an exception if the height is not yet available. ```kotlin val height = sheetState.requireSheetVisibleHeightDp() ``` -------------------------------- ### Experimental API Annotations Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/modules.md Some APIs are marked as experimental using @ExperimentalFoundationApi and @ExperimentalMaterial3Api. These APIs may change in future versions and require explicit opt-in. ```kotlin import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.material3.ExperimentalMaterial3Api @ExperimentalFoundationApi @ExperimentalMaterial3Api ``` -------------------------------- ### DraggableAnchors Interface Methods Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Provides methods to interact with defined anchor points, such as retrieving positions, checking existence, finding closest anchors, and getting min/max anchor values. ```kotlin fun positionOf(value: T): Float ``` ```kotlin fun hasAnchorFor(value: T): Boolean ``` ```kotlin fun closestAnchor(position: Float): T? ``` ```kotlin fun closestAnchor(position: Float, searchUpwards: Boolean): T? ``` ```kotlin fun minAnchor(): Float ``` ```kotlin fun maxAnchor(): Float ``` -------------------------------- ### Initialize Bottom Sheet State Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/README.md Create a BottomSheetState instance using rememberBottomSheetState. Configure initial values and their positions using height, offset, or contentHeight within the defineValues lambda. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { // Bottom sheet height is 100 dp. SheetValue.Collapsed at height(100.dp) // Bottom sheet offset is 60%, meaning it takes 40% of the screen. SheetValue.PartiallyExpanded at offset(percent = 60) // Bottom sheet height is equal to its content height. SheetValue.Expanded at contentHeight } ) ``` -------------------------------- ### Catching IllegalStateException for Dimension Access Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md Provides an example of how to catch IllegalStateException when accessing dimension properties like sheetVisibleHeight. It includes a strategy to re-schedule access using LaunchedEffect if the dimension is not yet ready. ```kotlin try { val visibleHeight = sheetState.requireSheetVisibleHeight() } catch (e: IllegalStateException) { Log.e("BottomSheet", "Dimension not ready", e) // Re-schedule access to later phase LaunchedEffect(Unit) { val visibleHeight = sheetState.requireSheetVisibleHeight() } } ``` -------------------------------- ### Convert Units with Density Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Utilize the Density interface for unit conversions between Dp and pixels. This is crucial for accurate layout calculations. ```kotlin with(density) { dp.toPx() // Convert Dp to Float pixels pixels.toDp() // Convert Float to Dp } ``` -------------------------------- ### DraggableAnchors Interface Methods Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Provides methods to interact with anchor positions for a draggable state, including getting positions, checking existence, finding closest anchors, and retrieving min/max anchor values. ```APIDOC ## DraggableAnchors Interface ### Description Structure representing the anchors of an AnchoredDraggableState. ### Methods #### positionOf ```kotlin fun positionOf(value: T): Float ``` Gets the anchor position for a value, or Float.NaN if not found. #### hasAnchorFor ```kotlin fun hasAnchorFor(value: T): Boolean ``` Checks if anchor exists for a value. #### closestAnchor ```kotlin fun closestAnchor(position: Float): T? ``` Finds the closest anchor to a position. #### closestAnchor (with direction) ```kotlin fun closestAnchor(position: Float, searchUpwards: Boolean): T? ``` Finds closest anchor in specified direction. #### minAnchor ```kotlin fun minAnchor(): Float ``` Returns the smallest anchor value. #### maxAnchor ```kotlin fun maxAnchor(): Float ``` Returns the biggest anchor value. ``` -------------------------------- ### Show Snackbar with SnackbarHostState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Use SnackbarHostState to display snackbars. It supports custom messages, action labels, durations, and dismiss actions. ```kotlin suspend fun showSnackbar( message: String, actionLabel: String? = null, duration: SnackbarDuration = SnackbarDuration.Short, withDismissAction: Boolean = false ): SnackbarResult ``` ```kotlin val scaffoldState = rememberBottomSheetScaffoldState(sheetState) LaunchedEffect(Unit) { scaffoldState.snackbarHostState.showSnackbar("Hello!") } ``` -------------------------------- ### Recommended Logging Pattern for Bottom Sheet State Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md This pattern demonstrates how to log state transitions, animation status, and offset changes for a BottomSheetScaffoldState. It uses `rememberBottomSheetState`, `LaunchedEffect`, and `snapshotFlow` to monitor various aspects of the sheet's behavior. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, confirmValueChange = { val allowed = isTransitionAllowed(it) Log.d("BottomSheet", "Transition attempt: ${currentValue} -> $it (allowed=$allowed)") allowed } ) // Monitor state changes LaunchedEffect(sheetState.currentValue) { Log.d("BottomSheet", "Current value: ${sheetState.currentValue}") } // Monitor animations LaunchedEffect(sheetState.draggableState.isAnimationRunning) { Log.d("BottomSheet", "Animation running: ${sheetState.draggableState.isAnimationRunning}") } // Monitor dimensions LaunchedEffect(Unit) { snapshotFlow { sheetState.offset } .collect { if (!it.isNaN()) { Log.d("BottomSheet", "Offset: $it") } } } ``` -------------------------------- ### Add Library Dependency Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/README.md Include this dependency in your app's build.gradle.kts file to use the library. Ensure you replace `` with the current latest version available on Maven Central. ```kotlin implementation("io.morfly.compose:advanced-bottomsheet-material3:") ``` -------------------------------- ### BottomSheetScaffold Optional Content Lambdas Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Use optional Composable lambdas for elements like the top app bar or drag handle. Provide null if these elements are not needed. ```kotlin topBar = { SmallTopAppBar(title = { Text("Title") }) }, sheetDragHandle = { BottomSheetDefaults.DragHandle() } ``` -------------------------------- ### Dynamically Reconfigure Bottom Sheet Values Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/README.md Dynamically reconfigure bottom sheet values by calling refreshValues within confirmValueChange. This allows updating the sheet's state definitions while it's in use, for example, removing a state mid-animation. ```kotlin var isInitialState by remember { mutableStateOf(true) } val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { SheetValue.Collapsed at height(100.dp) if (isInitialState) { SheetValue.PartiallyExpanded at offset(percent = 60) } SheetValue.Expanded at contentHeight }, confirmValueChange = { if (isInitialState) { isInitialState = false // Invokes defineValues lambda again. refreshValues() } true } ) ``` -------------------------------- ### Access BottomSheet Anchors After Initialization Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md Demonstrates the correct way to access bottom sheet anchors. Anchors are not available immediately and should be accessed within a `LaunchedEffect` that observes the anchors. ```kotlin // ✗ Won't work immediately val anchor = sheetState.draggableState.anchors.positionOf(SheetValue.Expanded) // ✓ Use after layout LaunchedEffect(sheetState.draggableState.anchors) { val anchor = sheetState.draggableState.anchors.positionOf(SheetValue.Expanded) } ``` -------------------------------- ### Create DraggableAnchors using a Config Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/modules.md Use the DraggableAnchors factory function with a configuration lambda to define anchor points and their positions. The `at` infix function simplifies setting anchor positions. ```kotlin fun DraggableAnchors( builder: DraggableAnchorsConfig.() -> Unit ): DraggableAnchors ``` -------------------------------- ### Missing Target Value Handling in Anchors Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/errors.md When a bottom sheet's current value is no longer present in anchors after `refreshValues()`, the library automatically snaps to the closest remaining anchor. This example shows the internal logic for finding and animating to the closest anchor. ```kotlin // From BottomSheetState.kt:339-366 with(draggableState) { val currentOffset = requireOffset() val searchUpwards = if (prevOffset == currentOffset) prevSearchedUpwards else prevOffset < currentOffset if (!anchors.hasAnchorFor(value)) { val closest = if (searchUpwards != null) { anchors.closestAnchor(currentOffset, searchUpwards) } else { anchors.closestAnchor(currentOffset) } if (closest != null) { scope.launch { animateTo(closest) } } false // Veto the original value change } } ``` -------------------------------- ### Multi-State Sheet Configuration Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Configures a bottom sheet with three states: Collapsed, PartiallyExpanded, and Expanded. Ideal for scenarios requiring intermediate states. ```kotlin enum class SheetValue { Collapsed, PartiallyExpanded, Expanded } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.PartiallyExpanded at offset(percent = 60) SheetValue.Expanded at contentHeight } ) ``` -------------------------------- ### Configure BottomSheet Positional and Velocity Thresholds Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Sets custom thresholds for determining when the bottom sheet should snap to a new state based on drag position and velocity. ```kotlin rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { /* ... */ }, positionalThreshold = { totalDistance -> totalDistance * 0.5f }, velocityThreshold = { 500f } // 500 px/s ) ``` -------------------------------- ### Snap Bottom Sheet State Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Use the `snapTo` method to immediately change the bottom sheet's state without animation, for instance, to collapse it. ```kotlin sheetState.snapTo(SheetValue.Collapsed) ``` -------------------------------- ### Configure BottomSheet sheetContentColor Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Specify the preferred color for content placed inside the bottom sheet. ```kotlin // Automatic based on container color sheetContentColor = contentColorFor(sheetContainerColor) // Explicit color sheetContentColor = Color.Black ``` -------------------------------- ### BottomSheetValuesConfig Usage Context Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Illustrates how 'Position' is created internally by builder functions like height() and offset() within BottomSheetValuesConfig. ```kotlin defineValues = { // These functions return Position internally SheetValue.Collapsed at height(100.dp) // Position created SheetValue.Expanded at offset(percent = 60) // Position created } ``` -------------------------------- ### Height Methods for Bottom Sheet Sizing Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Use height methods to define the bottom sheet's height. Supports pixels, dp, percentages, and wrapping content. ```kotlin height(px = 400f) ``` ```kotlin height(dp = 200.dp) ``` ```kotlin height(percent = 40) // Takes 40% of screen ``` ```kotlin contentHeight ``` -------------------------------- ### Snap to Anchor in AnchoredDraggableState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/modules.md Use the `snapTo` extension function to instantly move the `AnchoredDraggableState` to a specified target anchor value without animation. ```kotlin suspend fun AnchoredDraggableState.snapTo(targetValue: T): Unit ``` -------------------------------- ### Dynamic Multi-State BottomSheet Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Create a BottomSheet with dynamic states that can change based on UI logic. Use a state variable to conditionally define intermediate states. ```kotlin var showMiddleState by remember { mutableStateOf(false) } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) if (showMiddleState) { SheetValue.Partial at offset(percent = 60) } SheetValue.Expanded at contentHeight }, confirmValueChange = { newValue -> if (newValue == SheetValue.Partial) { showMiddleState = true } true } ) ``` -------------------------------- ### Remember Bottom Sheet State with Initial Value Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Configure the initial state of the bottom sheet when it's first created. Ensure the initial value is defined within the `defineValues` lambda. ```kotlin enum class SheetValue { Collapsed, Expanded } val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed // Sheet starts collapsed ) ``` -------------------------------- ### Configure BottomSheet Scaffold Visuals Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Customizes the visual appearance of the BottomSheetScaffold, including max width, shape, container color, drag handle, and swipe gesture enablement. ```kotlin BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { /* ... */ }, sheetMaxWidth = 600.dp, sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), sheetContainerColor = Color.White, sheetDragHandle = { BottomSheetDefaults.DragHandle() }, sheetSwipeEnabled = true, content = { /* ... */ } ) ``` -------------------------------- ### Initialize BottomSheetScaffoldState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Initialize BottomSheetScaffoldState with custom sheet value definitions. Accesses current sheet value and shows snackbars. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) val scaffoldState = rememberBottomSheetScaffoldState(sheetState) // Access sheet state val currentValue = scaffoldState.sheetState.currentValue // Show snackbar LaunchedEffect(Unit) { scaffoldState.snackbarHostState.showSnackbar("Hello!") } ``` -------------------------------- ### Remember BottomSheetState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Creates and remembers a BottomSheetState. Define initial value and anchors for collapsed, partially expanded, and expanded states. Use `height()` for fixed heights and `contentHeight` for dynamic heights based on content. ```kotlin val sheetState = rememberBottomSheetState( initialValue = SheetValue.Collapsed, defineValues = { SheetValue.Collapsed at height(100.dp) SheetValue.Expanded at contentHeight } ) ``` ```kotlin var hasPartial by remember { mutableStateOf(true) } val sheetState = rememberBottomSheetState( initialValue = SheetValue.PartiallyExpanded, defineValues = { SheetValue.Collapsed at height(100.dp) if (hasPartial) { SheetValue.PartiallyExpanded at offset(percent = 60) } SheetValue.Expanded at contentHeight } ) ``` -------------------------------- ### Snap BottomSheet to Collapsed State Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Launches a coroutine to instantly snap the bottom sheet to the collapsed state without animation. Requires a CoroutineScope. ```kotlin Button(onClick = { scope.launch { sheetState.snapTo(SheetValue.Collapsed) } }) { Text("Snap Closed") } ``` -------------------------------- ### BottomSheetScaffold Main Content Lambda Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/types.md Define the main content of the screen using a Composable lambda that accepts PaddingValues. This ensures the content is correctly padded to avoid overlapping with system bars or the bottom sheet. ```kotlin content = { paddingValues -> Box(modifier = Modifier.padding(paddingValues)) { // Main screen content } } ``` -------------------------------- ### Configure BottomSheet sheetMaxWidth Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Set the maximum width for the bottom sheet. Use Dp.Unspecified for a full-width sheet. ```kotlin // Full width (default) sheetMaxWidth = Dp.Unspecified // Limited width sheetMaxWidth = 600.dp // Tablet-optimized sheetMaxWidth = 400.dp ``` -------------------------------- ### Configure BottomSheet sheetShadowElevation Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Set the shadow elevation for a drop shadow effect on the bottom sheet. ```kotlin sheetShadowElevation = BottomSheetDefaults.Elevation // Default shadow sheetShadowElevation = 16.dp // Pronounced shadow sheetShadowElevation = 0.dp // No shadow ``` -------------------------------- ### Configure BottomSheet sheetDragHandle Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Provide a custom composable for the drag handle or set it to null to hide it. ```kotlin // Default Material3 drag handle sheetDragHandle = { BottomSheetDefaults.DragHandle() } // Custom drag handle sheetDragHandle = { Box( modifier = Modifier .padding(vertical = 8.dp) .width(32.dp) .height(4.dp) .background(Color.Gray, RoundedCornerShape(2.dp)) ) } // No drag handle sheetDragHandle = null ``` -------------------------------- ### BottomSheet Layout and Offset Utilities Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Utility functions for accessing and calculating bottom sheet dimensions and offsets. ```kotlin import io.morfly.compose.bottomsheet.material3.BottomSheetDefaults import io.morfly.compose.bottomsheet.material3.layoutHeightDp import io.morfly.compose.bottomsheet.material3.sheetFullHeightDp import io.morfly.compose.bottomsheet.material3.sheetVisibleHeightDp import io.morfly.compose.bottomsheet.material3.offsetDp import io.morfly.compose.bottomsheet.material3.requireLayoutHeightDp import io.morfly.compose.bottomsheet.material3.requireSheetFullHeightDp import io.morfly.compose.bottomsheet.material3.requireSheetVisibleHeightDp import io.morfly.compose.bottomsheet.material3.requireOffsetDp ``` -------------------------------- ### Add Dependency to build.gradle.kts Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/README.md Add this dependency to your module's build.gradle.kts file. Ensure compatibility with Compose Material3. ```kotlin dependencies { implementation("io.morfly.compose:advanced-bottomsheet-material3:") } ``` -------------------------------- ### BottomSheet with Custom Theme and Drag Handle Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/configuration.md Style a BottomSheet using custom shapes, colors, and elevations. Define a custom drag handle for enhanced visual feedback and control. ```kotlin BottomSheetScaffold( scaffoldState = scaffoldState, sheetContent = { /* ... */ }, sheetShape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp), sheetContainerColor = MaterialTheme.colorScheme.surfaceContainer, sheetTonalElevation = 8.dp, sheetShadowElevation = 12.dp, sheetDragHandle = { Surface( modifier = Modifier .padding(vertical = 8.dp) .width(40.dp) .height(5.dp), shape = RoundedCornerShape(2.5.dp), color = MaterialTheme.colorScheme.outline.copy(alpha = 0.4f) ) {} }, content = { paddingValues -> // Screen content } ) ``` -------------------------------- ### Remember BottomSheetScaffoldState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/modules.md Creates and remembers a BottomSheetScaffoldState for use in composables. Requires a BottomSheetState and SnackbarHostState. ```kotlin @Composable fun rememberBottomSheetScaffoldState( sheetState: BottomSheetState, snackbarHostState: SnackbarHostState ): BottomSheetScaffoldState ``` -------------------------------- ### AnchoredDraggableState Imports Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Imports for AnchoredDraggableState, its configuration, and related functions for managing anchored drag behavior. ```kotlin import io.morfly.compose.bottomsheet.material3.AnchoredDraggableState import io.morfly.compose.bottomsheet.material3.AnchoredDragScope import io.morfly.compose.bottomsheet.material3.DraggableAnchors import io.morfly.compose.bottomsheet.material3.DraggableAnchorsConfig import io.morfly.compose.bottomsheet.material3.rememberAnchoredDraggableState import io.morfly.compose.bottomsheet.material3.anchoredDraggable import io.morfly.compose.bottomsheet.material3.animateTo import io.morfly.compose.bottomsheet.material3.snapTo import io.morfly.compose.bottomsheet.material3.updateAnchorsAnimated ``` -------------------------------- ### rememberBottomSheetScaffoldState Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/README.md Creates and remembers the scaffold state for a bottom sheet, combining the sheet state and other necessary states for the scaffold. ```APIDOC ## rememberBottomSheetScaffoldState ### Description Creates and remembers the scaffold state for a bottom sheet. ### Parameters - `sheetState` (BottomSheetState) - The state of the bottom sheet. ### Usage Example ```kotlin val scaffoldState = rememberBottomSheetScaffoldState(sheetState) ``` ``` -------------------------------- ### Monitor BottomSheet State Changes Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Use LaunchedEffect to observe and log changes to the bottom sheet's current value. ```kotlin LaunchedEffect(sheetState.currentValue) { println("Sheet value changed to: ${sheetState.currentValue}") } ``` -------------------------------- ### Create DraggableAnchors Instance Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/api-reference.md Use the factory function to create an immutable DraggableAnchors instance by defining anchor points using a builder lambda. Requires @ExperimentalFoundationApi. ```kotlin val anchors = DraggableAnchors { State.Collapsed at 0f State.Expanded at 500f } ``` -------------------------------- ### Handle Initialization Errors for Layout Height Source: https://github.com/morfly/advanced-bottomsheet-compose/blob/main/_autodocs/quick-reference.md Accessing layout dimensions before they are ready can lead to incorrect values. Use `derivedStateOf` with `requireLayoutHeight()` to ensure the height is available or throw an error. ```kotlin // Problem: Access before layout val height = sheetState.layoutHeight // Returns Int.MAX_VALUE // Solution: Use derivedStateOf or require() val height by remember { derivedStateOf { sheetState.requireLayoutHeight() // Throws if not ready } } ```