В настоящее время я наблюдаю за каким -то странным поведением при использовании OutlinedTextfield внутри exposedDropdownmenubox . Если я уже щелкнул в OutlinedTextField один раз, фокус всегда возвращается к нему, когда я нажимаю в другое поле, или иногда, когда я просто прокручиваю свое представление - предпочтительно после того, как клавиатура закрыта вручную, если клавиатура остается видимым, я могу нажать на другие поля ввода без какой -либо проблемы. < /p>
кто -нибудь испытал подобное поведение и знает, как это исправить? 'm Использование версии 1.3.1 of androidx.compose.material: Материал
my composable выглядит так:
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ContributorComposable(contributor: Contributor, logbookEntryState: LogbookEntryState, enabled: Boolean) {
Spacer(modifier = Modifier.height(8.dp))
val addContributor: @Composable () -> Unit = {
IconButton(onClick = { logbookEntryState.contributors.add(Contributor()) }) {
Icon(imageVector = Icons.Filled.Add, contentDescription = "")
}
}
var expanded by remember { mutableStateOf(false) }
val options = logbookEntryState.contributorsDropDownList
Column(modifier = Modifier.fillMaxWidth()) {
Row(verticalAlignment = CenterVertically, horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(40.dp))
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { expanded = !expanded && enabled },
modifier = Modifier.focusable(false)
) {
Row(verticalAlignment = CenterVertically, horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
OutlinedTextField(
colors = if (
contributor.company.value.isNotBlank() ||
contributor.registrationNumber.value.isNotBlank() ||
contributor.userCertificationNumber.value.isNotBlank() ||
contributor.companyCertificationNumber.value.isNotBlank() ||
contributor.userFullname.value.isNotBlank()
) TextFieldDefaults.outlinedTextFieldColors(unfocusedBorderColor = db_primary_red) else TextFieldDefaults.outlinedTextFieldColors(),
modifier = Modifier
.weight(1f),
value = contributor.userFullname.value,
onValueChange = { newText ->
contributor.userFullname.value = newText
viewModel.findContributorByName(logbookEntryState, newText)
expanded = true
},
label = { Text(stringResource(id = R.string.logbook_entry_create_contributors)) },
trailingIcon = if (enabled) addContributor else null,
enabled = enabled,
)
if (enabled && logbookEntryState.contributors.size > 1) {
IconButton(onClick = { logbookEntryState.contributors.remove(contributor) }, modifier = Modifier.width(40.dp)) {
Icon(imageVector = Icons.Filled.Delete, contentDescription = "")
}
} else {
Spacer(modifier = Modifier.width(40.dp))
}
}
if (options.isNotEmpty())
ExposedDropdownMenu(
expanded = expanded,
modifier = Modifier.background(db_secondary_white),
onDismissRequest = { expanded = false },
) {
options.forEach { selectionOption ->
DropdownMenuItem(
modifier = Modifier
.background(db_secondary_white)
.exposedDropdownSize(true),
onClick = {
contributor.internalId = selectionOption.internalId
contributor.userFullname.value = selectionOption.userFullname.value
contributor.userFullnameErrorMessage.value = ""
contributor.company.value = selectionOption.company.value
contributor.companyErrorMessage.value = ""
contributor.registrationNumber.value = selectionOption.registrationNumber.value
contributor.registrationNumberErrorMessage.value = ""
contributor.userCertificationNumber.value = selectionOption.userCertificationNumber.value
contributor.userCertificationNumberErrorMessage.value = ""
contributor.companyCertificationNumber.value = selectionOption.companyCertificationNumber.value
contributor.companyCertificationNumberErrorMessage.value = ""
contributor.id = selectionOption.id
contributor.entryId = selectionOption.entryId
contributor.createdBy = selectionOption.createdBy
contributor.creationDate = selectionOption.creationDate
expanded = false
}
) {
Column(modifier = Modifier.fillMaxWidth()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.userFullname.value ?: "")
}
// if there are users with the same name, we show additional information
if (options.groupBy { it.userFullname }.size > 1) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.company.value ?: "")
}
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.registrationNumber.value ?: "")
}
if (viewModel.shouldShowCertificatenummber()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.userCertificationNumber.value ?: "")
}
}
if (viewModel.shouldShowCertificatenummber()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.companyCertificationNumber.value ?: "")
}
}
DefaultDivider()
Spacer(modifier = Modifier.height(8.dp))
}
}
}
}
}
}
}
ErrorComposable(contributor.userFullnameErrorMessage.value)
}
CustomTextField(
label = R.string.logbook_entry_create_company_contributors,
input = contributor.company,
errorMessage = contributor.companyErrorMessage,
enabled = enabled,
shouldShow = true,
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_registrationnr_contributors,
input = contributor.registrationNumber,
errorMessage = contributor.registrationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.logbook?.classEntity?.hasRegistrationNumber == true,
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_certification_numbers_contributors,
input = contributor.userCertificationNumber,
errorMessage = contributor.userCertificationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.shouldShowCertificatenummber(),
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_company_certification_numbers_contributors,
input = contributor.companyCertificationNumber,
errorMessage = contributor.companyCertificationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.shouldShowCertificatenummber(),
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
}
Подробнее здесь: https://stackoverflow.com/questions/754 ... ains-focus
OutdizedTextField в ExposedDropDownMenubox восстанавливает фокус ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1740143552
Anonymous
В настоящее время я наблюдаю за каким -то странным поведением при использовании OutlinedTextfield внутри exposedDropdownmenubox . Если я уже щелкнул в OutlinedTextField один раз, фокус всегда возвращается к нему, когда я нажимаю в другое поле, или иногда, когда я просто прокручиваю свое представление - предпочтительно после того, как клавиатура закрыта вручную, если клавиатура остается видимым, я могу нажать на другие поля ввода без какой -либо проблемы. < /p>
кто -нибудь испытал подобное поведение и знает, как это исправить? 'm Использование версии 1.3.1 of androidx.compose.material: Материал
my composable выглядит так:
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ContributorComposable(contributor: Contributor, logbookEntryState: LogbookEntryState, enabled: Boolean) {
Spacer(modifier = Modifier.height(8.dp))
val addContributor: @Composable () -> Unit = {
IconButton(onClick = { logbookEntryState.contributors.add(Contributor()) }) {
Icon(imageVector = Icons.Filled.Add, contentDescription = "")
}
}
var expanded by remember { mutableStateOf(false) }
val options = logbookEntryState.contributorsDropDownList
Column(modifier = Modifier.fillMaxWidth()) {
Row(verticalAlignment = CenterVertically, horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(40.dp))
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { expanded = !expanded && enabled },
modifier = Modifier.focusable(false)
) {
Row(verticalAlignment = CenterVertically, horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
OutlinedTextField(
colors = if (
contributor.company.value.isNotBlank() ||
contributor.registrationNumber.value.isNotBlank() ||
contributor.userCertificationNumber.value.isNotBlank() ||
contributor.companyCertificationNumber.value.isNotBlank() ||
contributor.userFullname.value.isNotBlank()
) TextFieldDefaults.outlinedTextFieldColors(unfocusedBorderColor = db_primary_red) else TextFieldDefaults.outlinedTextFieldColors(),
modifier = Modifier
.weight(1f),
value = contributor.userFullname.value,
onValueChange = { newText ->
contributor.userFullname.value = newText
viewModel.findContributorByName(logbookEntryState, newText)
expanded = true
},
label = { Text(stringResource(id = R.string.logbook_entry_create_contributors)) },
trailingIcon = if (enabled) addContributor else null,
enabled = enabled,
)
if (enabled && logbookEntryState.contributors.size > 1) {
IconButton(onClick = { logbookEntryState.contributors.remove(contributor) }, modifier = Modifier.width(40.dp)) {
Icon(imageVector = Icons.Filled.Delete, contentDescription = "")
}
} else {
Spacer(modifier = Modifier.width(40.dp))
}
}
if (options.isNotEmpty())
ExposedDropdownMenu(
expanded = expanded,
modifier = Modifier.background(db_secondary_white),
onDismissRequest = { expanded = false },
) {
options.forEach { selectionOption ->
DropdownMenuItem(
modifier = Modifier
.background(db_secondary_white)
.exposedDropdownSize(true),
onClick = {
contributor.internalId = selectionOption.internalId
contributor.userFullname.value = selectionOption.userFullname.value
contributor.userFullnameErrorMessage.value = ""
contributor.company.value = selectionOption.company.value
contributor.companyErrorMessage.value = ""
contributor.registrationNumber.value = selectionOption.registrationNumber.value
contributor.registrationNumberErrorMessage.value = ""
contributor.userCertificationNumber.value = selectionOption.userCertificationNumber.value
contributor.userCertificationNumberErrorMessage.value = ""
contributor.companyCertificationNumber.value = selectionOption.companyCertificationNumber.value
contributor.companyCertificationNumberErrorMessage.value = ""
contributor.id = selectionOption.id
contributor.entryId = selectionOption.entryId
contributor.createdBy = selectionOption.createdBy
contributor.creationDate = selectionOption.creationDate
expanded = false
}
) {
Column(modifier = Modifier.fillMaxWidth()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.userFullname.value ?: "")
}
// if there are users with the same name, we show additional information
if (options.groupBy { it.userFullname }.size > 1) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.company.value ?: "")
}
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.registrationNumber.value ?: "")
}
if (viewModel.shouldShowCertificatenummber()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.userCertificationNumber.value ?: "")
}
}
if (viewModel.shouldShowCertificatenummber()) {
Row(verticalAlignment = CenterVertically) {
Text(text = selectionOption.companyCertificationNumber.value ?: "")
}
}
DefaultDivider()
Spacer(modifier = Modifier.height(8.dp))
}
}
}
}
}
}
}
ErrorComposable(contributor.userFullnameErrorMessage.value)
}
CustomTextField(
label = R.string.logbook_entry_create_company_contributors,
input = contributor.company,
errorMessage = contributor.companyErrorMessage,
enabled = enabled,
shouldShow = true,
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_registrationnr_contributors,
input = contributor.registrationNumber,
errorMessage = contributor.registrationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.logbook?.classEntity?.hasRegistrationNumber == true,
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_certification_numbers_contributors,
input = contributor.userCertificationNumber,
errorMessage = contributor.userCertificationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.shouldShowCertificatenummber(),
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
CustomTextField(
label = R.string.logbook_entry_create_company_certification_numbers_contributors,
input = contributor.companyCertificationNumber,
errorMessage = contributor.companyCertificationNumberErrorMessage,
enabled = enabled,
shouldShow = viewModel.shouldShowCertificatenummber(),
mandatoryField = contributor.userFullname.value.isNotBlank(),
)
}
Подробнее здесь: [url]https://stackoverflow.com/questions/75460341/outlinedtextfield-in-exposeddropdownmenubox-regains-focus[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия