Created
April 17, 2019 13:42
-
-
Save pandulapeter/d8f2c0da14cc9259053911d7283e96e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseFragment<B : ViewDataBinding, VM : BaseViewModel>(@LayoutRes private val layoutResourceId: Int) : Fragment() { | |
| protected var binding by AutoClearedValue<B>() | |
| protected abstract val viewModel: VM | |
| final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = | |
| DataBindingUtil.inflate<B>(inflater, layoutResourceId, container, false).also { | |
| binding = it | |
| }.root | |
| @CallSuper | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| binding.lifecycleOwner = viewLifecycleOwner | |
| binding.setVariable(BR.viewModel, viewModel) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment