Skip to content

Commit

Permalink
Restore state of ReaderPostDetailFragment on onViewCreated instead of…
Browse files Browse the repository at this point in the history
… onActivityCreated

This fixes wordpress-mobile#14195
`onActivityCreated` is called after `onViewCreated`, so the state was being restored
after the view was ready and the post was already loaded with the wrong id.
  • Loading branch information
dnalves committed Sep 19, 2021
1 parent 5390201 commit fd41a74
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ class ReaderPostDetailFragment : ViewPagerFragment(),

initLikeFacesRecycler(savedInstanceState)
initViewModel(binding, savedInstanceState)
restoreState(savedInstanceState)
setHasOptionsMenu(true)

showPost()
}
Expand Down Expand Up @@ -841,12 +843,6 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
super.onSaveInstanceState(outState)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
restoreState(savedInstanceState)
}

private fun restoreState(savedInstanceState: Bundle?) {
savedInstanceState?.let {
blogId = it.getLong(ReaderConstants.ARG_BLOG_ID)
Expand Down

0 comments on commit fd41a74

Please sign in to comment.