Created
December 21, 2017 12:38
-
-
Save chris-horner/747dba2cf30194b58881f182c1373b87 to your computer and use it in GitHub Desktop.
Extension function forcing a shared element to run in a ViewGroup overlay.
This file contains 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
fun Transition.sharedElementsInOverlay(container: ViewGroup, start: View, end: View): Transition = | |
addListener(object : Transition.TransitionListener { | |
val endParent = end.parent as ViewGroup | |
val endOriginalPosition = endParent.indexOfChild(end) | |
override fun onTransitionStart(transition: Transition) { | |
start.visibility = View.GONE | |
container.overlay.add(start) | |
container.overlay.add(end) | |
} | |
override fun onTransitionEnd(transition: Transition) { | |
container.overlay.remove(start) | |
container.overlay.remove(end) | |
if (endParent.isAttachedToWindow) { | |
if (endOriginalPosition <= endParent.childCount) { | |
endParent.addView(end, endOriginalPosition) | |
} else { | |
endParent.addView(end) | |
} | |
} | |
} | |
override fun onTransitionResume(transition: Transition) {} | |
override fun onTransitionPause(transition: Transition) {} | |
override fun onTransitionCancel(transition: Transition) {} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment