Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zntfdr/521be2b3be4e755f0e65502c8bc7ad2e to your computer and use it in GitHub Desktop.
Save zntfdr/521be2b3be4e755f0e65502c8bc7ad2e to your computer and use it in GitHub Desktop.
An implementation for making tab bar item action
struct ContentView: View {
@State private var selection = 0
private var actionSelection: Binding<Int> {
Binding<Int>(get: {
self.selection
}) { (newValue: Int) in
if newValue == 1 {
// put action here
} else {
self.selection = newValue
}
}
}
var body: some View {
TabView(selection: actionSelection) {
FirstView()
.tabItem {
VStack {
Image("first")
Text("First")
}
}
.tag(0)
ActionView()
.font(.title)
.tabItem {
VStack {
Image("action")
Text("Action")
}
}
.tag(1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment