james
02/17/2022, 9:07 AMJavi Chaqués
02/17/2022, 9:39 AMjossiwolf
02/17/2022, 9:56 AMjames
02/17/2022, 10:09 AMsearch(searchTerm)
I understand part of your suggestion, but I can't understand how I will access the searchTerm
, since these are in different scopes.. where the searchTerm
is accessible, I cannot use LaunchedEffect
since I'm not inside a Composable function
I'm sure there will be a straightforward way to do this which I'm missing. any tips?jossiwolf
02/17/2022, 5:11 PMsearchTerm
is entered in the bottom sheet?james
02/17/2022, 9:12 PMval validateThenSearch = {
val searchTerm = searchFieldState.value.text.trim()
if (searchTerm.isNotEmpty()) {
focusManager.clearFocus(force = true)
modalCoroutineScope.launch {
searchModalState.hide()
}
// hack until we can correctly do this at end of animation
screenCoroutineScope.launch {
delay(250)
search(searchTerm)
}
}
}
jossiwolf
02/18/2022, 9:43 AMsnapshotFlow
works outside of composables, too. So something like:
val validateThenSearch = {
val searchTerm = searchFieldState.value.text.trim()
if (searchTerm.isNotEmpty()) {
focusManager.clearFocus(force = true)
modalCoroutineScope.launch {
// This is in a different coroutine than the hide call because hide can throw a CancellationException in some cases, but the sheet could still get hidden
val sheetHiddenEvents = snapshotFlow { searchModalState.currentValue }.filter { it == ModalBottomSheetValue.Hidden }
val waitForSheetHidden = sheetHiddenEvents.first()
search(searchTerm)
}
modalCoroutineScope.launch {
searchModalState.hide()
}
}
}
james
02/20/2022, 4:18 AM