Skip to content

Commit 88fddb8

Browse files
committed
Add ViewGroup extension function
* Visibility
1 parent ec94a60 commit 88fddb8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.enginebai.base.extensions
2+
3+
import android.view.View
4+
import android.view.ViewGroup
5+
6+
fun ViewGroup.setVisible(visible: Boolean) {
7+
visibility = if (visible) View.VISIBLE else View.INVISIBLE
8+
}
9+
10+
fun ViewGroup.setExistence(exist: Boolean) {
11+
visibility = if (exist) View.VISIBLE else View.GONE
12+
}
13+
14+
fun ViewGroup.gone() {
15+
setExistence(false)
16+
}
17+
18+
fun ViewGroup.invisible() {
19+
setVisible(false)
20+
}
21+
22+
fun ViewGroup.visible() {
23+
visibility = View.VISIBLE
24+
}
25+
26+
fun ViewGroup.toggleVisible() {
27+
visibility = if (visibility == View.VISIBLE) View.INVISIBLE else View.VISIBLE
28+
}
29+
30+
fun ViewGroup.toggleExistence() {
31+
visibility = if (visibility == View.VISIBLE) View.GONE else View.VISIBLE
32+
}
33+
34+
val ViewGroup.isGone: Boolean get() = (visibility == View.GONE)
35+
val ViewGroup.isInvisible: Boolean get() = (visibility == View.INVISIBLE)
36+
val ViewGroup.isVisible: Boolean get() = (visibility == View.VISIBLE)
37+

0 commit comments

Comments
 (0)