Коммит c297b7ba создал по автору Radch-enko's avatar Radch-enko
Просмотр файлов

Refactor: improve null safety, optimize dropdown handling, and enhance UI alignment

- Added null safety checks in `MainComponent` to prevent potential crashes during room selection.
- Replaced `ExposedDropdownMenuBox` with a custom `DropdownMenu` implementation for streamlined organizer selection.
- Adjusted dropdown menu width dynamically based on `TextField` size.
- Fixed UI inconsistencies in `EventDurationView` by using `stringResource` for all string references.
- Updated `UpdateEventComponent` to expand dropdown automatically when filtering organizers.
владелец c05e62ed
......@@ -30,10 +30,14 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
......@@ -62,6 +66,9 @@ fun EventOrganizerView(
onDoneInput: (String) -> Unit,
inputText: String
) {
val focusRequester = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
Column(modifier = modifier) {
Text(
text = stringResource(Res.string.selectbox_organizer_title),
......@@ -87,7 +94,13 @@ fun EventOrganizerView(
) {
TextField(
modifier = Modifier.fillMaxWidth(0.8f),
modifier = Modifier.onFocusChanged(
onFocusChanged = {
if (it.isFocused) {
onExpandedChange()
}
}
).focusRequester(focusRequester).fillMaxWidth(0.8f),
value = inputText,
singleLine = true,
onValueChange = {
......@@ -116,6 +129,7 @@ fun EventOrganizerView(
defaultKeyboardAction(ImeAction.Done)
onDoneInput(inputText)
onExpandedChange()
focusRequester.freeFocus()
}
),
)
......@@ -127,7 +141,7 @@ fun EventOrganizerView(
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { onExpandedChange() },
onDismissRequest = { },
properties = PopupProperties(focusable = false),
modifier = Modifier.width(with(LocalDensity.current) { mTextFieldSize.width.toDp() })
) {
......@@ -137,6 +151,8 @@ fun EventOrganizerView(
.fillMaxWidth(),
onClick = {
onSelectItem(organizer)
focusRequester.freeFocus()
focusManager.clearFocus()
onExpandedChange()
},
text = { Text(text = organizer.fullName) },
......
......@@ -148,7 +148,7 @@ class UpdateEventComponent(
val newList = state.value.organizers
.filter { it.fullName.lowercase().contains(input.lowercase()) }
.sortedBy { it.fullName.lowercase().indexOf(input.lowercase()) }
mutableState.update { it.copy(inputText = input, selectOrganizers = newList, expanded = true) }
mutableState.update { it.copy(inputText = input, selectOrganizers = newList) }
}
private fun checkEnableButton(
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать