@@ -7,7 +7,6 @@ A set of Kotlin extensions for dealing with ViewBinding.
7
7
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
8
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
9
10
-
11
10
- [ Installation] ( #installation )
12
11
- [ Usage] ( #usage )
13
12
- [ Delegate] ( #delegate )
@@ -19,30 +18,27 @@ A set of Kotlin extensions for dealing with ViewBinding.
19
18
## Installation
20
19
21
20
Add the dependency:
22
- ``` groovy
21
+
22
+ ``` kotlin
23
23
repositories {
24
24
mavenCentral()
25
25
google()
26
26
}
27
27
28
28
dependencies {
29
- implementation("com.redmadrobot.extensions:viewbinding-ktx:4.1.2-2 ")
29
+ implementation(" com.redmadrobot.extensions:viewbinding-ktx:4.2.1-0 " )
30
30
}
31
31
```
32
32
33
33
Enable ViewBinding in build script:
34
- ``` groovy
35
- android {
36
- // For Android Gradle Plugin 3.6
37
- viewBinding.isEnabled = true
38
34
35
+ ``` kotlin
36
+ android {
39
37
// For Android Gradle Plugin 4.0+
40
38
buildFeatures.viewBinding = true
41
- }
42
39
43
- // Optional: disable synthetics for views, keep only parcelize
44
- androidExtensions {
45
- features = ["parcelize"]
40
+ // For Android Gradle Plugin prior to 3.6
41
+ viewBinding.isEnabled = true
46
42
}
47
43
```
48
44
@@ -53,6 +49,7 @@ androidExtensions {
53
49
For Fragments' layouts use ` ViewBinding ` delegate.
54
50
Resulting binding bounded to Fragment View's lifecycle.
55
51
It will be cleared after ` onDestroyView ` .
52
+
56
53
``` kotlin
57
54
class ProfileFragment : Fragment (R .layout.fragment_profile) {
58
55
@@ -71,6 +68,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
71
68
### Extensions
72
69
73
70
Inflate ` ViewBinding ` using ` LayoutInflater ` :
71
+
74
72
``` kotlin
75
73
class PickDateFragment : DialogFragment () {
76
74
@@ -88,6 +86,7 @@ class PickDateFragment : DialogFragment() {
88
86
```
89
87
90
88
Inflate ` ViewBinding ` using ` Context ` :
89
+
91
90
``` kotlin
92
91
fun createDetailsView (card : Card ): MaterialTextView {
93
92
return requireContext().inflateViewBinding<ViewCardDetailsBinding >().apply {
@@ -98,6 +97,7 @@ fun createDetailsView(card: Card): MaterialTextView {
98
97
```
99
98
100
99
Inflate ` ViewBinding ` and attach it to ` ViewGroup ` :
100
+
101
101
``` kotlin
102
102
class ErrorView @JvmOverloads constructor(
103
103
context : Context ,
@@ -110,6 +110,7 @@ class ErrorView @JvmOverloads constructor(
110
110
```
111
111
112
112
Obtain ` ViewBinding ` from inflated view:
113
+
113
114
``` kotlin
114
115
class TransactionsItem : Item {
115
116
@@ -127,6 +128,7 @@ class TransactionsItem : Item {
127
128
```
128
129
129
130
## Contributing
131
+
130
132
Merge requests are welcome.
131
133
For major changes, please open an issue first to discuss what you would like to change.
132
134
0 commit comments