Skip to content

Instantly share code, notes, and snippets.

@no13bus
Created September 22, 2023 12:02
Show Gist options
  • Save no13bus/e4ca7e33716aed61c1232607122097f1 to your computer and use it in GitHub Desktop.
Save no13bus/e4ca7e33716aed61c1232607122097f1 to your computer and use it in GitHub Desktop.
ContentView
//
// 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