Skip to content

Instantly share code, notes, and snippets.

@lorenzofiamingo
Created May 2, 2020 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lorenzofiamingo/26d46c95eace51e97ceabe5177107824 to your computer and use it in GitHub Desktop.
Save lorenzofiamingo/26d46c95eace51e97ceabe5177107824 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