Last active
April 2, 2020 05:08
-
-
Save badrinathvm/ceb53dffdc3f4be24916e9357a9543f0 to your computer and use it in GitHub Desktop.
SwiftUI View for Rectangle
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
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