Created
June 21, 2024 08:06
-
-
Save Koshimizu-Takehito/c91755537fb7f4a20b1f0faed7551e60 to your computer and use it in GitHub Desktop.
ContentTransition
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
import SwiftUI | |
struct ContentView: View { | |
@State var rating: Double = 0 | |
var body: some View { | |
HStack(spacing: 18) { | |
Button( | |
action: { withAnimation { rating -= 1 } }, | |
label: { Image(systemName: "minus.circle") } | |
) | |
.disabled(rating <= 0) | |
Text(String(describing: Int(rating))) | |
.fixedSize() | |
.contentTransition(.numericText(value: rating)) | |
Button( | |
action: { withAnimation { rating += 1 } }, | |
label: { Image(systemName: "plus.circle") } | |
) | |
.disabled(rating >= 10) | |
} | |
.font(Font.system(size: 80).monospacedDigit().bold()) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment