Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MontiniCristian/fc680f4b5db2346b9044e4905077d6e9 to your computer and use it in GitHub Desktop.
Save MontiniCristian/fc680f4b5db2346b9044e4905077d6e9 to your computer and use it in GitHub Desktop.
SharedElement ChangeHandler for Conductor
import android.os.Bundle
import android.transition.*
import android.view.View
import android.view.ViewGroup
import com.bluelinelabs.conductor.changehandler.SharedElementTransitionChangeHandler
import java.util.ArrayList
class MySharedElementTransitionChangeHandler : SharedElementTransitionChangeHandler {
private val names: ArrayList<String>
constructor() {
names = ArrayList()
}
constructor(waitForTransitionNames: List<String>) {
names = ArrayList(waitForTransitionNames)
}
override fun saveToBundle(bundle: Bundle) {
bundle.putStringArrayList(KEY_WAIT_FOR_TRANSITION_NAMES, names)
}
override fun restoreFromBundle(bundle: Bundle) {
val savedNames = bundle.getStringArrayList(KEY_WAIT_FOR_TRANSITION_NAMES)
if (savedNames != null) {
names.addAll(savedNames)
}
}
override fun getExitTransition(container: ViewGroup, from: View?, to: View?, isPush: Boolean): Transition? {
return if (isPush) {
AutoTransition()
} else {
Fade()
}
}
override fun getSharedElementTransition(
container: ViewGroup,
from: View?,
to: View?,
isPush: Boolean
): Transition? {
return TransitionSet().addTransition(ChangeBounds()).addTransition(ChangeClipBounds())
.addTransition(ChangeTransform()).setDuration(400)
}
override fun getEnterTransition(container: ViewGroup, from: View?, to: View?, isPush: Boolean): Transition? {
return if (isPush) {
Fade()
} else {
Fade()
}
}
override fun configureSharedElements(container: ViewGroup, from: View?, to: View?, isPush: Boolean) {
for (name in names) {
addSharedElement(name)
waitOnSharedElementNamed(name)
}
}
companion object {
private val KEY_WAIT_FOR_TRANSITION_NAMES = "MySharedElementTransitionChangeHandler.names"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment