How can I pop to the Root view using SwiftUI?

Setting the view modifier isDetailLink to false on a NavigationLink is the key to getting pop-to-root to work. isDetailLink is true by default and is adaptive to the containing View. On iPad landscape for example, a Split view is separated and isDetailLink ensures the destination view will be shown on the right-hand side. Setting isDetailLink … Read more

SwiftUI iOS14 – NavigationView + List – Won’t fill space

Problem It looks like the default styles of a List or NavigationView in iOS 14 may in some cases be different than in iOS 13. Solution #1 – explicit listStyle It’s no longer always the PlainListStyle (as in iOS 13) but sometimes the InsetGroupedListStyle as well. You need to explicitly specify the listStyle to PlainListStyle: … Read more

What enables SwiftUI’s DSL?

As Martin says, if you look at the documentation for VStack‘s init(alignment:spacing:content:), you can see that the content: parameter has the attribute @ViewBuilder: init(alignment: HorizontalAlignment = .center, spacing: Length? = nil, @ViewBuilder content: () -> Content) This attribute refers to the ViewBuilder type, which if you look at the generated interface, looks like: @_functionBuilder public … Read more

SwiftUI @State var initialization issue

SwiftUI doesn’t allow you to change @State in the initializer but you can initialize it. Remove the default value and use _fullText to set @State directly instead of going through the property wrapper accessor. @State var fullText: String // No default value of “” init(letter: String) { _fullText = State(initialValue: list[letter]!) }

How to scroll List programmatically in SwiftUI?

SWIFTUI 2.0 Here is possible alternate solution in Xcode 12 / iOS 14 (SwiftUI 2.0) that can be used in same scenario when controls for scrolling is outside of scrolling area (because SwiftUI2 ScrollViewReader can be used only inside ScrollView) Note: Row content design is out of consideration scope Tested with Xcode 12b / iOS … Read more

SwiftUI: How to pop to Root view

Setting the view modifier isDetailLink to false on a NavigationLink is the key to getting pop-to-root to work. isDetailLink is true by default and is adaptive to the containing View. On iPad landscape for example, a Split view is separated and isDetailLink ensures the destination view will be shown on the right-hand side. Setting isDetailLink … Read more

SwiftUI update navigation bar title color

It is not necessary to use .appearance() to do this globally. Although SwiftUI does not expose navigation styling directly, you can work around that by using UIViewControllerRepresentable. Since SwiftUI is using a regular UINavigationController behind the scenes, the view controller will still have a valid .navigationController property. struct NavigationConfigurator: UIViewControllerRepresentable { var configure: (UINavigationController) -> … Read more