From 0692c2f011bc070adf615a8f65fc8bebd756b00e Mon Sep 17 00:00:00 2001 From: Alexander Karkossa Date: Mon, 10 Jun 2024 07:04:27 +0200 Subject: [PATCH] fix: disable scrim when fraction 0f --- bottom-drawer-scaffold/build.gradle | 2 +- .../BottomDrawerScaffold.kt | 6 +++++- .../compose/bottomdrawerscaffold/Scrim.kt | 17 +++++++++++------ .../sample/MainActivity.kt | 18 ++++++++++++++---- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/bottom-drawer-scaffold/build.gradle b/bottom-drawer-scaffold/build.gradle index 50a312a..5af584c 100644 --- a/bottom-drawer-scaffold/build.gradle +++ b/bottom-drawer-scaffold/build.gradle @@ -7,7 +7,7 @@ apply from: '../buildCompose.gradle' ext { PUBLISH_GROUP_ID = 'de.charlex.compose' - PUBLISH_VERSION = '2.0.0-rc01' + PUBLISH_VERSION = '2.0.0-rc02' PUBLISH_ARTIFACT_ID = 'bottom-drawer-scaffold' } diff --git a/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/BottomDrawerScaffold.kt b/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/BottomDrawerScaffold.kt index 9e1c2da..1d816c5 100644 --- a/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/BottomDrawerScaffold.kt +++ b/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/BottomDrawerScaffold.kt @@ -131,7 +131,11 @@ fun BottomDrawerScaffold( } }, fraction = { - calculateFraction(initialOffset, 0f, bottomSheetScaffoldState.bottomSheetState.requireOffset()) + try { + calculateFraction(initialOffset, 0f, bottomSheetScaffoldState.bottomSheetState.requireOffset()) + } catch (exception: IllegalStateException) { + 0f + } }, color = drawerScrimColor ) diff --git a/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/Scrim.kt b/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/Scrim.kt index f559948..ed66532 100644 --- a/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/Scrim.kt +++ b/bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/Scrim.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.semantics.contentDescription @@ -29,11 +30,15 @@ fun Scrim( Modifier } - Canvas( - Modifier - .fillMaxSize() - .then(dismissDrawer) - ) { - drawRect(color, alpha = fraction()) + val fraction = fraction() + + if(fraction > 0f) { + Canvas( + Modifier + .fillMaxSize() + .then(dismissDrawer) + ) { + drawRect(color, alpha = fraction()) + } } } diff --git a/example/src/main/java/de/charlex/compose/bottomdrawerscaffold/sample/MainActivity.kt b/example/src/main/java/de/charlex/compose/bottomdrawerscaffold/sample/MainActivity.kt index 089061e..688f69c 100644 --- a/example/src/main/java/de/charlex/compose/bottomdrawerscaffold/sample/MainActivity.kt +++ b/example/src/main/java/de/charlex/compose/bottomdrawerscaffold/sample/MainActivity.kt @@ -1,6 +1,7 @@ package de.charlex.compose.bottomdrawerscaffold.sample import android.os.Bundle +import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge @@ -36,6 +37,7 @@ import androidx.compose.material.icons.filled.Refresh import androidx.compose.material.icons.filled.Send import androidx.compose.material.icons.filled.ShoppingCart import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon @@ -211,11 +213,19 @@ fun Content() { .height(10.dp) .background(color = MaterialTheme.colorScheme.primary) ) - Text( + + Button( modifier = Modifier.align(Alignment.Center), - text = "Content", - style = MaterialTheme.typography.bodyMedium - ) + onClick = { + Log.d("TEST", "click") + } + ) { + Text( + text = "Content", + style = MaterialTheme.typography.bodyMedium + ) + } + Box( modifier = Modifier .fillMaxWidth()