Skip to content

Commit 64ed3ca

Browse files
Update ViewBinding.kt
1 parent ebaa82d commit 64ed3ca

File tree

1 file changed

+6
-7
lines changed
  • viewbinding-nonreflection/src/main/java/com/dylanc/viewbinding/nonreflection

1 file changed

+6
-7
lines changed

viewbinding-nonreflection/src/main/java/com/dylanc/viewbinding/nonreflection/ViewBinding.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,23 @@ class FragmentBindingDelegate<VB : ViewBinding>(
6666
) : ReadOnlyProperty<Fragment, VB> {
6767

6868
private var lifecycleObserver: LifecycleObserver? = null
69-
private var _binding: VB? = null
70-
private val binding: VB get() = _binding!!
69+
private var binding: VB? = null
7170

7271
@Suppress("UNCHECKED_CAST")
7372
override fun getValue(thisRef: Fragment, property: KProperty<*>): VB {
7473
if (lifecycleObserver == null) {
7574
lifecycleObserver = object : LifecycleObserver {
7675
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
7776
fun onDestroyView() {
78-
_binding = null
77+
binding = null
7978
}
8079
}.also {
8180
thisRef.viewLifecycleOwner.lifecycle.addObserver(it)
8281
}
8382
}
84-
if (_binding == null) {
85-
_binding = bind(thisRef.requireView())
83+
if (binding == null) {
84+
binding = bind(thisRef.requireView())
8685
}
87-
return binding
86+
return binding!!
8887
}
89-
}
88+
}

0 commit comments

Comments
 (0)