markiv / SwiftUI-Shimmer

Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, macOS, tvOS, watchOS and visionOS.
MIT License
1.04k stars 60 forks source link

Prevent shimmer animation from affecting initial layout of the view #20

Closed ast3150 closed 5 months ago

ast3150 commented 7 months ago

This introduces two changes:

  1. Prevents the shimmer animation from propagating to the modified view
  2. Delays the initial animation until the layout of the view is established so that the initial appearance of the view is not animated.

Fixes #19

ikok07 commented 7 months ago

It's working great with this fix! Thank you :)

vladyslavsosiuk commented 7 months ago

hi @ast3150 could you check if the prior pr fixes the issue you are addressing for you?

Mr-Fier-1 commented 7 months ago

@vladyslavsosiuk This prior pr fix, doesnt fix this Animation bug #19.

vladyslavsosiuk commented 7 months ago

Do you have steps to reproduce?

Mr-Fier-1 commented 7 months ago

Sure!

import Shimmer
import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {  // Use NavigationStack here 
            VStack {
                Text("NavigationView")
                secondView()
            }
        }
    }
}

struct secondView: View {
    var body: some View {
        RoundedRectangle(cornerRadius: 15)
            .foregroundStyle(.red)
            .frame(width: 50, height: 50)

            .shimmering()
        Text("This is the second View")
            .redacted(reason: .placeholder)
            .shimmering()
    }
}

In my case the NavigationView and NavigationStack conflicted with the modifier. When NavigationView was used this happened:

https://github.com/markiv/SwiftUI-Shimmer/assets/83609361/c482dfe9-9260-4dbb-8d7d-67fd442187ef

and with NavigationStack this:

https://github.com/markiv/SwiftUI-Shimmer/assets/83609361/1c58a4d6-dc81-4bf9-9ad2-901245ad2429

When using the changes from this MR, the visuals are as expected.

daniel-tandem commented 7 months ago

This PR fixes the issue I was seeing where I was trying to apply a shimmer on a view within a NavigationStack

markiv commented 5 months ago

Prevent shimmer animation from affecting initial layout of the view