I am trying to add a shared element transition to my fragment which will create something like a centered logo to top. I did this successfully with shared element transition but the logo also applies some window inset. The problem in that only after the shared element transition finished does the window inset gets applied. This make it looks like the views jump to their final position.
I am using the code below.
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = layoutInflater?.inflate(R.layout.onboarding_layout, container, false)
return view
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
ViewCompat.setOnApplyWindowInsetsListener(appimageviewLogo) { view, insets ->
val params = view.layoutParams as ViewGroup.MarginLayoutParams
params.topMargin = params.topMargin + insets.systemWindowInsetTop
insets
}
ViewCompat.setOnApplyWindowInsetsListener(appbuttonSkip) { view, insets ->
val params = view.layoutParams as ViewGroup.MarginLayoutParams
params.bottomMargin = params.bottomMargin + insets.systemWindowInsetBottom
insets.consumeSystemWindowInsets()
}
ViewCompat.requestApplyInsets(appimageviewLogo)
ViewCompat.requestApplyInsets(appbuttonSkip)
}
can someone help me here?
How can I apply the window inset first before performing the Shared element transition so the "jumping" wont occur?
So basically I'll answer my own question. The solution was to postpone the enterTransition of the incoming fragment then request the window inset then start the postponedEnterTransition.
I got all this from the post by Andranik Azizbekian at Medium. You can look at his post here about window insets here and here is the link for my questions and his answer to those questions. :)
Note: In order for postpone enter transition to work for fragments, setReorderingAllowed must be set true with the FragmentTransaction.