Skip to content

Commit

Permalink
Fix quick sheet options: dismiss before action
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Oct 20, 2024
1 parent b6b89f8 commit cf50ac9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.SheetState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -34,6 +35,7 @@ import kotlin.math.abs

@Composable
fun QuickOptionsBottomSheet(
sheetState: SheetState,
pair: QuickPair,
onPin: (QuickPair) -> Unit,
onUnpin: (QuickPair) -> Unit,
Expand All @@ -45,6 +47,7 @@ fun QuickOptionsBottomSheet(
ModalBottomSheet(
modifier = Modifier,
onDismissRequest = { onDismiss() },
sheetState = sheetState,
dragHandle = null,
containerColor = Color.White,
shape = RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -70,10 +73,12 @@ import dev.arkbuilders.rate.presentation.ui.QuickSwipeItem
import dev.arkbuilders.rate.presentation.ui.RateSnackbarHost
import dev.arkbuilders.rate.presentation.ui.SearchTextField
import dev.arkbuilders.rate.presentation.utils.DateFormatUtils
import kotlinx.coroutines.launch
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
import java.time.OffsetDateTime

@OptIn(ExperimentalMaterial3Api::class)
@RootNavGraph(start = true)
@Destination
@Composable
Expand Down Expand Up @@ -117,6 +122,9 @@ fun QuickScreen(navigator: DestinationsNavigator) {

val isEmpty = state.pages.isEmpty()

val scope = rememberCoroutineScope()
val bottomSheetState = rememberModalBottomSheetState()

Scaffold(
floatingActionButton = {
if (state.initialized.not())
Expand Down Expand Up @@ -153,7 +161,9 @@ fun QuickScreen(navigator: DestinationsNavigator) {
state = state,
onFilterChanged = viewModel::onFilterChanged,
onDelete = viewModel::onDelete,
onClick = viewModel::onShowOptions,
onClick = {
viewModel.onShowOptions(it)
},
onPin = viewModel::onPin,
onUnpin = viewModel::onUnpin,
onNewCode = {
Expand All @@ -164,6 +174,7 @@ fun QuickScreen(navigator: DestinationsNavigator) {
}
state.optionsData?.let {
QuickOptionsBottomSheet(
bottomSheetState,
pair = it.pair,
onPin = viewModel::onPin,
onUnpin = viewModel::onUnpin,
Expand All @@ -181,7 +192,15 @@ fun QuickScreen(navigator: DestinationsNavigator) {
)
},
onDelete = viewModel::onDelete,
onDismiss = viewModel::onHideOptions,
onDismiss = {
scope.launch {
bottomSheetState.hide()
}.invokeOnCompletion {
if (!bottomSheetState.isVisible) {
viewModel.onHideOptions()
}
}
},
)
}
}
Expand Down

0 comments on commit cf50ac9

Please sign in to comment.