Hiya Ive been utilizing the identical shimmer modifier for some time now. I only recently up to date to the brand new IOS and the shimmer modifier now not works. I made certain nothing in my code was depreciated. Im not sure as to manner it now not capabilities, I assume it is because of new updates in the best way IOS animates issues. Id recognize some perception. Thanks.
import SwiftUI
public struct Shimmer: ViewModifier {
let animation: Animation
@State personal var section: CGFloat = 0
public init(animation: Animation = Self.defaultAnimation) {
self.animation = animation
}
public static let defaultAnimation = Animation.linear(period: 1.5).repeatForever(autoreverses: false)
public init(period: Double = 1.5, bounce: Bool = false, delay: Double = 0) {
self.animation = .linear(period: period)
.repeatForever(autoreverses: bounce)
.delay(delay)
}
public func physique(content material: Content material) -> some View {
content material
.modifier(
AnimatedMask(section: section).animation(animation)
)
.onAppear { section = 0.8 }
}
struct AnimatedMask: AnimatableModifier {
var section: CGFloat = 0
var animatableData: CGFloat {
get { section }
set { section = newValue }
}
func physique(content material: Content material) -> some View {
content material
.masks(GradientMask(section: section).scaleEffect(4))
}
}
struct GradientMask: View {
let section: CGFloat
let centerColor = Coloration.black
let edgeColor = Coloration.black.opacity(0.3)
@Surroundings(.layoutDirection) personal var layoutDirection
var physique: some View {
let isRightToLeft = layoutDirection == .rightToLeft
LinearGradient(
gradient: Gradient(stops: [
.init(color: edgeColor, location: phase),
.init(color: centerColor, location: phase + 0.1),
.init(color: edgeColor, location: phase + 0.2)
]),
startPoint: isRightToLeft ? .bottomTrailing : .topLeading,
endPoint: isRightToLeft ? .topLeading : .bottomTrailing
)
}
}
}
public extension View {
@ViewBuilder func shimmering(
energetic: Bool = true, period: Double = 1.5, bounce: Bool = false, delay: Double = 0
) -> some View {
if energetic {
self.modifier(Shimmer(period: period, bounce: bounce, delay: delay))
} else {
self
}
}
@ViewBuilder func shimmering(energetic: Bool = true, animation: Animation = Shimmer.defaultAnimation) -> some View {
if energetic {
self.modifier(Shimmer(animation: animation))
} else {
self
}
}
}