https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
j

Javier

07/13/2022, 1:25 PM
Is it possible to indicate to Paparazzi to wait a few milliseconds to record the snapshot (I am showing an snackbar in Compose and Paparazzi can't get it)
b

Benoit Quenaudon

07/13/2022, 1:35 PM
I'm afk but there's a method where you can set the time you wanna start capturing. That might be the gif method. You can take only one frame later on kinda truck
j

Javier

07/13/2022, 1:47 PM
Yeah, but gif is not compatible with compose
b

Benoit Quenaudon

07/13/2022, 1:55 PM
Try something like
paparazzi.gif(view, start = 500L, end = 500L, fps = 1)
j

Javier

07/13/2022, 1:59 PM
I can't, I haven't a View with Compose
b

Benoit Quenaudon

07/13/2022, 2:01 PM
You cannot what?
j

Javier

07/13/2022, 2:02 PM
I haven't a View, I have a composable, I can't use it with
gif
method
it only accepts
View
b

Benoit Quenaudon

07/13/2022, 2:04 PM
Copy code
fun snapshot(name: String? = null, composable: @Composable () -> Unit) {
    val hostView = ComposeView(context)
    // During onAttachedToWindow, AbstractComposeView will attempt to resolve its parent's
    // CompositionContext, which requires first finding the "content view", then using that to
    // find a root view with a ViewTreeLifecycleOwner
    val parent = FrameLayout(context).apply { id = android.R.id.content }
    parent.addView(hostView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
    PaparazziComposeOwner.register(parent)
    hostView.setContent(composable)
    snapshot(parent, name)

    forceReleaseComposeReferenceLeaks()
  }
You can try to copy the hack it’s doing and pass the view to the gif method
👍 1
j

Javier

07/13/2022, 2:05 PM
I will try, thank you :)
y

yschimke

07/24/2022, 10:28 AM
I tried a PR for this https://github.com/cashapp/paparazzi/pull/509, but my impression is that it surfaces a bunch of areas that integration with compose is still needed.
State changes, Launched effects, all didn't act predictably.
A 5 second video completes in 300ms (although the first test takes a 10 second hit form classloading?
The 300ms video doesn't ever get to a LaunchedEffect during the 5 second capture, while the slow run processes a launched effect after 2.5 seconds.
j

Javier

07/24/2022, 10:47 AM
Thank you :) subscribed to all issues. I am not using launchedeffect as I delegate everything to the viewModel, if there is an snapshot I could try it next week
y

yschimke

07/24/2022, 11:04 AM
No idea, I'm external contributor. They will probably reject my PR as it would create juts more bugs raised for now.
👍 1
You may not use things like launched effects bit animations, or in my case a wear specific LazyColumn do. So things may or may not work.
As @Benoit Quenaudon said, you can copy the hack, hopefully it just works for you.
👍 1
j

Javier

11/04/2022, 4:18 PM
@Benoit Quenaudon sorry for my late reply, I tried it, a tons of images are created and a video too, but there is no animation. I tried to increase to 3 seconds but no luck, no animation is shown.
b

Benoit Quenaudon

11/04/2022, 8:27 PM
Sorry I cannot help more than that. The best try would be to have a repro test and attach it to an issue on the github repo
j

Javier

11/04/2022, 8:28 PM
I think it is better to get an official integration, but it is blocked as @yschimke mentioned on the issue. How is Square testing animations with Paparazzi? instead of testing an animation, setting a frame where the composable is visible (for example a snackbar)?
316 Views