Created
May 2, 2020 20:51
-
-
Save lorenzofiamingo/26d46c95eace51e97ceabe5177107824 to your computer and use it in GitHub Desktop.
An implementation for making tab bar item action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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