File tree 2 files changed +8
-0
lines changed
viewbinding-ktx/src/main/java/com/dylanc/viewbinding
viewbinding-nonreflection-ktx/src/main/java/com/dylanc/viewbinding/nonreflection
2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,16 @@ import androidx.viewbinding.ViewBinding
23
23
import com.google.android.material.tabs.TabLayout
24
24
25
25
inline fun <reified VB : ViewBinding > TabLayout.Tab.setCustomView (block : VB .() -> Unit ) {
26
+ requireNotNull(parent) { " Tab not attached to a TabLayout" }
26
27
inflateBinding<VB >(LayoutInflater .from(parent!! .context)).apply (block).let { binding ->
27
28
customView = binding.root
28
29
customView?.tag = binding
29
30
}
30
31
}
31
32
33
+ inline fun <reified VB : ViewBinding > TabLayout.updateCustomTab (index : Int , block : VB .() -> Unit ) =
34
+ getTabAt(index)?.customView?.getBinding<VB >()?.also (block)
35
+
32
36
inline fun <reified VB : ViewBinding > TabLayout.doOnCustomTabSelected (
33
37
crossinline onTabUnselected : VB .(TabLayout .Tab ) -> Unit = {},
34
38
crossinline onTabReselected : VB .(TabLayout .Tab ) -> Unit = {},
Original file line number Diff line number Diff line change @@ -24,9 +24,13 @@ import androidx.viewbinding.ViewBinding
24
24
import com.google.android.material.tabs.TabLayout
25
25
26
26
fun <VB : ViewBinding > TabLayout.Tab.setCustomView (inflate : (LayoutInflater ) -> VB , block : VB .() -> Unit ) {
27
+ requireNotNull(parent) { " Tab not attached to a TabLayout" }
27
28
customView = inflate(LayoutInflater .from(parent!! .context)).apply (block).root
28
29
}
29
30
31
+ fun <VB : ViewBinding > TabLayout.updateCustomTab (bind : (View ) -> VB , index : Int , block : VB .() -> Unit ) =
32
+ getTabAt(index)?.customView?.getBinding(bind)?.also (block)
33
+
30
34
fun <VB : ViewBinding > TabLayout.doOnCustomTabSelected (
31
35
bind : (View ) -> VB ,
32
36
onTabUnselected : (VB .(TabLayout .Tab ) -> Unit )? = null,
You can’t perform that action at this time.
0 commit comments