// // SheetTestView.swift // textinput // // Created by Venin Alexander on 3/24/22. // import SwiftUI extension View { func hideKeyboard() { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } } struct SheetTestView: View { @State var isShowWarnings = true @State var isPresentedDialog = false @State var inputString: String = "" var body: some View { VStack(spacing: 0) { pageView bottomBar .frame(height: 60) } .edgesIgnoringSafeArea(.bottom) } var bottomBar: some View { HStack { ForEach(0..<4) { index in Button("item \(index)"){ } } } } var pageView: some View { // each feature has it's own NavigationView stack NavigationView { mainContent .navigationBarTitleDisplayMode(.inline) .navigationBarHidden(false) .navigationBarTitle("Feature title") .navigationBarBackButtonHidden(true) } .navigationViewStyle(StackNavigationViewStyle()) } var mainContent: some View { VStack { Button("Refresh") { isShowWarnings = true } .border(Color.black) VStack(spacing: 0) { ScrollView(.vertical) { VStack(spacing: 40) { validationErrorMessage textInputView .padding(.top, 80) } .animation(.default, value: isShowWarnings) .padding(.horizontal, 20) }.frame(maxWidth: .infinity) Spacer() Button("Push the tempo") { isPresentedDialog = true hideKeyboard() } .border(Color.black) .sheet(isPresented: $isPresentedDialog) { isPresentedDialog = false isShowWarnings = false } content: { dialogContentView } } } } private var dialogContentView: some View { VStack { HStack { Spacer() Button("Close") { isPresentedDialog = false } }.padding() Spacer() Text("Dummy dialog message") Spacer() }.padding() } @ViewBuilder private var validationErrorMessage: some View { if isShowWarnings { ForEach(0..<7) { index in Text("some dynamic string \(index)") .foregroundColor(Color.red) .transition(.opacity.combined(with: .move(edge: .top))) } } } private var textInputView: some View { TextField("input field", text: $inputString) } }