https://kotlinlang.org logo
Title
d

Danish Ansari

03/30/2023, 11:50 AM
Does anybody of what’s the alternative of this in Jetpack compose? https://stackoverflow.com/a/74828216/3486601
r

Rizwan

03/30/2023, 1:16 PM
Did u try with keyboardoptions?
In compose
d

Danish Ansari

03/30/2023, 1:49 PM
Yes I have already tried it but it doesn’t work. There seems to be no alternative for
textNoSuggestions
there is parameter called
autoCorrect
in
KeyBoardOptions
but it doesn’t seem like it’s what I expected it to be.
Also from the documentation
autoCorrect
- informs the keyboard whether to enable auto correct. Only applicable to text based
KeyboardTypes
such as
KeyboardType.Email
,
KeyboardType.Uri
. It will not be applied to
KeyboardTypes
such as
KeyboardType.Number
And I’m using
KeyboardType.Number
r

Rizwan

03/31/2023, 12:37 AM
You can still use xml edittext in compose using androidview
d

Danish Ansari

03/31/2023, 7:02 AM
Just for such a simple thing, I don’t want to change my view. But I have found a workaround for now.
var value by remember { mutableStateOf("") }
var oldValueCount by remember { mutableStateOf(0) }

TextField(
    value = value,
    onValueChange = { newValue ->
        if ((newValue.count() - oldValueCount) <= 1) {
            value = newValue
            oldValueCount = newValue.count()
        }
    }
)
With the above workaround, even if the user clicks on suggested text to be pasted from Keyboard,
TextField
won’t get updated
r

Rizwan

03/31/2023, 7:32 AM
Great 👍