mirror of
https://github.com/MessageKit/MessageKit.git
synced 2026-02-06 19:03:19 +00:00
bff35fda61
* 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>
48 lines
1.0 KiB
Swift
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()
|
|
}
|
|
}
|