Created
March 17, 2022 04:08
-
-
Save cyypherus/1c7b023b61bb743b1501b9b887d47c88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import SwiftUI | |
struct ContentView: View { | |
@State var animate = false | |
let iconSize: CGFloat = 95 | |
let iconCount = 20 | |
let iconPadding: CGFloat = 5 | |
var marqueeWidth: CGFloat { | |
(iconSize * CGFloat(iconCount)) + (iconPadding * (CGFloat(iconCount) - 1)) | |
} | |
var body: some View { | |
GeometryReader { geo in | |
HStack(spacing: iconPadding) { | |
ForEach(0..<iconCount, id: \.self) { i in | |
RoundedRectangle(cornerRadius: 21) | |
.frame(width: iconSize, height: iconSize) | |
.foregroundColor(.indigo) | |
.overlay { | |
Text("\(i)") | |
} | |
} | |
} | |
.frame(width: marqueeWidth) | |
.offset( | |
x: animate ? -(marqueeWidth - geo.size.width) : 0 | |
) | |
} | |
.animation(.linear(duration: 10).repeatForever(autoreverses: true), value: animate) | |
.onAppear { | |
animate.toggle() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment