Fix image viewer & transitions (#1448)
This commit is contained in:
parent
d13a341a35
commit
a3fa0647b6
2 changed files with 69 additions and 19 deletions
|
@ -16,6 +16,7 @@ class ImagePagerAdapter(
|
|||
) : FragmentStatePagerAdapter(fragmentManager), SharedElementTransitionListener {
|
||||
|
||||
private var primaryItem: ViewMediaFragment? = null
|
||||
private var didTransition = false
|
||||
|
||||
override fun setPrimaryItem(container: ViewGroup, position: Int, item: Any) {
|
||||
super.setPrimaryItem(container, position, item)
|
||||
|
@ -24,7 +25,14 @@ class ImagePagerAdapter(
|
|||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return if (position >= 0 && position < attachments.size) {
|
||||
ViewMediaFragment.newInstance(attachments[position], position == initialPosition)
|
||||
// Fragment should not wait for or start transition if it already happened but we
|
||||
// instantiate the same fragment again, e.g. open the first photo, scroll to the
|
||||
// forth photo and then back to the first. The first fragment will trz to start the
|
||||
// transition and wait until it's over and it will never take place.
|
||||
ViewMediaFragment.newInstance(
|
||||
attachment = attachments[position],
|
||||
shouldStartPostponedTransition = !didTransition && position == initialPosition
|
||||
)
|
||||
} else {
|
||||
throw IllegalStateException()
|
||||
}
|
||||
|
@ -39,6 +47,7 @@ class ImagePagerAdapter(
|
|||
}
|
||||
|
||||
override fun onTransitionEnd() {
|
||||
this.didTransition = true
|
||||
primaryItem?.onTransitionEnd()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue