Files
MessageKit/Example/Sources/Views/SwiftUI/SwiftUIExampleView.swift
T
Martin Púčik bff35fda61 Added Swiftlint and Swiftformat plugins (#1729)
* build: Swiftlint plugin

* build: Swiftformat plugin

* build: Swiftformat plugin

* build: Swiftformat bash command

* style: Swiftformat rules

* style: Swiftformat applied to codebase

* style: Ignore Tests for Swiftlint

* Update bundler

* Update changelog and migration guide

* style: Ignore Example for Swiftlint

* chore: Changelog

* Update Xcode version for ci_pr_tests.yml

* Update ci_pr_framework.yml

* Update ci_pr_example.yml

* chore: Changelog

Co-authored-by: Jakub Kaspar <kaspikk@gmail.com>
2022-07-25 08:46:14 +00:00

48 lines
1.0 KiB
Swift

//
// ChatView.swift
// ChatExample
//
// Created by Kino Roy on 2020-07-18.
// Copyright © 2020 MessageKit. All rights reserved.
//
import MessageKit
import SwiftUI
// MARK: - SwiftUIExampleView
struct SwiftUIExampleView: View {
// MARK: Internal
@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)
}
// MARK: Private
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()
}
}
// MARK: - SwiftUIExampleView_Previews
struct SwiftUIExampleView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIExampleView()
}
}