1

I have the two following definitions.

The first one as an extension function allowing to set visible a View and also to set it as gone or invisible with the second parameter.

fun View.setVisible(visible: Boolean, goneWhenVisibleFalse: Boolean) {
    visibility = when {
        visible -> View.VISIBLE
        goneWhenVisibleFalse -> View.GONE
        else -> View.INVISIBLE
    }
}

The second here, as an extension property using the first above.

var View.visible: Boolean
    get() = visibility == View.VISIBLE
    set(value) {
        setVisible(value, true)
    }

None of complicated until here. The code compiles and the app launch correctly. BUT I get a black screen, no error in the logcat, nothing to get a trace.

After a while, I change the signature of the first function to receive the second parameter with true as default:

fun View.setVisible(visible: Boolean, goneWhenVisibleFalse: Boolean= true)

And then it works normally. The question is: why this happen? I dug into the bytecode. But looks there is no duplication of signatures, the number of parameters is different in both cases.

Maybe a bug of kotlin? I'm using kotlin plugin v1.2.30

crgarridos
  • 8,758
  • 3
  • 49
  • 61

1 Answers1

0

Use this:

View.setVisible(visible: Boolean, goneWhenInvisible: Boolean = false) { 
    visibility = if (visible) View.VISIBLE 
    else if (goneWhenInvisible) View.GONE 
    else View.INVISIBLE
}
crgarridos
  • 8,758
  • 3
  • 49
  • 61
user221256
  • 415
  • 5
  • 14