Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Check if fragment is added before accessing viewLifecycleOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wong committed Oct 13, 2021
1 parent 9eec743 commit 65426ff
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class TransferCodePagerFragment : Fragment(R.layout.fragment_transfer_code_pager
// Before that call, the fragment root will be measured with the entire screen size and not the reduced viewpager size
view.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
vaccinationHintViewModel.displayVaccinationHint.observe(viewLifecycleOwner) { shouldDisplayVaccinationHint ->
displayVaccinationHint(shouldDisplayVaccinationHint)
if (isAdded) {
vaccinationHintViewModel.displayVaccinationHint.observe(viewLifecycleOwner) { shouldDisplayVaccinationHint ->
displayVaccinationHint(shouldDisplayVaccinationHint)
}
}

view.viewTreeObserver.removeOnGlobalLayoutListener(this)
Expand Down

0 comments on commit 65426ff

Please sign in to comment.