1

Does anyone know why when I have two NavigationLinks in the same view, there is this bug that my view pops up correctly, but then immediately disappears. I've tried different solutions, but none of them seem to be working. Any help would be appreciated. I believe the error might be related to isActive, but I'm not sure.

So, basically, I have a button that is supposed to open up the MessageView through the NavigationLink and dismiss the ChatView and ConversationCell views.

import SwiftUI

struct ConversationsView: View {
    @State var isShowingNewMessageView: Bool = false
    @State var showChat: Bool = false

    var body: some View {
        ZStack(alignment: .bottomTrailing) {
            NavigationLink(isActive: $showChat, destination: {ChatView()}) {
//                EmptyView()
            }
        
            NavigationLink(destination: EmptyView(), label: {})
                .navigationViewStyle(StackNavigationViewStyle())
        
            ScrollView {
                VStack {
                    ForEach(0..<20) { _ in
                        NavigationLink {
                            ChatView()
                        } label: {
                            ConversationCell()
                            }
                    
                    }
                }
                .padding()
            }
        
            Button {
                self.isShowingNewMessageView.toggle()
            } label: {
                Image(systemName: "envelope")
                    .resizable()
                    .scaledToFit()
                    .frame(width: 32, height: 32)
                    .padding()
            }
            .background(Color.blue)
            .foregroundColor(.white)
            .clipShape(Circle())
            .padding()
            .sheet(isPresented: $isShowingNewMessageView, content: {
                NewMessageView(startChat: $showChat, show: $isShowingNewMessageView)
            })

        }
    }
}

struct ConversationsView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            ConversationsView()
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BuddyNew
  • 29
  • 4
  • Hard to say, since this isn't a [mre], but does this resolve your issue? https://stackoverflow.com/questions/67276205/swiftui-navigationlink-for-ios-14-5-not-working – jnpdx Jan 14 '22 at 03:51

0 Answers0