Skip to content
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

Avoid reapplying all RepeatingChangeEffectModifier changes in each onAppear #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonasrottmann
Copy link

@jonasrottmann jonasrottmann commented Mar 17, 2024

When using an effect as RepeatingChangeEffectModifier inside a lazy stack, it is possible that onAppear is called multiple times when the view comes back to being visible. That would cause the shine effect to repeat RepeatingChangeEffectModifier.timer.count times when becoming visible again. This PR tries to fix this by pausing/resetting the timer count when the view disappears. I hope this is the correct way to solve this 🙂

ScrollView {
    LazyVStack {
        ForEach(0...50, id: \.self) { _ in
            Button { } label: {
                Label("Shine", systemImage: "sun.horizon.fill")
            }
            .buttonStyle(.borderedProminent)
            .controlSize(.large)
            .conditionalEffect(.repeat(.shine, every: .seconds(1)), condition: true)
        }
    }
}
demo.mov

@jonasrottmann jonasrottmann changed the title Avoid reapplying all RepeatingChangeEffectModifier changes in second onAppear Avoid reapplying all RepeatingChangeEffectModifier changes in each onAppear Mar 17, 2024
@mergesort
Copy link
Collaborator

Hey @jonasrottmann, sorry for the delayed reply — I was very heads down on shipping my app and hadn't had the time to look this change over. I reached out to @robb to see if this change could have any side effects and he mentioned that this may cause problems due to ScrollView visibility, two views could get out of sync if one of them scrolled offscreen. I don't have a fix in mind to account for that, but I wanted to note that there may be another layer of consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants