Skip to content

Commit

Permalink
Merge pull request #6 from bayu07750/development/delta
Browse files Browse the repository at this point in the history
set binding to null prevent memory leak
  • Loading branch information
yzzzd authored May 31, 2022
2 parents ffc6f85 + 85fdbf8 commit fce8132
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/src/main/java/com/crocodic/core/base/fragment/CoreFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ import androidx.fragment.app.Fragment
import com.crocodic.core.helper.ImagePreviewHelper
import com.crocodic.core.helper.util.ClickPrevention

abstract class CoreFragment<VB : ViewDataBinding>(@LayoutRes private val layoutRes: Int): Fragment(), ClickPrevention {
abstract class CoreFragment<VB : ViewDataBinding>(@LayoutRes private val layoutRes: Int) :
Fragment(), ClickPrevention {

protected lateinit var binding: VB
private var _binding: VB? = null
protected val binding get() = _binding!!

open var title: String = ""
open var hasLoadedOnce = false

val imagePreview by lazy { context?.let { ImagePreviewHelper(it) } }

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
binding.lifecycleOwner = this
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

0 comments on commit fce8132

Please sign in to comment.