2

I have a main compose with a scaffold, top app bar, FAB, navigation bar. Then I have a couple of composable screens I can navigate to and the navigation animation is working fine, which means the default fade in, fade out of Accompanist Navigation Animation.

Then I have another screen, let's call it B, which has its own scaffold and top app bar. Whenever I navigate to that screen B, the content of the main screen weirdly jump up quickly before fading out. And when I come back, the content of screen B moves down quickly before fading out.

Is there a way to force the content to stay in place? I guess it as to do with navigating from a scaffold to another one.

DeKekem
  • 589
  • 10
  • 20

2 Answers2

0

I have come upon this situation or something similar, and I suspect there is something about having Scaffold inside NavHost; my first thought is to have it the other way around, so NavHost inside Scaffold, as per the official docs.

gabiteris
  • 346
  • 1
  • 3
  • 5
0

I'm not using Accompanist, but its navigation animation APIs have been copied to androidx.navigation:navigation-compose:2.7.0. This bug remained. There is a recent issue on issuetracker, where I may have found the problem.

Make sure that your screens take the entire size of the parent, e.g. Modifier.fillMaxSize(). This is because guys at Google didn't override the default SizeTransform argument in ContentTransform's primary constructor, which goes like this:

fun SizeTransform(
    clip: Boolean = true,
    sizeAnimationSpec: (initialSize: IntSize, targetSize: IntSize) -> FiniteAnimationSpec<IntSize> =
        { _, _ ->
            spring(
                stiffness = Spring.StiffnessMediumLow,
                visibilityThreshold = IntSize.VisibilityThreshold
            )
        }
): SizeTransform = SizeTransformImpl(clip, sizeAnimationSpec)

So there you have your jumping - it's because your screen content could be changing in size. You didn't provide any code, so it's hard to say for sure.

Calamity
  • 700
  • 7
  • 23