Created
April 19, 2022 20:20
-
-
Save amosgyamfi/e8c215de81bc5a48e19a425f18487bcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Chains.swift | |
// Stream Spring Demo | |
// | |
// Created by Amos | |
// | |
import SwiftUI | |
struct StreamDemo: View { | |
let letters = Array("Stream") | |
@State private var enabled = false | |
@State private var dragAmount = CGSize.zero | |
var body: some View { | |
HStack(spacing: 0) { | |
ForEach(0..<letters.count) { num in | |
Text(String(letters[num])) | |
.font(.largeTitle) | |
.rotationEffect(.degrees(enabled ? 0 : 360), anchor: .bottom) | |
.offset(dragAmount) | |
.animation(.interpolatingSpring(stiffness: 170, damping: 15).delay(Double(num) / 20), value: dragAmount) | |
} | |
} | |
.padding() | |
.gesture( | |
DragGesture() | |
.onChanged { dragAmount = $0.translation } | |
// _ ignore the value coming in this time | |
.onEnded { _ in | |
withAnimation{ | |
dragAmount = .zero | |
enabled.toggle() | |
} | |
} | |
) | |
} | |
} | |
struct StreamDemo_Previews: PreviewProvider { | |
static var previews: some View { | |
StreamDemo() | |
.preferredColorScheme(.dark) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment