From 4223fb3ada4ebf4bf7550e0777dac315c7f6878f Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 16 Oct 2025 17:25:12 +1300 Subject: [PATCH 1/3] Replace onAppear with task for animation toggle --- Sources/SkeletonUI/Modifiers/SkeletonModifier.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift index 8b2b96a..ec3dc7b 100644 --- a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift +++ b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift @@ -13,10 +13,9 @@ public struct SkeletonModifier: ViewModifier { .modifier(SkeletonAnimatableModifier(animate ? 1 : 0, appearance)) .clipShape(SkeletonShape(shape)) .animation(animation.type, value: animate) - .onAppear { - DispatchQueue.main.async { - animate.toggle() - } + .task { + guard !animate else { return } + animate.toggle() } } } From 35e2de7600863068782695bda1c43d0ebefd9f2e Mon Sep 17 00:00:00 2001 From: Henry Storch Date: Fri, 17 Oct 2025 08:53:27 +1300 Subject: [PATCH 2/3] Add fallback support for iOS <16 --- Sources/SkeletonUI/Modifiers/SkeletonModifier.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift index ec3dc7b..2a8deef 100644 --- a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift +++ b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift @@ -13,9 +13,20 @@ public struct SkeletonModifier: ViewModifier { .modifier(SkeletonAnimatableModifier(animate ? 1 : 0, appearance)) .clipShape(SkeletonShape(shape)) .animation(animation.type, value: animate) - .task { + .startOnce { guard !animate else { return } animate.toggle() } } } + +extension View { + @ViewBuilder + func startOnce(_ action: @escaping () -> Void) -> some View { + if #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) { + self.task { action() } + } else { + self.onAppear { DispatchQueue.main.async { action() } } + } + } +} From cd2adc5f748081a3539cca2d478f97ca8542d596 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 20 Oct 2025 11:41:00 +1300 Subject: [PATCH 3/3] Update SkeletonModifier.swift Use withAnimation instead of implicit animation --- Sources/SkeletonUI/Modifiers/SkeletonModifier.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift index 2a8deef..7458891 100644 --- a/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift +++ b/Sources/SkeletonUI/Modifiers/SkeletonModifier.swift @@ -12,10 +12,11 @@ public struct SkeletonModifier: ViewModifier { content .modifier(SkeletonAnimatableModifier(animate ? 1 : 0, appearance)) .clipShape(SkeletonShape(shape)) - .animation(animation.type, value: animate) .startOnce { guard !animate else { return } - animate.toggle() + withAnimation(animation.type) { + animate.toggle() + } } } }