Skip to content

Commit

Permalink
feat: haptic feedback in tabview
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian committed Feb 23, 2024
1 parent e4cf1d9 commit 056c2b9
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions showdown/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,40 @@

import SwiftUI

extension Binding {
func onUpdate(_ closure: @escaping () -> Void) -> Binding<Value> {
Binding(get: {
wrappedValue
}, set: { newValue in
wrappedValue = newValue
closure()
})
}
}

struct ContentView: View {
@State private var tabSelection: Int = 1

func hapticFeedback(value: Int){
self.tabSelection = value
UIImpactFeedbackGenerator(style: .light).impactOccurred()
}

var body: some View {
VStack {
Text("Showdown! iOS client")
}
.padding()
TabView (selection: $tabSelection.onUpdate {
hapticFeedback(value: tabSelection)
}) {
Text("Showdown")
.tabItem {
Label("Showdown!", image: "showdown") }
Text("Account")
.tabItem {
Label("Account", systemImage: "person")
}
Text("Settings")
.tabItem {
Label("Settings", systemImage: "gear")
} }
}
}

Expand Down

0 comments on commit 056c2b9

Please sign in to comment.