Таким образом, после того, как я был перемещен в это композиционное приложение, автоматически сосредотачивается на первом Textfield, но оно не показывает автозаполнения, после того, как я сам заполняю первое поле, и я нажимаю на второе поле, я, наконец, смогу увидеть предложение автозаполнения, если я снова нажимаю на первое поле, я тоже вижу его.@Composable
fun LoginScreen(navController: NavController, logo: Int?) {
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var emailCheck by remember { mutableStateOf(false) }
var passwordCheck by remember { mutableStateOf(false) }
val focusRequesterEmail = remember { FocusRequester() }
val focusRequesterPassword = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
var isLoading by remember { mutableStateOf(false) }
var authError by remember { mutableStateOf(null) }
fun checkEmail() = email.contains("@1511.ru").also { emailCheck = it }
fun checkPassword() = (password.length > 16).also { passwordCheck = it }
val context = LocalContext.current
LaunchedEffect(Unit) {
focusRequesterEmail.requestFocus()
}
val handleLogin = {
isLoading = true
authError = null
ApiClient.login(
username = email,
password = password,
onSuccess = {
savePrefs(context, "email", email)
saveCookiesToPrefs(context, getCookies())
navController.navigate("postLogin") {
popUpTo("login") { inclusive = true }
}
isLoading = false
},
onError = { error ->
isLoading = false
authError = error
focusRequesterEmail.requestFocus()
}
)
}
val noirColor = Color(0xff211f1f)
val errorColor by animateColorAsState(
targetValue = if (!emailCheck || !passwordCheck) Color.Red else Color.Transparent,
animationSpec = tween(durationMillis = 300)
)
val infiniteTransition = rememberInfiniteTransition(label = "iconPulse")
val animatedColor by infiniteTransition.animateColor(
initialValue = Color.LightGray,
targetValue = noirColor,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
),
label = "colorAnim"
)
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xfffefefe))
.padding(horizontal = 15.dp)
.systemBarsPadding()
.imePadding(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(Modifier.height(20.dp))
logo?.apply {
Image(
painter = painterResource(this),
contentDescription = "App Logo",
modifier = Modifier
.size(60.dp)
)
}
Spacer(Modifier.height(20.dp))
Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(R.drawable.arrow_forward_ios),
contentDescription = "Terminal Arrow",
tint = animatedColor,
modifier = Modifier
.size(23.dp)
)
Spacer(
modifier = Modifier
.width(5.dp)
)
OutlinedTextField(
value = email,
onValueChange = {
email = it
checkEmail()
},
placeholder = {
Text(
text = "Введите свой лицейский email...",
fontSize = 15.sp,
color = noirColor,
fontWeight = FontWeight.Medium
)
},
singleLine = true,
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
cursorColor = noirColor,
focusedTextColor = noirColor,
unfocusedTextColor = noirColor,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
modifier = Modifier
.fillMaxWidth()
.semantics {
contentType = ContentType.Username
}
.focusRequester(focusRequesterEmail),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Email,
imeAction = ImeAction.Next,
autoCorrect = false
),
keyboardActions = KeyboardActions(
onNext = { focusRequesterPassword.requestFocus() }
)
)
}
AnimatedVisibility(visible = emailCheck) {
Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(R.drawable.arrow_forward_ios),
contentDescription = "Terminal Arrow",
tint = animatedColor,
modifier = Modifier
.size(23.dp)
)
Spacer(
modifier = Modifier
.width(5.dp)
)
OutlinedTextField(
value = password,
onValueChange = {
password = it
checkPassword()
},
placeholder = {
Text(
text = "Введите пароль от нее...",
fontSize = 15.sp,
color = noirColor,
fontWeight = FontWeight.Medium
)
},
modifier = Modifier
.fillMaxWidth()
.semantics {
contentType = ContentType.Password
}
.focusRequester(focusRequesterPassword),
singleLine = true,
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
cursorColor = noirColor,
focusedTextColor = noirColor,
unfocusedTextColor = noirColor,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Done,
autoCorrect = false
),
keyboardActions = KeyboardActions(
onDone = {
focusManager.clearFocus()
handleLogin()
}
),
visualTransformation = PasswordVisualTransformation()
)
}
}
Spacer(Modifier.weight(1f))
Button(
onClick = handleLogin,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 60.dp),
enabled = emailCheck && passwordCheck && !isLoading,
colors = ButtonColors(
contentColor = Color(0xfffefefe),
containerColor = noirColor,
disabledContainerColor = noirColor,
disabledContentColor = Color(0xfffefefe)
),
) {
Text(
text = "Дальше",
fontSize = 18.sp,
fontWeight = FontWeight.Medium,
color = Color(0xfffefefe)
)
}
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier
.padding(vertical = 16.dp)
.align(Alignment.CenterHorizontally)
)
}
Spacer(
modifier = Modifier
.height(20.dp)
)
authError?.let { error ->
Row(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 100.dp)
.verticalScroll(rememberScrollState())
.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.Center
) {
Text(
text = error,
color = errorColor,
fontSize = 14.sp,
lineHeight = 18.sp
)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ks-strange
Составьте автозаполнение работает странно ⇐ Android
Форум для тех, кто программирует под Android
1755031671
Anonymous
Таким образом, после того, как я был перемещен в это композиционное приложение, автоматически сосредотачивается на первом Textfield, но оно не показывает автозаполнения, после того, как я сам заполняю первое поле, и я нажимаю на второе поле, я, наконец, смогу увидеть предложение автозаполнения, если я снова нажимаю на первое поле, я тоже вижу его.@Composable
fun LoginScreen(navController: NavController, logo: Int?) {
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var emailCheck by remember { mutableStateOf(false) }
var passwordCheck by remember { mutableStateOf(false) }
val focusRequesterEmail = remember { FocusRequester() }
val focusRequesterPassword = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
var isLoading by remember { mutableStateOf(false) }
var authError by remember { mutableStateOf(null) }
fun checkEmail() = email.contains("@1511.ru").also { emailCheck = it }
fun checkPassword() = (password.length > 16).also { passwordCheck = it }
val context = LocalContext.current
LaunchedEffect(Unit) {
focusRequesterEmail.requestFocus()
}
val handleLogin = {
isLoading = true
authError = null
ApiClient.login(
username = email,
password = password,
onSuccess = {
savePrefs(context, "email", email)
saveCookiesToPrefs(context, getCookies())
navController.navigate("postLogin") {
popUpTo("login") { inclusive = true }
}
isLoading = false
},
onError = { error ->
isLoading = false
authError = error
focusRequesterEmail.requestFocus()
}
)
}
val noirColor = Color(0xff211f1f)
val errorColor by animateColorAsState(
targetValue = if (!emailCheck || !passwordCheck) Color.Red else Color.Transparent,
animationSpec = tween(durationMillis = 300)
)
val infiniteTransition = rememberInfiniteTransition(label = "iconPulse")
val animatedColor by infiniteTransition.animateColor(
initialValue = Color.LightGray,
targetValue = noirColor,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
),
label = "colorAnim"
)
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xfffefefe))
.padding(horizontal = 15.dp)
.systemBarsPadding()
.imePadding(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(Modifier.height(20.dp))
logo?.apply {
Image(
painter = painterResource(this),
contentDescription = "App Logo",
modifier = Modifier
.size(60.dp)
)
}
Spacer(Modifier.height(20.dp))
Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(R.drawable.arrow_forward_ios),
contentDescription = "Terminal Arrow",
tint = animatedColor,
modifier = Modifier
.size(23.dp)
)
Spacer(
modifier = Modifier
.width(5.dp)
)
OutlinedTextField(
value = email,
onValueChange = {
email = it
checkEmail()
},
placeholder = {
Text(
text = "Введите свой лицейский email...",
fontSize = 15.sp,
color = noirColor,
fontWeight = FontWeight.Medium
)
},
singleLine = true,
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
cursorColor = noirColor,
focusedTextColor = noirColor,
unfocusedTextColor = noirColor,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
modifier = Modifier
.fillMaxWidth()
.semantics {
contentType = ContentType.Username
}
.focusRequester(focusRequesterEmail),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Email,
imeAction = ImeAction.Next,
autoCorrect = false
),
keyboardActions = KeyboardActions(
onNext = { focusRequesterPassword.requestFocus() }
)
)
}
AnimatedVisibility(visible = emailCheck) {
Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(R.drawable.arrow_forward_ios),
contentDescription = "Terminal Arrow",
tint = animatedColor,
modifier = Modifier
.size(23.dp)
)
Spacer(
modifier = Modifier
.width(5.dp)
)
OutlinedTextField(
value = password,
onValueChange = {
password = it
checkPassword()
},
placeholder = {
Text(
text = "Введите пароль от нее...",
fontSize = 15.sp,
color = noirColor,
fontWeight = FontWeight.Medium
)
},
modifier = Modifier
.fillMaxWidth()
.semantics {
contentType = ContentType.Password
}
.focusRequester(focusRequesterPassword),
singleLine = true,
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
cursorColor = noirColor,
focusedTextColor = noirColor,
unfocusedTextColor = noirColor,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Done,
autoCorrect = false
),
keyboardActions = KeyboardActions(
onDone = {
focusManager.clearFocus()
handleLogin()
}
),
visualTransformation = PasswordVisualTransformation()
)
}
}
Spacer(Modifier.weight(1f))
Button(
onClick = handleLogin,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 60.dp),
enabled = emailCheck && passwordCheck && !isLoading,
colors = ButtonColors(
contentColor = Color(0xfffefefe),
containerColor = noirColor,
disabledContainerColor = noirColor,
disabledContentColor = Color(0xfffefefe)
),
) {
Text(
text = "Дальше",
fontSize = 18.sp,
fontWeight = FontWeight.Medium,
color = Color(0xfffefefe)
)
}
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier
.padding(vertical = 16.dp)
.align(Alignment.CenterHorizontally)
)
}
Spacer(
modifier = Modifier
.height(20.dp)
)
authError?.let { error ->
Row(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 100.dp)
.verticalScroll(rememberScrollState())
.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.Center
) {
Text(
text = error,
color = errorColor,
fontSize = 14.sp,
lineHeight = 18.sp
)
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79733652/compose-autofill-works-strange[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия