Skip to content

Instantly share code, notes, and snippets.

@Koshimizu-Takehito
Created June 21, 2024 08:06
Show Gist options
  • Save Koshimizu-Takehito/c91755537fb7f4a20b1f0faed7551e60 to your computer and use it in GitHub Desktop.
Save Koshimizu-Takehito/c91755537fb7f4a20b1f0faed7551e60 to your computer and use it in GitHub Desktop.
ContentTransition
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