Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo code of building modifier by mutating function in SwiftUI
// buttonLabel modifier
struct TokenButtonLabel: View {
// --snip--
/// State properties
var isHighlighted = false
// --snip--
}
extension TokenButtonLabel {
/// Pass highlightSwitch argument bonded with @State variable in order to trigger updates
mutating func highlight(_ highlightSwitch: TokenButton.StateSwitch) -> Self {
self.isHighlighted = highlightSwitch == .on ? true : false
return self
}
}
// buttonStyle modifier
struct TokenButtonStyle: ButtonStyle {
// --snip--
/// State properties
var isActive = true
// --snip--
}
extension TokenButtonStyle {
// Pass highlightSwitch argument bonded with @State variable in order to trigger updates
mutating func activate(_ activeSwitch: TokenButton.StateSwitch) -> Self {
self.isActive = activeSwitch == .on ? true : false
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.