https://kotlinlang.org logo
Title
c

Colton Idle

06/22/2022, 6:53 PM
Maybe I need more sleep... but how do I make sure that I use the default capitalization EXCEPT when I declare the type to be a NAME?
KeyboardOptions.Default.copy(
    capitalization = when (textFieldType) {
        MyCustomInputFieldType.EMAIL -> "How do I use the default here?"
        MyCustomInputFieldType.NAME -> KeyboardCapitalization.Sentences
        MyCustomInputFieldType.NUMBER -> "and here?"
    }
j

jw

06/22/2022, 6:57 PM
You should really invert the two constructs so as to only copy when needed, but you can use
KeyboardOptions.Default.capitalization
to get the default
l

Landry Norris

06/22/2022, 6:58 PM
If you look here, you can also see the default’s value, which is
KeyboardCapitalization.None
c

Colton Idle

06/22/2022, 6:59 PM
@ jw I'm only showing a snippet here, but in general it looks like this. so inverting the two constructs woulnd't make sense (i think) in my actual case. just my snippet
KeyboardOptions.Default.copy(
    capitalization = when (textFieldType) {
        MyCustomInputFieldType.EMAIL -> "How do I use the default here?"
        MyCustomInputFieldType.NAME -> KeyboardCapitalization.Sentences
        MyCustomInputFieldType.NUMBER -> "and here?"
    }
    keyboardType =
        when (textFieldType) {
          MyInputFieldType.EMAIL -> KeyboardType.Email
          MyInputFieldType.PASSWORD -> KeyboardType.Password
          MyInputFieldType.NAME -> KeyboardType.Text
          MyInputFieldType.NUMBER -> KeyboardType.Number
        },
   ),
But cool. KeyboardOptions.Default.capitalization should work. thanks