Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit f0ec976

Browse files
committed
feat: add some helpers for view bindings
1 parent c5722a0 commit f0ec976

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

viewbinding/src/main/java/com/crazylegend/viewbinding/ViewBindingExtensions.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@ import android.view.ViewGroup
99
import androidx.annotation.RequiresApi
1010
import androidx.appcompat.app.AppCompatActivity
1111
import androidx.core.view.children
12+
import androidx.core.view.isInvisible
13+
import androidx.core.view.isVisible
1214
import androidx.fragment.app.Fragment
1315
import androidx.recyclerview.widget.RecyclerView
1416
import androidx.viewbinding.ViewBinding
1517

1618

1719
inline fun <T : ViewBinding> Activity.viewBinding(crossinline bindingInflater: (LayoutInflater) -> T) =
18-
lazy(LazyThreadSafetyMode.NONE) {
19-
bindingInflater.invoke(layoutInflater)
20-
}
20+
lazy(LazyThreadSafetyMode.NONE) {
21+
bindingInflater.invoke(layoutInflater)
22+
}
2123

2224
fun <T : ViewBinding> Fragment.viewBinding(viewBindingFactory: (View) -> T, disposeRecyclerViewsAutomatically: Boolean = true) =
23-
FragmentViewBindingDelegate(this, viewBindingFactory, disposeRecyclerViewsAutomatically)
25+
FragmentViewBindingDelegate(this, viewBindingFactory, disposeRecyclerViewsAutomatically)
2426

2527

2628
fun <T : ViewBinding> globalViewBinding(viewBindingFactory: (View) -> T) =
27-
GlobalViewBindingDelegate(viewBindingFactory)
29+
GlobalViewBindingDelegate(viewBindingFactory)
2830

2931
internal fun ensureMainThread() {
3032
if (Looper.myLooper() != Looper.getMainLooper()) {
@@ -39,4 +41,16 @@ fun ViewBinding?.disposeRecyclers() {
3941
it.adapter = null
4042
}
4143
}
44+
}
45+
46+
fun ViewBinding.gone() {
47+
root.isVisible = false
48+
}
49+
50+
fun ViewBinding.show() {
51+
root.isVisible = true
52+
}
53+
54+
fun ViewBinding.invisible() {
55+
root.isInvisible = true
4256
}

0 commit comments

Comments
 (0)