From 394183720a2579a07cba7d1e52cb21570a3b4fa0 Mon Sep 17 00:00:00 2001 From: Alain Stulz Date: Wed, 15 Nov 2023 14:37:13 +0100 Subject: [PATCH 1/2] Prevent shimmer animation from affecting the initial layout cycle of the view --- Sources/Shimmer/Shimmer.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Shimmer/Shimmer.swift b/Sources/Shimmer/Shimmer.swift index de93ea7..0a3fc49 100644 --- a/Sources/Shimmer/Shimmer.swift +++ b/Sources/Shimmer/Shimmer.swift @@ -82,10 +82,15 @@ public struct Shimmer: ViewModifier { public func body(content: Content) -> some View { content + .animation(nil, value: false) // Prevent animation from propagating to the modified view .mask(LinearGradient(gradient: gradient, startPoint: startPoint, endPoint: endPoint)) .animation(animation, value: isInitialState) .onAppear { - isInitialState = false + // Delay the animation until the initial layout is established + // to prevent animating the appearance of the view + DispatchQueue.main.asyncAfter(deadline: .now()) { + isInitialState = false + } } } } From 4290558c09e554bd5f7b9c87e0a44fd1dcd3b412 Mon Sep 17 00:00:00 2001 From: Alain Stulz Date: Thu, 25 Jan 2024 13:37:06 +0100 Subject: [PATCH 2/2] Remove animation(nil) because it's not strictly necessary --- Sources/Shimmer/Shimmer.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Shimmer/Shimmer.swift b/Sources/Shimmer/Shimmer.swift index 0a3fc49..3ed6755 100644 --- a/Sources/Shimmer/Shimmer.swift +++ b/Sources/Shimmer/Shimmer.swift @@ -82,7 +82,6 @@ public struct Shimmer: ViewModifier { public func body(content: Content) -> some View { content - .animation(nil, value: false) // Prevent animation from propagating to the modified view .mask(LinearGradient(gradient: gradient, startPoint: startPoint, endPoint: endPoint)) .animation(animation, value: isInitialState) .onAppear {