Skip to content

Instantly share code, notes, and snippets.

@huan-nguyen
Last active September 28, 2018 12:10
Show Gist options
  • Select an option

  • Save huan-nguyen/0ec738d68484e49c3cf625a2c9e85279 to your computer and use it in GitHub Desktop.

Select an option

Save huan-nguyen/0ec738d68484e49c3cf625a2c9e85279 to your computer and use it in GitHub Desktop.
Updated code with tap position
override fun onViewCreated(view: View, savedState: Bundle?) {
super.onViewCreated(view, savedState)
tapPosition = savedState?.getInt(TAP_POSITION, NO_POSITION) ?: NO_POSITION
postponeEnterTransition()
...
}
...
private fun render(state: State) {
when (state) {
...
is Success -> {
...
(view?.parent as? ViewGroup)?.doOnPreDraw {
if (exitTransition == null) {
exitTransition = SlideExplode().apply {
duration = TRANSITION_DURATION
interpolator = transitionInterpolator
}
}
val layoutManager = emailList.layoutManager as LinearLayoutManager
layoutManager.findViewByPosition(tapPosition)?.let { view ->
view.getGlobalVisibleRect(viewRect)
(exitTransition as Transition).epicenterCallback =
object : Transition.EpicenterCallback() {
override fun onGetEpicenter(transition: Transition) = viewRect
}
}
startPostponedEnterTransition()
}
}
}
}
...
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(TAP_POSITION, tapPosition)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment