anko icon indicating copy to clipboard operation
anko copied to clipboard

Proposal: easier view visibility

Open neworld opened this issue 7 years ago • 3 comments

Current Android way to change the visibility of views is not very clean. What if we could have these:

button.gone()
title.visibleIf(item.title != null, otherwise = View::gone)

Interface could be:

fun View.gone()
fun View.visible()
fun View.invisible()

fun View.visibleIf(state: Boolean, otherwise: View.() -> Unit)

If these little helpers could be a part of Anko, I would like to implement this.

neworld avatar May 26 '17 10:05 neworld

👍

By the way, what about makeGone(), makeVisible(), makeInvisible()?

yanex avatar May 26 '17 19:05 yanex

Naming depends. I personally and my colleagues prefer shorter. It is pretty intuitive, heavily used, especially my beloved visibleIf(...). However, the interface has to be consistent, so I don't see any problem to use longer names if they are following some consistency or conventions.

neworld avatar May 27 '17 09:05 neworld

Has this been implemented? I am personally using similar helpers and they're just what Anko commons should have. My extension functions, which are as concise as image_view.show():

// shows this view
fun View.show(): View {
    this.visibility = View.VISIBLE
    return this
}
// hides the view
fun View.hide(): View {
    this.visibility = View.INVISIBLE
    return this
}
// makes the view gone
fun View.gone(): View {
    this.visibility = View.GONE
    return this
}

Pfuster12 avatar Sep 25 '18 17:09 Pfuster12