pocmo / recompose

recompose is a tool for converting Android layouts in XML to Kotlin code using Jetpack Compose.
Apache License 2.0
794 stars 49 forks source link

Issue #91: Add support for ImageButton #110

Closed t-regbs closed 2 years ago

t-regbs commented 3 years ago

I added this check to the LineWriter:

fun startLine(text: String = "") {
        if (builder.isNotEmpty() && checkLast('(').not()) {
            repeat(indent) { builder.append(INDENT) }
        }
        builder.append(text)
}

Where checkLast is

fun checkLast(char: Char): Boolean {
        return builder.last() == char
}

Because without the check instead of having as desired:

Button(onClick = {}, modifier = Modifier.width(100.dp).height(100.dp)) {
         Image(imageResource(R.drawable.ic_lock_power_off))
}

I get:

Button(onClick = {}, modifier = Modifier.width(100.dp).height(100.dp)) {
         Image(      imageResource(R.drawable.ic_lock_power_off))
}
pocmo commented 3 years ago

Hey @t-regbs. Thank you for your pull request. Overall this looks good. I wonder if we can solve the problem you are describing differently than the change in startLine(). The function startLine() is supposed to start an indented line and now you made it more complex handling other unrelated cases. So, I wonder if we should avoid calling startLine() in the first place if this is not what we want here... but I haven't looked closely at the code yet.