Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quick sheet options: dismiss before action #125

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -107,11 +110,11 @@ private fun Content(
OutlinedButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
onDismiss()
if (pair.isPinned())
onUnpin(pair)
else
onPin(pair)
onDismiss()
},
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, ArkColor.Border),
Expand All @@ -137,8 +140,8 @@ private fun Content(
OutlinedButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
onEdit(pair)
onDismiss()
onEdit(pair)
},
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, ArkColor.Border),
Expand All @@ -160,8 +163,8 @@ private fun Content(
OutlinedButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
onReuse(pair)
onDismiss()
onReuse(pair)
},
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, ArkColor.Border),
Expand All @@ -183,8 +186,8 @@ private fun Content(
OutlinedButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
onDelete(pair)
onDismiss()
onDelete(pair)
},
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, ArkColor.BorderError),
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,12 @@ fun QuickScreen(navigator: DestinationsNavigator) {
)
},
onDelete = viewModel::onDelete,
onDismiss = viewModel::onHideOptions,
onDismiss = {
scope.launch {
bottomSheetState.hide()
viewModel.onHideOptions()
}
},
)
}
}
Expand Down