Skip to content

Instantly share code, notes, and snippets.

@badrinathvm
Last active April 2, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badrinathvm/ceb53dffdc3f4be24916e9357a9543f0 to your computer and use it in GitHub Desktop.
Save badrinathvm/ceb53dffdc3f4be24916e9357a9543f0 to your computer and use it in GitHub Desktop.
SwiftUI View for Rectangle
struct RectangleView: View {
var index: Int
@State private var animate = false
var publisher:PassthroughSubject<AnimationStatus, Never>
var body: some View {
Rectangle()
.foregroundColor(Color.green)
.frame(width: 50, height: 10)
.opacity(animate ? 1: 0.2)
.animation(.easeInOut)
.onReceive(publisher) { (value) in
switch value {
case .start(let index):
if index == self.index {
self.animate = true
} else {
self.animate = false
}
case .stop(let index):
if index == self.index {
self.animate = false
}
case .stopAll:
self.animate = false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment