DocumentGroup double back button fix
If you are building DocumentGroup
-based apps in SwiftUI, you may have noticed that apps that worked fine in Xcode 15 now show two back buttons when being built with Xcode 16.
While I’m not sure what’s causing this, you can fix this bug by applying .toolbarRole(.automatic)
to the document group content view.
Since this is only available in iOS 16, this extension may be convenient if you target older versions of iOS:
extension View {
@ViewBuilder
func withAutomaticToolbarRole() -> some View {
if #available(iOS 16.0, *) {
self.toolbarRole(.automatic)
} else {
self
}
}
}
You can now adjust your document group content to remove the extra back button:
@main
struct MyApp: App {
var body: some Scene {
DocumentGroup(newDocument: MyDocumentType()) { file in
MyDocumentView(file: file)
.withAutomaticToolbarRole()
}
}
}
Hope this helps…and fingers crossed that Apple fixes this bug soon!
Discussions & More
Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon..
If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.
If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.