-
-
Save zntfdr/521be2b3be4e755f0e65502c8bc7ad2e 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