Skip to content

Rive Button with state not working well when in a lazy scrollview #395

@rob-howard

Description

@rob-howard

Description

I am implementing a button in a large scrollview LazyVStack that contains a button similar to a heart / like button for content.

I'm not sure if this is a Rive issue or an understanding issue on my part.

When the user taps the button, it will toggle state. Which seems to be working.

The issue is happens upon view loading, it does not seem to initialize in the proper state.

Provide a Repro

LazyVStack {
RiveLikeButtonView(fileName: fileName, text: "100", isLiked: isLiked) {
toggle()
}.id(1)
RiveLikeButtonView(fileName: fileName, text: "100", isLiked: isLiked) {
toggle()
}.id(2)
RiveLikeButtonView(fileName: fileName, text: "100", isLiked: isLiked) {
toggle()
}.id(3)
///.... a bunch of times to make it render off screen
}

Not working:

riveViewModel.view()
.onAppear {
print("on appear: (isLiked)")

                    // riveViewModel.setInput("hasLiked", value: isLiked)
                    // riveViewModel.reset()
                    riveViewModel.setInput("hasLiked", value: isLiked)
                }

Working: but not exactly sure why?

riveViewModel.view()
.onAppear {
print("on appear: (isLiked)")

                    riveViewModel.setInput("hasLiked", value: isLiked)
                    riveViewModel.reset()
                    riveViewModel.setInput("hasLiked", value: isLiked)
                }

Expected behavior

The state of the input for hasLiked to be reflected in the animation state machine.

Screenshots

actual: icons don't start in the proper state:

Image

expected: icons in the proper state:

Image

Device & Versions (please complete the following information)

  • Device: ios simulator + live devices
  • iOS version ios 17, 18 +

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions