rive-app/rive-ios

Syncronously render the first animation frame for snapshot tests

Opened this issue · 0 comments

jaanus commented

Description

Rive animations don’t render their content for snapshot tests, for example when using Pointfreeco snapshot-testing.

Provide a Repro

It happens with any Rive animation. For example:

public struct RiveAnimationView: View {
  let riveFileData: Data

  public init(riveFileData: Data) {
    self.riveFileData = riveFileData
  }

  public var body: some View {
    RiveViewModel(
      RiveModel(
        riveFile: try! RiveFile(
          byteArray: [UInt8](riveFileData)
        )
      )
    )
    .view()
  }
}

Here is a complete example project where you can observe the bug: BlankRiveSnapshot.zip

Observed behavior

Rive animation is not rendered for the snapshot test. The view is simply blank.

Expected behavior

Rive animation should be rendered with its first frame visible on the snapshot test.

Additional context

I guess it happens because Rive internally works mostly asynchronously and non-blocking, which makes sense in a real app. It would be helpful to make this work somehow, even if it means modifying the Rive runtime behavior or environment. E.g. with my snapshot tests, I could pass in some extra parameter or environment to Rive, to make it render its first frame synchronously for the snapshot test.