Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active May 9, 2024 07:36
Show Gist options
  • Save benigumocom/3eb09ba7f3048e82f5af89459a3dd673 to your computer and use it in GitHub Desktop.
Save benigumocom/3eb09ba7f3048e82f5af89459a3dd673 to your computer and use it in GitHub Desktop.
【SwiftUI】.contentTransition(.symbolEffect(.replace)) 👉 https://android.benigumo.com/20240509/contenttransition/
import SwiftUI
struct TestSymbolTransition: View {
@State private var value = true
var body: some View {
VStack {
Button {
value.toggle()
} label: {
Label("Favorite", systemImage: value ? "heart.fill" : "heart")
}
Button {
value.toggle()
} label: {
Label("Favorite", systemImage: "heart")
.symbolVariant(value ? .fill : .none)
}
Button {
value.toggle()
} label: {
Label("Favorite", systemImage: "heart")
.symbolVariant(value ? .fill : .none)
.contentTransition(.symbolEffect(.replace))
}
Button {
value.toggle()
} label: {
Label("Favorite", systemImage: "heart")
.symbolVariant(value ? .fill : .none)
.contentTransition(
.symbolEffect(value ? .replace.upUp : .replace.downUp)
)
}
}
.buttonBorderShape(.capsule)
.buttonStyle(.borderedProminent)
.tint(.pink)
}
}
#Preview {
BackgroundCheckeredPattern {
TestSymbolTransition()
}
}
@benigumocom
Copy link
Author

sc 2024-05-09 at 16 05 46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment