FB7673786
Paste the code below into a playground, and try incrementing and decrementing the stepper. The buttons will sporadically enable and disable.
This only happens with the Stepper.init(onIncrement:onDecrement:) initializer. It will work fine with a binding.
import SwiftUI
import PlaygroundSupport
class ViewModel: ObservableObject {
@Published var count = 0
}
struct ViewModelView<Content: View>: View {
@ObservedObject var viewModel = ViewModel()
let content: (ViewModel) -> Content
init(@ViewBuilder content: @escaping (ViewModel) -> Content) {
self.content = content
}
var body: some View {
self.content(self.viewModel)
}
}
let v = ViewModelView { viewModel in
Stepper(onIncrement: { viewModel.count += 1 }, onDecrement: { viewModel.count -= 1 }) {
Text("\(viewModel.count)")
}
}
PlaygroundPage.current.setLiveView(v)
I probably can not reproduce the problem here (tried both macOS and iOS playgrounds). What I can reliably reproduce is Stepper, that does not trigger actions properly, on changing the direction, i.e. if I click "+", "+", and then "-", "-", "-", first "-" will act as "+", second "-" will not trigger any action, and only third "-" will act as "-" (that thing is easily reproducible without viewModel/TCA), via the following fragment: