This file contains 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
//... | |
android { | |
//... | |
buildFeatures { | |
compose true | |
} | |
composeOptions { | |
kotlinCompilerExtensionVersion '1.3.1' |
This file contains 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
val coroutineScope = rememberCoroutineScope() | |
val modalSheetState = rememberModalBottomSheetState( | |
initialValue = ModalBottomSheetValue.Hidden, | |
confirmStateChange = { it != ModalBottomSheetValue.HalfExpanded }, | |
skipHalfExpanded = true, | |
) |
This file contains 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
ModalBottomSheetLayout( | |
sheetState = modalSheetState, | |
sheetShape = RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp), | |
sheetContent = { | |
Column( | |
//... | |
) { | |
//... | |
Button( |
This file contains 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
BackHandler(modalSheetState.isVisible) { | |
coroutineScope.launch { modalSheetState.hide() } | |
} |
This file contains 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
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
JetpackComposeBottomSheetTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colors.background | |
) { | |
BottomSheetLayout() |
This file contains 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
@Composable | |
fun BottomSheetLayout() { | |
//... | |
var isSheetFullScreen by remember { mutableStateOf(false) } | |
val roundedCornerRadius = if (isSheetFullScreen) 0.dp else 12.dp | |
val modifier = if (isSheetFullScreen) | |
Modifier | |
.fillMaxSize() | |
else |
This file contains 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
@Composable | |
fun BottomSheetLayout() { | |
val coroutineScope = rememberCoroutineScope() | |
val modalSheetState = rememberModalBottomSheetState( | |
initialValue = ModalBottomSheetValue.Hidden, | |
confirmStateChange = { it != ModalBottomSheetValue.HalfExpanded }, | |
skipHalfExpanded = true | |
) | |
ModalBottomSheetLayout( |
This file contains 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
// Material3 Colors | |
// Light | |
val PrimaryLight = Color(0xFF0061a4) | |
val OnPrimaryLight = Color(0xFFFFFFFF) | |
val PrimaryContainerLight = Color(0xFFd1e4ff) | |
val OnPrimaryContainerLight = Color(0xFF001d36) | |
val SecondaryLight = Color(0xFF535f70) | |
val OnSecondaryLight = Color(0xFFffffff) |
This file contains 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
private val DarkColorPalette = darkColorScheme( | |
primary = PrimaryDark, | |
onPrimary = OnPrimaryDark, | |
primaryContainer = PrimaryContainerDark, | |
onPrimaryContainer = OnPrimaryContainerDark, | |
secondary = SecondaryDark, | |
onSecondary = OnSecondaryDark, | |
secondaryContainer = SecondaryContainerDark, | |
onSecondaryContainer = OnSecondaryContainerDark, | |
tertiary = TertiaryDark, |
This file contains 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
class DataStoreUtil(private val context: Context) { | |
companion object { | |
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore("settings") | |
val THEME_KEY = booleanPreferencesKey("theme") | |
} | |
fun getTheme(isSystemDarkTheme: Boolean): Flow<Boolean> = context.dataStore.data | |
.map { preferences -> | |
preferences[THEME_KEY] ?: isSystemDarkTheme |
OlderNewer