Created
June 22, 2025 10:07
-
-
Save vaimalaviya1233/9c402b129c313ae8e69323863361ec11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tobi.example2ktdsl.ui.screens | |
import android.content.res.Configuration | |
import androidx.compose.foundation.BorderStroke | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.width | |
import androidx.compose.foundation.layout.wrapContentHeight | |
import androidx.compose.foundation.shape.RoundedCornerShape | |
import androidx.compose.material3.Button | |
import androidx.compose.material3.Card | |
import androidx.compose.material3.CardDefaults | |
import androidx.compose.material3.ExperimentalMaterial3Api | |
import androidx.compose.material3.MaterialTheme | |
import androidx.compose.material3.ModalBottomSheet | |
import androidx.compose.material3.Slider | |
import androidx.compose.material3.SliderDefaults | |
import androidx.compose.material3.Text | |
import androidx.compose.material3.rememberModalBottomSheetState | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableFloatStateOf | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.tooling.preview.Wallpapers | |
import androidx.compose.ui.unit.dp | |
@OptIn(ExperimentalMaterial3Api::class) | |
@Composable | |
fun PartialBottomSheet() { | |
var showBottomSheet by remember { mutableStateOf(false) } | |
val sheetState = rememberModalBottomSheetState( | |
skipPartiallyExpanded = false, | |
) | |
Column( | |
modifier = Modifier.fillMaxWidth(), | |
horizontalAlignment = Alignment.CenterHorizontally, | |
) { | |
Button( | |
onClick = { showBottomSheet = true } | |
) { | |
Text("Display partial bottom sheet") | |
} | |
if (showBottomSheet) { | |
ModalBottomSheet( | |
modifier = Modifier.fillMaxHeight(), | |
sheetState = sheetState, | |
onDismissRequest = { showBottomSheet = false } | |
) { | |
Text( | |
"Swipe up to open sheet. Swipe down to dismiss.", | |
modifier = Modifier.padding(16.dp) | |
) | |
CustomCardExample {} | |
SliderAdvancedExample() | |
} | |
} | |
} | |
} | |
@Preview | |
@Composable | |
fun SliderAdvancedExample() { | |
var sliderPosition by remember { mutableFloatStateOf(0f) } | |
Column { | |
Slider( | |
value = sliderPosition, | |
onValueChange = { sliderPosition = it }, | |
colors = SliderDefaults.colors( | |
thumbColor = MaterialTheme.colorScheme.secondary, | |
activeTrackColor = MaterialTheme.colorScheme.secondary, | |
inactiveTrackColor = MaterialTheme.colorScheme.secondaryContainer, | |
), | |
steps = 16, | |
valueRange = 10f..50f, | |
modifier = Modifier.padding(horizontal = 16.dp) | |
) | |
Text(text = sliderPosition.toInt().toString()) | |
} | |
} | |
@Composable | |
fun CustomCardExample(event: () -> Unit) { | |
Card( | |
border = BorderStroke(1.dp, Color.Black), | |
colors = CardDefaults.cardColors( | |
containerColor = MaterialTheme.colorScheme.surfaceVariant, | |
), | |
elevation = CardDefaults.cardElevation( | |
defaultElevation = 4.dp | |
), | |
enabled = true, | |
modifier = Modifier.padding(16.dp), | |
onClick = event, | |
shape = RoundedCornerShape(8.dp), | |
) { | |
Text( | |
text = "Custom card that uses the Card composable. Tap me to say hello world.", | |
modifier = Modifier | |
.padding(16.dp) | |
.fillMaxWidth() | |
.wrapContentHeight() | |
) | |
} | |
} | |
@Preview(device = "spec:width=1344px,height=2992px,dpi=480,isRound=true", apiLevel = 36, | |
uiMode = Configuration.UI_MODE_NIGHT_YES, | |
wallpaper = Wallpapers.NONE, name = "Bottom Settings" | |
) | |
@Composable | |
fun PartialBottomSheetPreview() { | |
PartialBottomSheet() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developer.android.com/develop/ui/compose/components/slider
https://github.com/android/snippets/blob/a37e65129e087db5aeea808411ed1d2653a22b69/compose/snippets/src/main/java/com/example/compose/snippets/components/Card.kt
https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#Slider(androidx.compose.material3.SliderState,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.SliderColors,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function1,kotlin.Function1)
https://developer.android.com/develop/ui/compose/components/bottom-sheets-partial