Skip to content

UI stops recomposing after first test when using animations in lifecycle coroutine scope #1867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
saket opened this issue Mar 10, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@saket
Copy link
Collaborator

saket commented Mar 10, 2025

Description
When paparazzi's injected lifecycle is used for launching an animation with a frame clock, the UI stops recomposing in subsequent tests. Since paparazzi shares the same renderer instance across all tests, could some important state be failing to reset correctly?

Steps to Reproduce
When the two tests in the following code are run, they'll produce two animated snapshots using identical code. The first one will display an animated counter whereas the second one will remain stuck at 0.

class FooTest {
  @get:Rule
  val paparazzi = Paparazzi()

  @Test fun first() {
    takeSnapshot()
  }

  @Test fun second() {
    takeSnapshot()
  }

  private fun takeSnapshot() {
    paparazzi.gif {
      val counter by produceState(initialValue = 0) {
        while (isActive) {
          delay(100)
          this.value += 1
          println("writing value = ${this.value}")
        }
      }

      SideEffect {
        println("reading value = $counter")
      }

      val lifecycleOwner = LocalLifecycleOwner.current
      DisposableEffect(Unit) {
        val animatable = Animatable(0f)
        onDispose {
          lifecycleOwner.lifecycle.coroutineScope.launch {
            withContext(AndroidUiDispatcher.Main) {
              animatable.animateTo(1f)
            }
          }
        }
      }

      Text(
        modifier = Modifier
          .fillMaxSize()
          .background(Color(0xFF073858))
          .padding(16.dp),
        text = "Counter = $counter",
        color = Color.Yellow,
      )
    }
  }
}

Additional information:

  • Paparazzi Version: 1d2e1db
  • OS: macOS
  • Compile SDK: 35
  • Gradle Version: 8.12.1
  • Android Gradle Plugin Version: 8.8.1
@saket saket added the bug Something isn't working label Mar 10, 2025
@geoff-powell geoff-powell added this to the 2.0.0-alpha02 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants