Any ideas as to how Apple implemented the \"slide to unlock\" (also, \"slide to power off\" is another identical example) animation?
I thought about some sort of ani
Here's a SwiftUI version:
struct Shimmer: AnimatableModifier {
private let gradient: Gradient
init(sideColor: Color = Color(white: 0.25), middleColor: Color = .white) {
gradient = Gradient(colors: [sideColor, middleColor, sideColor])
}
@State private var position: CGFloat = 0
var animatableData: CGFloat {
get { position }
set { position = newValue }
}
func body(content: Content) -> some View {
content
.overlay(LinearGradient(
gradient: gradient,
startPoint: .init(x: position - 0.2 * (1 - position), y: 0.5),
endPoint: .init(x: position + 0.2 * position, y: 0.5)))
.mask(content)
.onAppear {
withAnimation(Animation
.linear(duration: 2)
.delay(1)
.repeatForever(autoreverses: false)) {
position = 1
}
}
}
}
Use it like this:
Text("slide to unlock")
.modifier(Shimmer())