Created
October 4, 2022 12:11
-
-
Save SarahAlsharif/31b82579eb3ce4fb87752fe3dc3909ab 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
struct StarsRating: View { | |
@State var rating : [Rating] = [] | |
func addStars (index : Int) { | |
var currentRating : Rating = .oneStar | |
rating.removeAll() | |
for _ in 0 ... index { | |
rating.append(currentRating) | |
currentRating = currentRating.next() | |
} | |
} | |
var body: some View { | |
ZStack { | |
Color.blue.opacity(0.2).ignoresSafeArea() | |
VStack { | |
MultiStepsView(steps: $rating, extraContent: ["star.fill","star.fill","star.fill","star.fill","star.fill"], extraContentPosition: .onTop, extraContentSize: CGSize(width: 39, height: 30), action: addStars) { | |
Image(systemName: "star") | |
.frame(width: 30, height: 30) | |
} | |
.accentColor(.yellow) | |
.font(.title2) | |
Text(rating.isEmpty ? "How much would you rate this?": "\(rating.last!.rawValue) stars") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment