Files
MessageKit/Example/Sources/Views/SwiftUI/SwiftUIExampleView.swift
T
martinpucik 4ab430c7b1 refactor: InpuBar as subview instead of accessoryView
Cleanup of commented and not used code
Moved some internal properties to state object
Removed iOS 13 available checks
2022-05-04 16:44:27 +02:00

42 lines
1006 B
Swift

//
// ChatView.swift
// ChatExample
//
// Created by Kino Roy on 2020-07-18.
// Copyright © 2020 MessageKit. All rights reserved.
//
import SwiftUI
import MessageKit
struct SwiftUIExampleView: View {
@State var messages: [MessageType] = SampleData.shared.getMessages(count: 20)
var body: some View {
MessagesView(messages: $messages).onAppear {
self.connectToMessageSocket()
}.onDisappear {
self.cleanupSocket()
}
.navigationBarTitle("SwiftUI Example", displayMode: .inline)
}
private func connectToMessageSocket() {
MockSocket.shared.connect(with: [SampleData.shared.nathan, SampleData.shared.wu]).onNewMessage { message in
self.messages.append(message)
}
}
private func cleanupSocket() {
MockSocket.shared.disconnect()
}
}
struct SwiftUIExampleView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIExampleView()
}
}