Skip to content

Commit

Permalink
Merge pull request #8 from jaesung-0o0/feature/jaesung/100-beta-1
Browse files Browse the repository at this point in the history
[Release/1.0.0-Beta.1] Merge to main
  • Loading branch information
x-0o0 authored Feb 28, 2023
2 parents aeb840d + 68d9327 commit a8e6433
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 24 deletions.
6 changes: 4 additions & 2 deletions Documentation/Chat_in_Channel/MessageList.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

## Lists messages in row contents

In the constructor, you can list message objects that conform to `MessageProtocol` to display messages using the `rowContent` parameter.
In the intializer, you can list message objects that conform to `MessageProtocol` to display messages using the `rowContent` parameter.

All the body and row contents are flipped vertically so that new messages can be listed from the bottom.

The messages are listed in the following order, depending on the `readReceipt` value of the `MessageProtocol`. For more details, please refer to `MessageProtocol/readReceipt` or `ReadReceipt`.

sending → failed → sent → delivered → seen
> **NOTE:** The order of the messages is like below:
>
> sending → failed → sent → delivered → seen
## Scrolls to bottom

Expand Down
7 changes: 7 additions & 0 deletions Sources/ChatUI/ChatInChannel/ChannelInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

import SwiftUI

/**
The view that displays the following channel information:

- The image of the channel
- The title of the channel
- The subtitle of the channel
*/
public struct ChannelInfoView: View {
@Environment(\.appearance) var appearance

Expand Down
18 changes: 3 additions & 15 deletions Sources/ChatUI/ChatInChannel/ChannelStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@

import SwiftUI

// TODO: VStack 감싸기
/**
```swift
ChannelStack(channel, spacing: 0) {
MessageList() { ... }

MessageField { ... }
}
.channelInfoBar { ... }
```
*/

/**
The *vertical* stack view that provides ``ChannelInfoView`` as a `ToolbarItem`.

Expand All @@ -34,10 +22,10 @@ import SwiftUI
}
```
*/
public struct ChannelStack<C: ChannelProtocol, Content: View>: View {
public struct ChannelStack<ChannelType: ChannelProtocol, Content: View>: View {
@EnvironmentObject private var configuration: ChatConfiguration

let channel: C
let channel: ChannelType
let content: () -> Content

public var body: some View {
Expand All @@ -56,7 +44,7 @@ public struct ChannelStack<C: ChannelProtocol, Content: View>: View {
}

public init(
_ channel: C,
_ channel: ChannelType,
@ViewBuilder content: @escaping () -> Content
) {
self.channel = channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class LocationModel: NSObject, ObservableObject {
case tracked
}

// TODO: change to `false`
@Published var locationTrackingStatus: TrackStatus = .none
@Published var coordinateRegion: MKCoordinateRegion = .init(
center: .init(latitude: 37.57827, longitude: 126.97695),
Expand Down
44 changes: 44 additions & 0 deletions Sources/ChatUI/ChatInChannel/MessageField/MessageField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@ import Combine
import SwiftUI
import PhotosUI

/**
The view for sending messages.

When creating a `MessageField`, you can provide an action for how to handle a new `MessageStyle` information in the `onSend` parameter. `MessageStyle` can contain different types of messages, such as text, media (photo, video, document, contact), and voice.

```swift
MessageField { messageStyle in
viewModel.sendMessage($0)
}
```

To handle menu items, assign state property to `isMenuItemPresented` parameter.

```swift
MessageField(isMenuItemPresented: $isMenuItemPresented) { ... }

if isMenuItemPresented {
MyMenuItemList()
}
```

To publish a new message, you can create a new `MessageStyle` object and send it using `send(_:)`.

```swift
let _ = Empty<Void, Never>()
.sink(
receiveCompletion: { _ in
// Create `MessageStyle` object
let style = MessageStyle.text("{TEXT}")
// Publish the created style object via `send(_:)`
sendMessagePublisher.send(style)
},
receiveValue: { _ in }
)
```

You can subscribe to `sendMessagePublisher` to handle new messages.

```swift
.onReceive(sendMessagePublisher) { messageStyle in
// Handle `messageStyle` here (e.g., sending message with the style)
}
```
*/
public struct MessageField: View {
@EnvironmentObject private var configuration: ChatConfiguration

Expand Down
14 changes: 11 additions & 3 deletions Sources/ChatUI/ChatInChannel/MessageList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@

import SwiftUI

/**
The view that lists message objects.

In the intializer, you can list message objects that conform to ``MessageProtocol`` to display messages using the `rowContent` parameter.

All the body and row contents are flipped vertically so that new messages can be listed from the bottom.

The messages are listed in the following order, depending on the ``ReadReceipt`` value of the ``MessageProtocol``. For more details, please refer to ``MessageProtocol/readReceipt`` or ``ReadReceipt``.

- **NOTE:** The order of the messages: sending → failed → sent → delivered → seen
*/
public struct MessageList<MessageType: MessageProtocol & Identifiable, RowContent: View>: View {

@EnvironmentObject var configuration: ChatConfiguration
Expand Down Expand Up @@ -104,7 +114,6 @@ public struct MessageList<MessageType: MessageProtocol & Identifiable, RowConten
showsScrollButton = isScrollButtonShown
}

print(diff)
if isKeyboardShown && diff < -20 {
isKeyboardShown = false
}
Expand All @@ -114,7 +123,6 @@ public struct MessageList<MessageType: MessageProtocol & Identifiable, RowConten
/// When tapped sending button. Called after `onSent` in ``MessageField``
.onChange(of: sendingMessages) { newValue in
if let id = sendingMessages.first?.id {
print("☺️ \(id)")
withAnimation {
scrollView.scrollTo(id, anchor: .bottom)
}
Expand Down Expand Up @@ -145,7 +153,7 @@ public struct MessageList<MessageType: MessageProtocol & Identifiable, RowConten

public init(
_ messageData: [MessageType],
showsDate: Bool = false,
showsDate: Bool = false, // TODO: Not Supported yet
@ViewBuilder rowContent: @escaping (_ message: MessageType) -> RowContent
) {
var sendingMessages: [MessageType] = []
Expand Down
2 changes: 1 addition & 1 deletion Sources/ChatUI/ChatInChannel/MessageSearchBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

// TODO: Not current scope
// TODO: Not Supported yet
struct MessageSearchBar: View {
@State private var searchText: String = ""

Expand Down
1 change: 0 additions & 1 deletion Sources/ChatUI/ChatInChannel/ScrollButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public struct ScrollButton: View {
let _ = Empty<Void, Never>()
.sink(
receiveCompletion: { _ in
print("☺️ scrollsToBottom send")
scrollDownPublisher.send(())
},
receiveValue: { _ in }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

// TODO: Not current scope
// TODO: Not Supported yet
struct MessageSearch_Previews: PreviewProvider {
static var previews: some View {
MessageSearchBar()
Expand Down

0 comments on commit a8e6433

Please sign in to comment.