Skip to content

Commit

Permalink
Optimized the exception message of Fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCaiCoding committed Jan 4, 2022
1 parent 8f83a68 commit 83a27bb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FragmentBindingProperty<VB : ViewBinding>(private val clazz: Class<VB>) :
if (binding is ViewDataBinding) binding.lifecycleOwner = thisRef.viewLifecycleOwner
}
} catch (e: IllegalStateException) {
throw IllegalStateException("The binding property has been destroyed.")
throw IllegalStateException("The property of ${property.name} has been destroyed.")
}
}

Expand All @@ -55,7 +55,7 @@ class FragmentInflateBindingProperty<VB : ViewBinding>(private val clazz: Class<
binding = (clazz.getMethod("inflate", LayoutInflater::class.java).invoke(null, thisRef.layoutInflater) as VB)
.also { binding -> if (binding is ViewDataBinding) binding.lifecycleOwner = thisRef.viewLifecycleOwner }
} catch (e: IllegalStateException) {
throw IllegalStateException("The binding property has been destroyed.")
throw IllegalStateException("The property of ${property.name} has been destroyed.")
}
thisRef.viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.dylanc.viewbinding

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FragmentBindingDelegate<VB : ViewBinding>(private val bind: (View) -> VB)
if (binding is ViewDataBinding) binding.lifecycleOwner = thisRef.viewLifecycleOwner
}
} catch (e: IllegalStateException) {
throw IllegalStateException("The binding property has been destroyed.")
throw IllegalStateException("The property of ${property.name} has been destroyed.")
}
return binding
}
Expand All @@ -55,7 +55,7 @@ class FragmentInflateBindingDelegate<VB : ViewBinding>(private val inflate: (Lay
if (binding is ViewDataBinding) binding.lifecycleOwner = thisRef.viewLifecycleOwner
}
} catch (e: IllegalStateException) {
throw IllegalStateException("The binding property has been destroyed.")
throw IllegalStateException("The property of ${property.name} has been destroyed.")
}
thisRef.viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
Expand Down

0 comments on commit 83a27bb

Please sign in to comment.