Hello all,
I’ve only been at this for a few months, so I apologize if this has been answered elsewhere.
I’ve created a custom toggle button within my app’s main view. When tapped, it runs a simple isPressed.toggle()
function, which then changes some details about the button. Other parts of the view are executing commands via .onChange(of: isPressed...)
or waiting on a variable to be updated via isPressed.toggle()
function.
When I extract the button to it’s own view, it can no longer be used to update the state of a variable in the main view, nor can an element in the main view use the .onChange
function.
Example:
Button(action: {
customToggle.toggle()
}, label: {
Text("Button Label")
if customToggle == false {
*code*
} else {
*code*
}
}
Can someone point me in the right direction?