UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Toolbar with VStack gets truncated after selecting picker value from navigation view

Forums > SwiftUI

I want my App navigation title to contain two text views. One if the name of the app and the other is something they have selected. I found a way to do this is use a toolbar in principal placement rather than the navigation bar title since the nav bar title doesnt allow vstacks.

This works until I select a value from a picker that utilises a navigation view to navigate to another view in order to select the value. Once returning to the main view the toolbar is now showing the bottom of the vstack mainly chopped off. However the bar still takes up as much space.

As its hard to describe and seems particular to my combination of Navigation View, Tab view, Form and Toolbar with a non-inline picker I have recreated an example. Select a value with the picker and you will see the truncation. Its worse when you have padding on the vstack.

I have tried using various combinations of ToolBarItems or ToolBarItemGroups, sometimes changing the placement and sometimes seperating my two texts views into different items rather than a vstack but cant recreate the simple double heading without the truncation bug.

import SwiftUI

struct ContentView: View {
    @State var dummySelection: Int = 1
    var body: some View {
        NavigationView {
            TabView {
                Form {
                    Picker(selection: $dummySelection, Text("Picker")) {
                        ForEach(1..<100) { i in
                            Text("\(i)")
                        }
                    }
                    Text("Hello, world!")
                        .padding()
                }
            }
            .toolbar {
                ToolbarItemGroup(placement: .principal) {
                    VStack {
                        Text("Heading")
                        Text("Subheading")
                    }
                    .font(.title)
                }
            }

        }

    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.