fix: Fix sheets coming and leaving

This commit is contained in:
Myzel394 2023-12-15 22:14:48 +01:00
parent 39895bcd40
commit 101f8d46e9
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 18 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@ -41,6 +42,7 @@ import app.myzel394.alibi.ui.components.atoms.MessageBox
import app.myzel394.alibi.ui.components.atoms.MessageType
import app.myzel394.alibi.ui.models.AudioRecorderModel
import app.myzel394.alibi.ui.utils.MicrophoneInfo
import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@ -73,11 +75,17 @@ fun MicrophoneSelection(
visibleMicrophones
}
val scope = rememberCoroutineScope()
fun hideSheet() {
scope.launch {
sheetState.hide()
showSelection = false
}
}
if (showSelection) {
ModalBottomSheet(
onDismissRequest = {
showSelection = false
},
onDismissRequest = ::hideSheet,
sheetState = sheetState,
) {
Column(
@ -114,7 +122,7 @@ fun MicrophoneSelection(
selectedAsFallback = isTryingToReconnect,
onSelect = {
audioRecorder.changeMicrophone(null)
showSelection = false
hideSheet()
}
)
}
@ -128,7 +136,7 @@ fun MicrophoneSelection(
disabled = isTryingToReconnect && microphone == audioRecorder.selectedMicrophone,
onSelect = {
audioRecorder.changeMicrophone(microphone)
showSelection = false
hideSheet()
}
)
}
@ -165,7 +173,7 @@ fun MicrophoneSelection(
selected = audioRecorder.selectedMicrophone == microphone,
onSelect = {
audioRecorder.changeMicrophone(microphone)
showSelection = false
hideSheet()
}
)
}
@ -181,7 +189,10 @@ fun MicrophoneSelection(
if (shownMicrophones.isNotEmpty() || (settings.audioRecorderSettings.showAllMicrophones && hiddenMicrophones.isNotEmpty())) {
Button(
onClick = {
showSelection = true
scope.launch {
showSelection = true
sheetState.show()
}
},
colors = ButtonDefaults.textButtonColors(),
) {

View File

@ -34,7 +34,6 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun QuickMaxDurationSelector(
settings: AppSettings,
onDismiss: () -> Unit,
) {
val scope = rememberCoroutineScope()

View File

@ -156,7 +156,6 @@ fun StartRecording(
if (showQuickMaxDurationSelector) {
QuickMaxDurationSelector(
settings = appSettings,
onDismiss = {
showQuickMaxDurationSelector = false
},