Skip to content

Commit db5f491

Browse files
authored
Merge pull request #2 from jaesung-0o0/develop
[Release/1.0.0-beta.0] Chat in Channel & Appearance
2 parents 2372245 + e672730 commit db5f491

File tree

72 files changed

+4520
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4520
-7
lines changed

.gitignore

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
10+
11+
12+
Swift.gitignore
13+
14+
build/
15+
DerivedData/
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
xcuserdata/
25+
26+
*.moved-aside
27+
*.xccheckout
28+
*.xcscmblueprint
29+
30+
*.hmap
31+
*.ipa
32+
*.dSYM.zip
33+
*.dSYM
34+
35+
# Swift Package Manager
36+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
37+
# Packages/
38+
# Package.pins
39+
# Package.resolved
40+
# .build/
41+
# Add this line if you want to avoid checking in Xcode SPM integration.
42+
.swiftpm/xcode
43+
44+
45+
*.xcodeproj/*
46+
!*.xcodeproj/project.pbxproj
47+
!*.xcodeproj/xcshareddata/
48+
!*.xcworkspace/contents.xcworkspacedata
49+
/*.gcno
50+
51+
**/xcshareddata/WorkspaceSettings.xcsettings
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Appearance
2+
3+
The `Appearance` struct represents a set of predefined appearances used in the app's user interface such as colors and typography.
4+
Use these colors to maintain consistency and familiarity in the user interface.
5+
6+
## Example Usage
7+
```swift
8+
@Environment(\.appearance) var appearance
9+
10+
var body: some View {
11+
Text("New Chat")
12+
.font(appearance.title)
13+
.foregroundColor(appearance.primary)
14+
}
15+
```
16+
17+
## Customization
18+
```swift
19+
let appearance = Appearance(tint: .orange)
20+
21+
var body: some View {
22+
ChatView()
23+
.environment(\.appearance, appearance)
24+
}
25+
```
26+
27+

Documentation/Appearance/Colors.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Colors
2+
3+
| Property Name | Type | Description | Default Value |
4+
| --- | --- | --- | --- |
5+
| tint | Color | The main colors used in views provided by ChatUI. | Color(.systemBlue) |
6+
| primary | Color | The primary label color. | Color.primary |
7+
| secondary | Color | The secondary label color. | Color.secondary |
8+
| background | Color | The background color. | Color(.systemBackground) |
9+
| secondaryBackground | Color | The secondary background color. | Color(.secondarySystemBackground) |
10+
| localMessageBackground | Color | The background color for local user's message body. | Color(.tintColor) |
11+
| remoteMessageBackground | Color | The background color for remote user's message body. | Color(.secondarySystemBackground) |
12+
| imagePlaceholder | Color | The color used in image placeholder. | Color(.secondarySystemBackground) |
13+
| border | Color | The color used in border. | Color(.secondarySystemBackground) |
14+
| disabled | Color | The color used for disabled states. | Color.secondary |
15+
| error | Color | The color used for error states. | Color(.systemRed) |
16+
| prominent | Color | The prominent color. This color is used for text on prominent buttons. | Color.white |
17+
| link | Color | The link color. | Color(uiColor: .link) |
18+
| prominentLink | Color | The link color that is used in prominent views such as local message body. | Color(uiColor: .systemYellow) |
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Image Scales
2+
3+
This Swift extension provides convenient properties to scale `Image`
4+
views to predefined sizes. The `scale(_:contentMode:)`
5+
method is used to resize an image or other view to a specific size while keeping its aspect ratio.
6+
7+
## Properties
8+
9+
| Property Name | Size | Content Mode |
10+
| --- | --- | --- |
11+
| xSmall | 16 x 16 | .fit |
12+
| xSmall2 | 16 x 16 | .fill |
13+
| small | 20 x 20 | .fit |
14+
| small2 | 20 x 20 | .fill |
15+
| medium | 24 x 24 | .fit |
16+
| medium2 | 24 x 24 | .fill |
17+
| large | 36 x 36 | .fit |
18+
| large2 | 36 x 36 | .fill |
19+
| xLarge | 48 x 48 | .fit |
20+
| xLarge2 | 48 x 48 | .fill |
21+
| xxLarge | 64 x 64 | .fit |
22+
| xxLarge2 | 64 x 64 | .fill |
23+
| xxxLarge | 90 x 90 | .fit |
24+
| xxxLarge2 | 90 x 90 | .fill |
25+
26+
## Method
27+
28+
```swift
29+
func scale(_ scale: CGSize, contentMode: ContentMode) -> some View
30+
31+
```
32+
33+
**Description**
34+
35+
Scales the view to the specified size while maintaining its aspect ratio.
36+
37+
Use this method to resize an image or other view to a specific size while keeping its aspect ratio.
38+
39+
**Parameters**
40+
41+
| Parameter | Description |
42+
| --- | --- |
43+
| scale | The target size for the view, specified as a CGSize. |
44+
| contentMode | The content mode to use when scaling the view. The default value is ContentMode.aspectFit. |
45+
46+
**Return Value**
47+
48+
A new view that scales the original view to the specified size.
49+
50+
**Example Usage**
51+
52+
```swift
53+
Image("my-image")
54+
.scale(CGSize(width: 100, height: 100), contentMode: .fill)
55+
```
56+
57+
In this example, the Image view is scaled to a size of `100` points by `100` points while maintaining its aspect ratio. The `contentMode` parameter is set to `.fill`, which means that the image is stretched to fill the available space, possibly cutting off some of the edges.
58+

Documentation/Appearance/Images.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Images
2+
3+
ChatUI provides image objects as an extension of the Image class in SwiftUI, where each image is created as a static variable with a default value being an image with a specific system name. These image names can be used to display icons, avatars, and other images. The names of these images can be used in the code to display the respective icon for various purposes in the user interface.
4+
5+
| Property Name | Type | Default Value | Description |
6+
| --- | --- | --- | --- |
7+
| menu | Image | Image(systemName: "circle.grid.2x2.fill") | Icon for a menu |
8+
| camera | Image | Image(systemName: "camera.fill") | Icon for a camera |
9+
| photoLibrary | Image | Image(systemName: "photo") | Icon for a photo library |
10+
| mic | Image | Image(systemName: "mic.fill") | Icon for a microphone |
11+
| giphy | Image | Image(systemName: "face.smiling.fill") | Icon for GIPHY |
12+
| send | Image | Image(systemName: "paperplane.fill") | Icon for sending a message |
13+
| buttonHidden | Image | Image(systemName: "chevron.right") | Icon for a hidden button |
14+
| directionDown | Image | Image(systemName: "chevron.down") | Icon for a downward direction |
15+
| location | Image | Image(systemName: "location.fill") | Icon for a location |
16+
| document | Image | Image(systemName: "paperclip") | Icon for a document |
17+
| music | Image | Image(systemName: "music.note") | Icon for music |
18+
| sending | Image | Image(systemName: "circle.dotted") | Icon for a message that is currently being sent |
19+
| sent | Image | Image(systemName: "checkmark.circle") | Icon for a sent message |
20+
| delivered | Image | Image(systemName: "checkmark.circle.fill") | Icon for a delivered message |
21+
| failed | Image | Image(systemName: "exclamationmark.circle") | Icon for a failed message |
22+
| downloadFailed | Image | Image(systemName: "icloud.slash") | Icon for a failed download |
23+
| close | Image | Image(systemName: "xmark.circle.fill") | Icon for closing a window |
24+
| flip | Image | Image(systemName: "arrow.triangle.2.circlepath") | Icon for flipping an object |
25+
| delete | Image | Image(systemName: "trash") | Icon for deleting an object |
26+
| pause | Image | Image(systemName: "pause.circle.fill") | Icon for pausing an activity |
27+
| play | Image | Image(systemName: "play.circle.fill") | Icon for playing an activity |
28+
| person | Image | Image(systemName: "person.crop.circle.fill") | Icon for a person |
29+
30+
The example usage in the code demonstrates how to use these images to display the send icon, by making the icon resizable, setting its size, and clipping it to a circle shape.
31+
32+
```swift
33+
Image.send
34+
.resizable()
35+
.frame(width: 100, height: 100)
36+
.clipShape(Circle())
37+
```
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Typography
2+
3+
| Property Name | Type | Description | Default Value |
4+
| --- | --- | --- | --- |
5+
| messageBody | Font | The font used in message's body. | .subheadline |
6+
| caption | Font | The font used in additional minor information such as date. | .caption |
7+
| footnote | Font | The font used in additional major information such as sender's name. | .footnote |
8+
| title | Font | The font used in the title such as the title of the channel in ChannelInfoView. | .headline |
9+
| subtitle | Font | The font used in the subtitle such as the subtitle of the channel in ChannelInfoView. | .footnote |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ChannelInfoView
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# MessageField
2+
3+
The message field is a UI component for sending messages.
4+
5+
## How to send a new message
6+
7+
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.
8+
9+
```swift
10+
MessageField { messageStyle in
11+
viewModel.sendMessage($0)
12+
}
13+
```
14+
15+
### Supported message styles
16+
17+
- [x] text
18+
- [x] voice
19+
- [x] photo library
20+
- [x] giphy
21+
- [x] location
22+
- [ ] camera (*coming soon*)
23+
- [ ] document (*coming soon*)
24+
- [ ] contacts (*coming soon*)
25+
26+
## Handling menu items
27+
28+
```swift
29+
MessageField(isMenuItemPresented: $isMenuItemPresented) { ... }
30+
31+
if isMenuItemPresented {
32+
MyMenuItemList()
33+
}
34+
```
35+
36+
## Sending location
37+
38+
To send a location, you can use the `LocationSelector` component, which presents a UI for the user to select a location. When the user taps the send location button, the `onSend` action of the `MessageField` is called.
39+
40+
> **NOTE:**
41+
>
42+
> If you want to use `sendMessagePublisher` instead `onSend`, please refer to [Sending a new message by using publisher](https://www.notion.so/ChatUI-ab3dddb98c44434d993c96ae9da6b929#d918e619224147958c840e678c93890a)
43+
44+
```swift
45+
@State private var showsLocationSelector: Bool = false
46+
47+
var body: some View {
48+
LocationSelector(isPresented: $showsLocationSelector)
49+
}
50+
```
51+
52+
## Sending a new message by using publisher
53+
54+
```swift
55+
public var sendMessagePublisher: PassthroughSubject<MessageStyle, Never>
56+
```
57+
58+
`sendMessagePublisher` is a Combine `Publisher` that passes `MessageStyle` object.
59+
60+
### How to publish
61+
62+
To publish a new message, you can create a new `MessageStyle` object and send it using `send(_:)`.
63+
64+
```swift
65+
let _ = Empty<Void, Never>()
66+
.sink(
67+
receiveCompletion: { _ in
68+
// Create `MessageStyle` object
69+
let style = MessageStyle.text("{TEXT}")
70+
// Publish the created style object via `send(_:)`
71+
sendMessagePublisher.send(style)
72+
},
73+
receiveValue: { _ in }
74+
)
75+
```
76+
77+
### How to subscribe
78+
79+
You can subscribe to `sendMessagePublisher` to handle new messages.
80+
81+
```swift
82+
.onReceive(sendMessagePublisher) { messageStyle in
83+
// Handle `messageStyle` here (e.g., sending message with the style)
84+
}
85+
```
86+
87+
### Use cases
88+
- rating system
89+
- answering by defined message
90+
91+
- - -
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# MessageList
2+
3+
## Lists messages in row contents
4+
5+
In the constructor, you can list message objects that conform to `MessageProtocol` to display messages using the `rowContent` parameter.
6+
7+
All the body and row contents are flipped vertically so that new messages can be listed from the bottom.
8+
9+
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`.
10+
11+
sending → failed → sent → delivered → seen
12+
13+
## Scrolls to bottom
14+
15+
When a new message is sent or the scroll button is tapped, the view automatically scrolls to the bottom. You can also scroll the message list in other situations using the `scrollDownPublisher` by subscribing to it. See the following examples for how to use it.
16+
17+
### How to publish
18+
19+
```swift
20+
let _ = Empty<Void, Never>()
21+
.sink(
22+
receiveCompletion: { _ in
23+
scrollDownPublisher.send(())
24+
},
25+
receiveValue: { _ in }
26+
)
27+
```
28+
29+
### How to subscribe
30+
31+
```swift
32+
.onReceive(scrollDownPublisher) { _ in
33+
withAnimation {
34+
scrollView.scrollTo(id, anchor: .bottom)
35+
}
36+
}
37+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# MessageRow
2+
3+
## Displays message content
4+
5+
This is a view that is provided by default in ChatUI to display message information.
6+
7+
It shows the following information:
8+
9+
- Message content
10+
- Message sent date
11+
- Message sender information
12+
- Message delivery status
13+
14+
## Message Delivery Status
15+
16+
The message delivery status can be one of the following:
17+
18+
- sending
19+
- failed
20+
- sent
21+
- delivered
22+
- seen

Package.resolved

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "giphy-ios-sdk",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/Giphy/giphy-ios-sdk",
7+
"state" : {
8+
"revision" : "699483a3a2b534e9dc3a3ab85a9f7095e306bde1",
9+
"version" : "2.2.2"
10+
}
11+
},
12+
{
13+
"identity" : "libwebp-xcode",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/SDWebImage/libwebp-Xcode",
16+
"state" : {
17+
"revision" : "4f52fc9b29600a03de6e05af16df0d694cb44301",
18+
"version" : "1.2.4"
19+
}
20+
}
21+
],
22+
"version" : 2
23+
}

0 commit comments

Comments
 (0)