Skip to content

Instantly share code, notes, and snippets.

@addeeandra
Created March 13, 2022 10:49
Show Gist options
  • Save addeeandra/3ff2ea049d46248c2020af872171c88f to your computer and use it in GitHub Desktop.
Save addeeandra/3ff2ea049d46248c2020af872171c88f to your computer and use it in GitHub Desktop.
ViewStubBehavior Usage
// might be called from Activity.onCreate or Fragment.onViewCreated
override fun setupViews() {
// setup stub behavior on sales
ViewStubBehavior.setup(
viewBinding.flSales,
viewBinding.stubSales,
viewBinding.scrollContainer
) { _, view ->
val stubBinding = DataBindingUtil.bind<ViewSectionSalesBinding>(view)
stubBinding?.lifecycleOwner = this
stubBinding?.viewmodel = viewModel
stubBinding?.executePendingBindings()
viewModel.fetchSales()
}
// setup stub behavior on inventories
ViewStubBehavior.setup(
viewBinding.flInventories,
viewBinding.stubInventories,
viewBinding.scrollContainer
) { _, view ->
val stubBinding = DataBindingUtil.bind<ViewSectionInventoriesBinding>(view)
stubBinding?.lifecycleOwner = this
stubBinding?.viewmodel = viewModel
stubBinding?.executePendingBindings()
viewModel.fetchInventories()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment