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

Siyamed

09/01/2020, 10:55 PM
hard to read
g

Guy Bieber

09/01/2020, 11:02 PM
less weird
s

Siyamed

09/01/2020, 11:07 PM
does the icon click? or does it immediately act as if textfield was clicked and get into edit mode?
i can think that the icon click is handled after the textfield in this example
even though i do not know how things are placed and ordered
as far as i know once a click is handled by a handler, it is not delegated to others.
cc @Alexandre Elias [G]
g

Guy Bieber

09/01/2020, 11:15 PM
It acts like a textfield immediately. I don’t see a shadow on the icon when pressed.
s

Siyamed

09/01/2020, 11:19 PM
then textifeld gets the click
the remaining of the code would be useful
TextfieldWithHint composable
g

Guy Bieber

09/01/2020, 11:25 PM
Copy code
@Composable
    fun TextFieldWithHint(
        text: String,
        hint: @Composable() () -> Unit,
        onDone: (String) -> Unit = {},
        backgroundColor: Color = nikolaColors.color19,
        textColor : Color = nikolaColors.White,
        fontSize : TextUnit =  18.sp,
        trailingIcon: @Composable (() -> Unit)? = null,
        keyboardType: KeyboardType = KeyboardType.Text,
        visualTransformation: VisualTransformation =  VisualTransformation.None,
        cursorColor : Color = nikolaColors.White
    ) {

        val mText =
            savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue(text) }


        OutlinedTextField(
            value = mText.value,
            label = hint,
            textStyle = TextStyle (
                color = textColor,
                fontSize = fontSize
            ),
            keyboardType = keyboardType,
            imeAction = ImeAction.Done,
            trailingIcon = trailingIcon,
            onValueChange = {
                mText.value = it
            },
            onImeActionPerformed = { action, softKeyboard ->
                if (action == ImeAction.Done) {
                    //todo remove hack when android fixes it
                    //On older phones the shift key shows up as 00 in the string
                    val char : Char = 0x00.toChar()
                    var str = mText.value.text.replace("${char}", "")
                    onDone(str) 
                    hideKeyboard()
                }
            },
            activeColor = cursorColor,
            visualTransformation = visualTransformation
        )
    }
I bet the if statement isn’t reevaluated for the visualTransformation .
s

Siyamed

09/01/2020, 11:30 PM
thank you I see it now. checked the code a bit. this sounds like a bug
trailing icon is defined before textfield in the code
I wonder if it is what causes the trailing not to be able to get the click
Can you please create a ticket about this?
g

Guy Bieber

09/01/2020, 11:41 PM
Question: does it evaluate in order of definition. If so the trailing icon should have got the click.
@Siyamed The issue tracker (https://issuetracker.google.com/issues?q=componentid:612128) does not allow me to create an issue (create button is grey).
This works in alpha-02
👍 1