title: swift ui my chat view is not stay on the screen can you help me?
body: <p>I have a problem When I click the button in the conversation view, the people to start the conversation screen, namely the new message view, appears. When I choose one of the contacts, the chat view screen comes up, but this only happens once when I first open the application. When I try more than once, when I select the user in the new message view, I go to the chat view and then the conversation view goes and the chat view does not stay on the screen. can you help me ?</p>
  <p></p>
  <p></p>
  <pre><code>import SwiftUI
  import Kingfisher
  
  struct conversationsview: View {
      @State var showmwssageview = false
      @State  var showchatview = false
      @State var selecteduser : User?
      @ObservedObject var viewmodel = ConversationViewModel()
      
      var body: some View {
          ZStack(alignment: .bottomTrailing){
              if let user  = selecteduser{
                  NavigationLink(isActive: $showchatview) {
                      chatview(user: user)
                      
                  } label: {
                      
                  }
                 
             }
                  ScrollView{
                      VStack(alignment: .leading){
                          ForEach(viewmodel.recentmessages){message in
                             usercell(viewmodel: ConversationCellViewModel(message))
  
                          }
                      }
                  }
                  Button {
                      self.showmwssageview = true
                      
                      
                  } label: {
                      Image(systemName: &quot;square.and.pencil&quot;).resizable().scaledToFit().frame(width: 24, height: 24).padding()
                  }.background(Color(.systemBlue)).foregroundColor(.white).clipShape(Circle()).padding().sheet(isPresented: $showmwssageview) {
                      newmessageview(showchatview: $showchatview,  user: $selecteduser)
                      
                  }
             
  
              }.onAppear {
             
                  viewmodel.fetchrecentmessages()
          }
      }
  }
  
  </code></pre>
  <pre><code>
  import SwiftUI
  
  struct newmessageview: View {
      @Binding var showchatview: Bool
      @Environment(\.dismiss) var dismiss
      @State private var searchtext = &quot;&quot;
      @State private var isediting = false
      @ObservedObject var viewnodel = NewMessageViewModel()
      @Binding var user : User?
     
      var body: some View {
          
         
              ScrollView{
                  searchbar(text: $searchtext, isediting: $isediting).onTapGesture {
                      isediting.toggle()
                  }.padding()
                  VStack(alignment: .leading){
                      ForEach(viewnodel.users){user in
                          
                          Button {
                              
                              self.showchatview.toggle()
                              self.user = user
                              dismiss()
                             
                            
                             
                          } label: {
                              usercelltwo(user: user)
                          }
                          
                         
  
  
                        
  
                      }
                  }
              }
          
      }
  }
  
  </code></pre>
  <pre><code>
  import SwiftUI
  
   struct chatview: View {
      
      @State private var messagetext = &quot;&quot;
      @ObservedObject var viewmodel : ChatViewModel
       @ObservedObject var conviewmodel = ConversationViewModel()
     
  
      private let user: User
      
       init(user:User) {
          self.user = user
          self.viewmodel = ChatViewModel(user: user)
         
           
      }
      
      
       var body: some View {
          VStack {
              ScrollView{
                  VStack(alignment: .leading,spacing: 12){
                      ForEach(viewmodel.messages){message in
                          messageview(viewmodel: MessageViewModel( message))
                      }
                  }
              }
              custominputview(text: $messagetext, action: sendmessage)
              //input view
              
          }.navigationTitle(user.verifyid).navigationBarTitleDisplayMode(.inline).padding(.vertical)
       }
      
      func sendmessage(){
          
          viewmodel.sendmessage(messagetext)
          messagetext = &quot;&quot;
         
          
      }
  }
  
  </code></pre>