File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed
app/src/main/java/com/dylanc/viewbinding/sample/widget
viewbinding-ktx/src/main/java/com/dylanc/viewbinding
viewbinding-nonreflection-ktx/src/main/java/com/dylanc/viewbinding/nonreflection Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,11 @@ package com.dylanc.viewbinding.sample.widget
18
18
19
19
import android.content.Context
20
20
import android.util.AttributeSet
21
+ import android.view.LayoutInflater
21
22
import androidx.constraintlayout.widget.ConstraintLayout
22
23
import com.dylanc.viewbinding.binding
24
+ import com.dylanc.viewbinding.inflate
25
+ import com.dylanc.viewbinding.nonreflection.inflate
23
26
import com.dylanc.viewbinding.sample.R
24
27
import com.dylanc.viewbinding.sample.databinding.LayoutCustomViewBinding
25
28
@@ -29,7 +32,7 @@ import com.dylanc.viewbinding.sample.databinding.LayoutCustomViewBinding
29
32
class CustomView (context : Context , attrs : AttributeSet ? = null ) :
30
33
ConstraintLayout (context, attrs) {
31
34
32
- val binding: LayoutCustomViewBinding by binding ()
35
+ val binding = inflate< LayoutCustomViewBinding > ()
33
36
34
37
init {
35
38
binding.tvTitle.setText(R .string.show_loading_dialog)
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ inline fun <reified VB : ViewBinding> ViewGroup.binding(attachToParent: Boolean
59
59
inflateBinding<VB >(LayoutInflater .from(context), if (attachToParent) this else null , attachToParent)
60
60
}
61
61
62
+ inline fun <reified VB : ViewBinding > ViewGroup.inflate () =
63
+ inflateBinding<VB >(LayoutInflater .from(context), this , true )
64
+
62
65
inline fun <reified VB : ViewBinding > TabLayout.Tab.setCustomView (onBindView : VB .() -> Unit ) {
63
66
customView = inflateBinding<VB >(LayoutInflater .from(parent!! .context)).apply (onBindView).root
64
67
}
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ fun <VB : ViewBinding> ViewGroup.binding(
58
58
inflate(LayoutInflater .from(context), if (attachToParent) this else null , attachToParent)
59
59
}
60
60
61
+ inline fun <reified VB : ViewBinding > ViewGroup.inflate (inflate : (LayoutInflater , ViewGroup ? , Boolean ) -> VB ) =
62
+ inflate(LayoutInflater .from(context), this , true )
63
+
61
64
fun <VB : ViewBinding > TabLayout.Tab.setCustomView (
62
65
inflate : (LayoutInflater ) -> VB ,
63
66
onBindView : VB .() -> Unit
You can’t perform that action at this time.
0 commit comments