Hey kotliners, :slightly_smiling_face: Does anybod...
# android
h
Hey kotliners, 🙂 Does anybody have some opinion about KTX:
isVisible
,
isInvisible
,
isGone
extensions? I mean, first time I implemented KTX in my project I expected something like:
gone()
,
visible()
,
invisible()
h
I always use
isVisible
to set visibility according to a boolean expression. For example:
titleView.isVisible = title.isNotEmpty()
. So something like
visible()
would not be so helpful for me.
h
Good point, but in case you have no boolean expression, you just want to set some view visible/invisible after some liveData changes? You don't think
visible()
or
invisible()
is a better approach?
Idk, it seems more elegant for me 😄
h
Actually, I even wasn't sure if your
visible()
function is setting it to visible or checking if it's visible...
Generally functions that do something should start with a verb. So
setVisible()
or
makeVisible()
sound better to me.
visible()
on the other hand, is an adverb, so the word doesn't seem to indicate that the function changes the visibility of the view.
c
Yeah mutators in general are shortened in Kotlin (remove the
get
and the
set
) but when it comes to boolean expressions you'd still have
is
or
has
for example. I wasn't aware KTX had those already, they sound pretty nifty though.
h
I got it! Thank you for the opinion guys
s
I'm a little bit on the fence about having boolean setters/getters for setting visibility, since it's really a tri-state thingy. Who's to say that
isVisible = false
makes it
GONE
and not
INVISIBLE
, for instance?
☝️ 1
✔️ 1
I mean “who's to say” is obviously the API and its docs, but my point is that the name itself is somewhat ambiguous.
☝️ 1
h
@sindrenm. I faced this code and it kinda bugged my mind a bit 😄 A banch of
true
and
false
Then, we made some extensions
c
How often do folks make things invisible instead of gone though? Realistically if I don't want to show something, I don't want it taking up any space on the screen. There are of course cases where you would want invisible but I don't think I've had a use for it on the last 4 apps I've worked on
h
Yeah I agree, I rarely set some view as invisible... but in this case it was needed