Created
September 22, 2023 12:02
-
-
Save no13bus/e4ca7e33716aed61c1232607122097f1 to your computer and use it in GitHub Desktop.
ContentView
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
// | |
// ContentView.swift | |
// Example-iOS | |
// | |
// Created by Alex.M on 26.05.2022. | |
// | |
import SwiftUI | |
struct SheetView: View { | |
@Environment(\.dismiss) var dismiss | |
var body: some View { | |
Button("Press to dismiss") { | |
dismiss() | |
} | |
.font(.title) | |
.padding() | |
.background(.black) | |
} | |
} | |
struct SecondView: View { | |
@State private var showingSheet: Bool = false | |
var body: some View { | |
VStack{ | |
Button("Show Sheet") { | |
showingSheet.toggle() | |
} | |
.sheet(isPresented: $showingSheet) { | |
SheetView() | |
} | |
} | |
.navigationBarTitle("Second", displayMode: .inline) | |
} | |
} | |
struct HomeView: View { | |
@State private var showingSheet: Bool = false | |
var body: some View { | |
NavigationLink(destination: SecondView()) { | |
Text("Click me") | |
} | |
} | |
} | |
struct Settings: View { | |
var body: some View { | |
Text("Settings") | |
} | |
} | |
struct ContentView: View { | |
@State private var selectedTab = 0 | |
var body: some View { | |
NavigationView { | |
TabView(selection: $selectedTab) { | |
HomeView() | |
.tabItem { | |
Image(systemName: "house") | |
Text("Home") | |
} | |
.tag(0) | |
Settings() | |
.tabItem { | |
Image(systemName: "gear") | |
Text("Settings") | |
} | |
.tag(2) | |
} | |
.navigationBarTitle(selectedTab == 0 ? "Home" : "Settings", displayMode: .automatic) | |
} | |
.navigationViewStyle(.stack) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment