https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
s

Slavi

11/18/2023, 1:12 PM
I experience weird behaviour when switching between two TextFields. Tapping to another field causes keyboard to hide and quickly appear again. Any suggestions on how to fix this? I haven't found any similar complaints, so I guess it's not a common issue. My code example is quite simple though
RPReplay_Final1700313029.MP4
Copy code
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
Column(
    modifier = Modifier.fillMaxSize(),
) {
    TextField(
        value = email,
        onValueChange = { email = it },
    )

    TextField(
        value = password,
        onValueChange = { password = it },
    )
}
For ordered focus, do like:
Copy code
Modifier
    .focusProperties { right = Default }
    .focusProperties { right = item1 }
    .focusProperties { right = item2 }
    .focusable()
👍 2
s

Slavi

11/18/2023, 1:44 PM
@Joel Denke Sorry, I don't understand how to apply your solution. As far as I can understand, this article is mostly about how to pass and request focus. I don't have any problem with requesting focus on those fields atm. The issue is keyboard being reopened on every focus change. I struggle to understand how focus ordering will help with it
j

Joel Denke

11/18/2023, 2:29 PM
I think it will deal with keyboard opening avoided by having proper focus request to make sure delegate between each field, like click on it. Could ofc be an iOS bug in CMP. But from my understanding should help.
s

Slavi

11/19/2023, 8:35 AM
if this:
Copy code
val emailFocusRequester = remember { FocusRequester() }
val passwordFocusRequester = remember { FocusRequester() }

var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }

Column {
    TextField(
        modifier = Modifier
            .focusRequester(emailFocusRequester)
            .focusProperties { right = passwordFocusRequester },
        value = email,
        onValueChange = { email = it },
    )
    TextField(
        modifier = Modifier
            .focusRequester(passwordFocusRequester)
            .focusProperties {
                left = emailFocusRequester
                right = FocusRequester.Default
            },
        value = password,
        onValueChange = { password = it },
    )
}
is what Joel advised me to try, then it didn't work as well. I still see keyboard being turned down and pulled back on every click to neighbour text field
k

Kashismails

11/20/2023, 10:53 AM
have you find any solution to this?
s

Slavi

11/20/2023, 3:17 PM
Nope
k

Kashismails

11/20/2023, 3:31 PM
@Dima Avdeev can we please get a solution to this asap 🥹 🥹 🥹
s

Slavi

11/20/2023, 3:36 PM
Issue on github you mentioned was created 1 month ago. It seems atm solution is only to abandon material textfields for iOS
k

Kashismails

11/20/2023, 3:37 PM
I have started migrating to ui text field but that would need forms to be completely migrated to uikit and thats hectic
@Slavi have you been able to do this?
s

Slavi

11/29/2023, 8:29 AM
@Kashismails No, I'm not in such a hurry. I can wait for an official fix by jetbrains devs
k

Kashismails

11/29/2023, 8:30 AM
i have been trying to do this but no success 😞
😥 1
3 Views