SwiftUI sheets bolded

310 views Asked by At

When I present a sheet with SwiftUI, everything gets bolded. If I swipe a bit, the bold goes away.

Example:

.navigationBarItems(leading:
    Button(action:{
      self.isSheetPresented.toggle()
    }) {
      Text("Display")
    }
    .frame(width: 25, height: 45)
    .sheet(isPresented: $isSheetPresented) {
      Textfield("Hello", text: $binding)
    })
  }

Is there an easy workaround besides applying

.fontWeight(.regular) or .font(.body) 

to everything?

PS: running Xcode Version 12.2 beta 3 (12B5035g) on MacOS 11.0 Beta (20A5395g)

2

There are 2 answers

2
Asperi On BEST ANSWER

Try to move sheet out of navigationBarItems and attach to some view inside body, like

// ... other views
.navigationBarItems(leading:
    Button(action:{
      self.isSheetPresented.toggle()
    }) {
      Text("Display")
    }
    .frame(width: 25, height: 45)
)

...

} // end of NavigationView
.sheet(isPresented: $isSheetPresented) {    // << here !!
  Textfield("Hello", text: $binding)
}
0
MarcoGT On

Ok, I did some tests:

.navigationBarItems(leading:
                                Button(action: {self.showingSettings = true}) {
                Image(systemName: "gear")
            }
            //.sheet(isPresented: $showingAddItem, content: {
              //  AddView(expirations: self.expirations)
            ,
                    trailing:
                        Button(action: {self.showingAddItem = true}) {
                Image(systemName: "plus")
            }
            //.sheet(isPresented: $showingSettings, content: {
            //    SettingsView()
            
        )
        .sheet(isPresented: $showingAddItem, content: {
            AddView(expirations: self.expirations)
        })
        .sheet(isPresented: $showingSettings, content: {
            SettingsView()
        })

But by doing so the trailing button is not working, only the leading one