SwiftUI animation bug

Hi there,

I am still quite new to Swift and have following problem: Many animations in my app have bugs, like you can see in the attached images. I cannot attach a video so I attached images from the video. Here is my description: When I click on a NavigationLink, the title of the following page appears after the animation and the whole content of the page moves up. What can I do against this?

This is my code from the first page:


struct Medikamente: View {
    var body: some View {
        
        NavigationStack {
            List {
                Group {
                    NavigationLink(destination: Acetylsalicylsaeure()){
                        Image("AcetylsalicylsaeureMediLabel")
                            .resizable()
                            .frame(width:60, height: 30)
                        Text("Acetylsalicylsäure")
                    }
                    NavigationLink(destination: Amiodaron()){
                        Image("AmiodaronMediLabel")
                            .resizable()
                            .frame(width:60, height: 30)
                        Text("Amiodaron")
                    }
                    NavigationLink(destination: Atropin()){
                        Image("AtropinMediLabel")
                            .resizable()
                            .frame(width:60, height: 30)
                        Text("Atropin")
                    }
                    NavigationLink(destination: Butylscopolamin()){
                        Image("ButylscopolaminMediLabel")
                            .resizable()
                            .frame(width:60, height: 30)
                        Text("Butylscopolamin")
                    }
// More medication
                }
                }           
                .navigationTitle("Medikamente")
                .navigationBarTitleDisplayMode(.automatic)
            }
        }
    }
#Preview {
    Medikamente()
}

And this is the code from the second page.


struct Acetylsalicylsaeure: View {
    var body: some View {
        NavigationStack {
            List {
                Section {
                    Image("AcetylsalicylsaeureMediLabel")
                        .resizable()
                        .scaledToFit()
                }
                NavigationLink(destination: List {
                    
                    Section {
                        Text("**500 mg Trockensubstanz** + 5ml Lösungsmittel")
                        Text("diverse orale Darreichungsformen")
                    } header: {
                        Text("**Allgemeine Informationen** \nKonzentration")
                    }
                    Section {
                        Text("Thrombozytenaggregationshemmer")
                    } header: {
                        Text("Arzneimittelgruppe")
                    }
                    .navigationTitle("Acetylsalicylsäure")
                    .navigationBarTitleDisplayMode(.inline)
                    
                }) {
                    Text("Allgemeine Informationen")
                }
// More NavigationLinks...

                NavigationLink(destination: List {
                    Section {
                        Text("Im Rettungsdienst nicht möglich")
                    } header: {
                        Text("**Erfolgsprüfung**")
                    }
                    .navigationTitle("Acetylsalicylsäure")
                    .navigationBarTitleDisplayMode(.inline)
                }) {
                    Text("Erfolgsprüfung")
                }
                NavigationLink(destination: List {
                    Section {
                        Text("Lt. BPR „Akutes Coronarsyndrom“, Heparin 5.000 I.E. i.v.")
                    } header: {
                        Text("**Folgemaßnahmen**")
                    }
                    .navigationTitle("Acetylsalicylsäure")
                    .navigationBarTitleDisplayMode(.inline)
                }) {
                    Text("Folgemaßnahmen")
                }
                            .navigationTitle("Acetylsalicylsäure")
                                        .navigationBarTitleDisplayMode(.inline)
            }
        }
    }
}

#Preview {
    Acetylsalicylsaeure()
}

Thank you so much for your help!

Laurin

Answered by rinuality in 770485022

I found a solution: You just have to set

.navigationTitle("Acetylsalicylsäure")
.navigationBarTitleDisplayMode(.inline)

a bracket lower. So one more closed bracket before the mentioned text and one less after it. :)

Accepted Answer

I found a solution: You just have to set

.navigationTitle("Acetylsalicylsäure")
.navigationBarTitleDisplayMode(.inline)

a bracket lower. So one more closed bracket before the mentioned text and one less after it. :)

SwiftUI animation bug
 
 
Q