Reputation: 105
I have a button that increments a firebase value by one, however I'm trying to only allow that button to be tapped once. Tried a few things but couldn't get it work correctly is there an simple way to get this working?
Button(action: {
let db = Firestore.firestore()
let like = Int.init(self.likes)!
db.collection("posts").document(self.id).updateData(["likes": "\(like + 1)"]) { err in
if err != nil {
print(err)
return
}
print("updated...")
}
}) {
Image(systemName: "arrow.up.square")
.frame(width: 26, height: 26)
}
Upvotes: 1
Views: 1178
Reputation: 54611
Here is a simple demo:
struct ContentView: View {
@State var buttonTapped = false
var body: some View {
Button(action: {
self.buttonTapped.toggle()
// other actions...
}) {
Text("Tap me")
}
.disabled(buttonTapped)
}
}
Upvotes: 4