Skip to content

Commit

Permalink
Improve valid name text behaviour for custom lists dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Mar 6, 2024
1 parent 382afe2 commit 65c2359
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ class SelectLocationScreenTest {
setContentWithTheme {
SelectLocationScreen(
uiState =
SelectLocationUiState.Content(
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = DUMMY_RELAY_COUNTRIES,
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
),
SelectLocationUiState.Content(
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = DUMMY_RELAY_COUNTRIES,
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
),
onSelectRelay = mockedOnSelectRelay
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,6 @@ fun ScaffoldWithSmallTopBar(
actions = actions
)
},
content = {
content(
Modifier.fillMaxSize()
.padding(it)
)
}
content = { content(Modifier.fillMaxSize().padding(it)) }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -99,6 +101,7 @@ fun CreateCustomListDialog(
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
val name = remember { mutableStateOf("") }
val isValidName by remember { derivedStateOf { name.value.isNotBlank() } }

AlertDialog(
title = {
Expand All @@ -115,7 +118,7 @@ fun CreateCustomListDialog(
onInputChanged()
},
onSubmit = {
if (it.isNotBlank()) {
if (isValidName) {
createCustomList(it)
}
},
Expand Down Expand Up @@ -152,7 +155,7 @@ fun CreateCustomListDialog(
PrimaryButton(
text = stringResource(id = R.string.create),
onClick = { createCustomList(name.value) },
isEnabled = name.value.isNotBlank()
isEnabled = isValidName
)
},
dismissButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -79,6 +80,7 @@ fun EditCustomListNameDialog(
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
val input = remember { mutableStateOf(uiState.name) }
val isValidName by remember { derivedStateOf { input.value.isNotBlank() } }
AlertDialog(
title = {
Text(
Expand All @@ -94,7 +96,7 @@ fun EditCustomListNameDialog(
onInputChanged()
},
onSubmit = {
if (it.isNotBlank()) {
if (isValidName) {
updateName(it)
}
},
Expand Down Expand Up @@ -141,7 +143,7 @@ fun EditCustomListNameDialog(
PrimaryButton(
text = stringResource(id = R.string.save),
onClick = { updateName(input.value) },
isEnabled = input.value.isNotBlank()
isEnabled = isValidName
)
},
dismissButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import kotlinx.coroutines.launch
fun RunOnKeyChange(key: Any, block: suspend CoroutineScope.() -> Unit) {
val scope = rememberCoroutineScope()
rememberSaveable(key) {
scope.launch {
block()
}
scope.launch { block() }
key
}
}

0 comments on commit 65c2359

Please sign in to comment.