Post

Replies

Boosts

Views

Activity

TabView - PageTabViewStyle does not conform to edgesIgnoreSafeArea in Landscape mode on all notched iPhones
Running PageTabViewStyle in landscape orientation on any iPhone with a notch results in odd spacing on the leading side of the view, edgesIgnoringSafeArea does not seem to be working correctly? Adding a second Edges ignore in the body seems to help, but still left with a leading white area. PageTabViewStyle and edgesIgnore seem to work fine on older non-notch phones. Anyone know a solution to this problem? import SwiftUI struct TestTabView: View {   var colors : [Color] = [.red, .yellow, .blue, .green]   @State private var page: Int = 1   var body: some View {     TabView (selection: $page){       ForEach(0..<colors.count, id: \.self) {index in Rectangle().foregroundColor(colors[index]).edgesIgnoringSafeArea(.all) .tag([index])       }     }     .tabViewStyle(PageTabViewStyle())     .edgesIgnoringSafeArea(.all)   } } struct TestTabView_Previews: PreviewProvider {   static var previews: some View {     TestTabView()   } }
1
0
1.2k
Dec ’20
Creating a new Core data Entry/Object while in modal view stops the dismissal of the view, presentationMode.wrappedValue.dismiss() no longer works.
Creating a new Core data Entry/Object (addItem) while in modal stops the dismissal of the view, presentationMode.wrappedValue.dismiss() no longer works. The sample below uses the template provided in Beta 6 with core data, with the additional of a full screen cover to save some data. After the new Item is created, the modal will no longer dismiss. Any way around this? import SwiftUI import CoreData struct ContentView: View {   @Environment(\.managedObjectContext) private var viewContext   @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],animation: .default) private var items: FetchedResults<Item>   @State private var isPresented = false      var body: some View {     NavigationView {       List {         ForEach(items) { item in           Text("\(item.timestamp!, formatter: itemFormatter)")         }         .onDelete(perform: deleteItems)       }       .toolbar {         Button(action: {isPresented.toggle()}) {Image(systemName: "plus")}           .fullScreenCover(isPresented: $isPresented, content: { PopUpView() })       }     }   }     private func deleteItems(offsets: IndexSet) {         withAnimation {             offsets.map { items[$0] }.forEach(viewContext.delete)             do {                 try viewContext.save()             } catch {                 let nsError = error as NSError                 fatalError("Unresolved error \(nsError), \(nsError.userInfo)")             }         }     } } private let itemFormatter: DateFormatter = {     let formatter = DateFormatter()     formatter.dateStyle = .short     formatter.timeStyle = .medium     return formatter }() struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)     } } struct PopUpView: View {   @Environment(\.managedObjectContext) private var viewContext   @Environment(\.presentationMode) private var presentationMode   var body: some View {     Button(action: addItem) {Text ("Add Item")}     Button(action: {presentationMode.wrappedValue.dismiss()} ) {Text ("Dismiss View")}   }      private func addItem() {       let newItem = Item(context: viewContext)        newItem.timestamp = Date()     do {         try viewContext.save()         self.presentationMode.wrappedValue.dismiss()     } catch {         let nsError = error as NSError         fatalError("Unresolved error \(nsError), \(nsError.userInfo)")     }   } }
0
0
628
Sep ’20