sindrenm
05/14/2018, 11:34 AMView
in android-ktx? I find the getters really handy and readable, but the setters feel “imbalanced” and not thought through:
inline var View.isVisible: Boolean
get() = visibility == View.VISIBLE
set(value) {
visibility = if (value) View.VISIBLE else View.GONE
}
inline var View.isInvisible: Boolean
get() = visibility == View.INVISIBLE
set(value) {
visibility = if (value) View.INVISIBLE else View.VISIBLE
}
inline var View.isGone: Boolean
get() = visibility == View.GONE
set(value) {
visibility = if (value) View.GONE else View.VISIBLE
}
In my opinion, saying button.isVisible = false
in Android doesn't really make sense because of the difference between View.INVISIBLE
and View.GONE
. What do you guys think?stan0
05/14/2018, 11:46 AMisVissible = false
doesn’t mean gone
logically. But in reality I think that switching between VISIBLE
and GONE
is way more often used. So I guess it’s a shortcut for this case.sindrenm
05/14/2018, 11:50 AMView.isVisible(Boolean)
from the get-go, and I'm thinking this is exactly that reason. It doesn't really make sense when you have three different states of visibility.ghedeon
05/14/2018, 11:50 AMfun View.show() {
visibility = View.VISIBLE
}
fun View.hide() {
visibility = View.GONE
}
Nick Skelton
05/14/2018, 1:24 PMfun View.show() {
visibility = View.VISIBLE
}
fun View.gone() {
visibility = View.GONE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
stan0
05/14/2018, 1:31 PMView.begone()
:))diego-gomez-olvera
05/14/2018, 2:01 PMView.INVISIBLE
so I find the current definition quite convenient. Keeping in mind that Kotlin does not have ternary operator, being able to do view.isVisible = value
is quite nice