Skip to content

Commit

Permalink
Merge pull request #952 from haoxiuwen/doc-v2
Browse files Browse the repository at this point in the history
Add iOS UIKit Docs
  • Loading branch information
haoxiuwen authored Sep 19, 2024
2 parents 512e314 + 933cd14 commit bb3f70b
Show file tree
Hide file tree
Showing 12 changed files with 686 additions and 208 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion docs/.vuepress/sidebar/uikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ const chatUikitSidebar = [
{ text: '进阶用法', link: 'chatuikit_advancedusage.html' },
{ text: '可配项', link: 'chatuikit_config_item.html' },
{ text: '主题', link: 'chatuikit_theme.html' },
{ text: '自定义', link: 'chatuikit_customize.html' },
{ text: '界面风格',
collapsible: true,
children: [
{ text: '会话列表页面', link: 'chatuikit_custom_contact_list.html' },
{ text: '聊天页面', link: 'chatuikit_custom_chat.html' },
{ text: '联系人列表页面', link: 'chatuikit_custom_contact_list.html' },
{ text: '联系人详情页面', link: 'chatuikit_custom_contact_details.html' },
{ text: '群详情页面', link: 'chatuikit_custom_group_details.html' },
],
},
{ text: '事件监听', link: 'chatuikit_listener.html' },
{ text: '拦截主要页面点击跳转事件', link: 'chatuikit_customize_clickjump.html' },
],
Expand Down
122 changes: 0 additions & 122 deletions docs/uikit/chatuikit/ios/chatuikit_config_item.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,128 +42,6 @@

11. `Appearance.avatarPlaceHolder = value` 头像占位图。

## 会话列表可配项

1. `Appearance.conversation.rowHeight = value`:会话列表 Cell 的高度。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_rowHeight.png)

2. `Appearance.conversation.swipeLeftActions = value`/`Appearance.conversation.swipeRightActions = value`:会话列表左滑菜单项和右滑菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_swipeLeftActions.png)

3. `Appearance.conversation.moreActions = value`:右滑会话后出现的 `...` 菜单项点击后的 ActionSheet 的菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_swipe_right_more.png)

4. `Appearance.conversation.singlePlaceHolder = value` 会话列表单聊会话头像占位图和群聊会话头像占位图。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_placeHolder.png)

5. `Appearance.conversation.dateFormatToday = value`/`Appearance.conversation.dateFormatOtherDay = value`:今天和今天之外的日期格式。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_dateFormat.png)

6. `Appearance.conversation.listMoreActions = value`:点击会话列表右上角的 `+` 之后的 ActionSheet 的菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/conversation/Appearance_conversation_list_more.png)

## 联系人列表及其后续页面可配项

1. `Appearance.contact.rowHeight = value`:联系人列表 Cell 的高度。

![img](/images/uikit/chatuikit/ios/configurationitem/contact/Appearance_contact_rowHeight.png)

2. `Appearance.contact.headerRowHeight = value`:联系人列表 Header Cell 的高度。

![img](/images/uikit/chatuikit/ios/configurationitem/contact/Appearance_contact_headerRowHeight.png)

3. `Appearance.contact.listHeaderExtensionActions = value`:联系人列表 Header List 数据源。

![img](/images/uikit/chatuikit/ios/configurationitem/contact/Appearance_contact_listHeaderExtensionActions.png)

4. `Appearance.contact.detailExtensionActionItems = value`:联系人以及群组详情 header 中可配菜单项,主要功能包括聊天、音视频通话等。

![img](/images/uikit/chatuikit/ios/configurationitem/contact/Appearance_contact_detailExtensionActionItems.png)

5. `Appearance.contact.moreActions = value`:联系人以及群组详情右上角的 `...` 点击后的 ActionSheet 的菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/contact/Appearance_contact_moreActions.png)


## 聊天页面可配项

1. `Appearance.chat.maxInputHeight = value`:聊天页面输入框最大输入高度。

2. `Appearance.chat.inputPlaceHolder = value`:聊天页面输入框默认占位符。

3. `Appearance.chat.inputBarCorner = value`:聊天页面输入框圆角。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_input.png)

4. `Appearance.chat.bubbleStyle = value`:聊天页面消息气泡的样式分为带箭头与多圆角两种。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_bubbleStyle.png)

5. `Appearance.chat.contentStyle = value`:聊天页面消息中显示内容的可配项数组,可以将不想要的功能移除即可。可配置项有是否显示昵称、是否显示头像、是否显示 reply、是否显示reaction、是否显示 thread、是否显示时间等。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_contentStyle.png)

6. `Appearance.chat.messageLongPressedActions = value`:聊天页面长按消息后的 ActionSheet 菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_messageLongPressedActions.png)

7. `Appearance.chat.reportSelectionTags = value`:聊天页面非法消息的举报类型。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_report.png)

8. `Appearance.chat.reportSelectionReasons = value`:聊天页面非法消息的举报原因。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_report.png)

9. `Appearance.chat.inputExtendActions = value`:聊天页面输入框右侧 `+` 点击后 ActionSheet 菜单项。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_input.png)

10. `Appearance.chat.dateFormatToday = value`/`Appearance.chat.dateFormatOtherDay = value`:聊天页面消息今天和今天之外的日期格式。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_dateFormat.png)

11. `Appearance.chat.audioDuration = value`:聊天页面语音消息录制的最大时长,默认为 60 秒。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_audioDuration.png)

12. `Appearance.chat.receiveAudioAnimationImages = value`/`Appearance.chat.sendAudioAnimationImages = value`:聊天页面接收方/发送方语音消息播放时的动画图片。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_receiveAudioAnimationImages.png)

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_bubbleColor.png)

13. `Appearance.chat.receiveTextColor = value`/`Appearance.chat.sendTextColor = value`:聊天页面接收方/发送方消息文字颜色。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_textColor.png)

14. `Appearance.chat.imageMessageCorner = value`:聊天页面图片消息圆角,默认为 4。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_imageMessageCorner.png)

15. `Appearance.chat.imagePlaceHolder = value`:聊天页面图片消息占位图。

16. `Appearance.chat.videoPlaceHolder = value`:聊天页面视频消息占位图。

17. `Appearance.chat.recallExpiredTime = value`:聊天页面消息撤回的有效时间,默认为 120 秒。

18. `Appearance.chat.newMessageSoundPath = value`:聊天页面收到新消息时的播放音频文件的路径。

19. `Appearance.chat.receiveTranslationColor = value`:消息接收方翻译文本颜色。

20. `Appearance.chat.sendTranslationColor = value`:消息发送方翻译文本颜色。

21. `Appearance.chat.enableTranslation = value`:是否开启文本消息长按翻译功能,默认为 `false`,即该功能默认关闭。如需开启该特性,需设置为 `true`

22. `Appearance.chat.targetLanguage = value`:翻译目标语言默认为中文。





Expand Down
212 changes: 212 additions & 0 deletions docs/uikit/chatuikit/ios/chatuikit_custom_chat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# 设置聊天页面

你可以配置聊天页面的头部导航栏、消息列表项、输入框和跳转事件等。详见 [MessageListController.swift](https://github.com/easemob/easemob-uikit-ios/blob/main/Sources/EaseChatUIKit/Classes/UI/Components/Conversation/Controllers/ConversationListController.swift)

![img](/images/uikit/chatuikit/ios/custom_chat.png)

## 自定义头部导航栏

聊天页面、会话列表页面、联系人列表页面、群详情页面和联系人详情页面的标题栏均使用 `EaseChatNavigationBar`。如果聊天页面(`MessageListController.swift`)的标题栏不满足需求,建议自定义标题栏,重载方法传入自定义的导航类。关于头部导航栏中的标题、头像、背景色、导航栏右侧按钮的显示图片和左侧的头像,详见[自定义会话列表页面的头部标题栏](chatuikit_custom_conversation_list.html#自定义头部导航栏)

## 自定义消息列表项

要自定义消息表中列表项的内容,即各种消息类型的 Cell,你需要执行以下步骤:

1. 继承 `EaseChatUIKit` 中对应的消息 Cell 类,注册新的自定义类。

2. 重载对应的方法。

每个对应的消息类型 Cell 中都有初始化方法、气泡中内容 `createContent``refresh` 方法可重载,以及其他各种小模块的 UI 创建重载方法等。

如果需要复用已有逻辑再增加新逻辑,则只需重载对应方法后调用 `super.xxx`,例如:

```Swift
override open func refresh(entity: MessageEntity) {
super.refresh(entity:entity)
//继续你的新逻辑
}
```

如果需要修改之前的逻辑,则需复制之前的 `refresh ` 方法中的代码进行修改,无需调用 `super.xxxx`

| 消息 Cell 类 | 描述 | 注册重载对应属性 |
| --------------------- | ------------------ | ------------------------------------------------------------ |
| `TextMessageCell ` | 文本消息 | `ComponentsRegister.shared.ChatTextMessageCell = YourTextMessageCell.self` |
| `ImageMessageCell` | 图片消息 | `ComponentsRegister.shared.ChatImageMessageCell = YourImageMessageCell.self` |
| `AudioMessageCell` | 音频消息 | `ComponentsRegister.shared.ChatAudioMessageCell = YourAudioMessageCell.self` |
| `VideoMessageCell` | 视频消息 | `ComponentsRegister.shared.ChatVideoMessageCell = YourVideoMessageCell.self` |
| `FileMessageCell` | 文件消息 | `ComponentsRegister.shared.ChatFileMessageCell = YourFileMessageCell.self` |
| `ContactCardCell` | 联系人卡片消息 | `ComponentsRegister.shared.ChatContactMessageCell = YourContactCardCell.self` |
| `LocationMessageCell` | 位置消息 | `ComponentsRegister.shared.ChatLocationCell = YourLocationMessageCell.self` |
| `CombineMessageCell` | 合并转发消息 | `ComponentsRegister.shared.ChatCombineCell = YourCombineMessageCell.self` |
| `AlertMessageCell` | 提示消息 | `ComponentsRegister.shared.ChatAlertCell = YourAlertMessageCell.self` |
| `CustomMessageCell` | 自定义消息 | `ComponentsRegister.shared.ChatCustomMessageCell = YourCustomMessageCell.self` |

### 设置消息气泡的样式

你可以通过 `Appearance.chat.bubbleStyle = withArrow` 设置聊天页面消息气泡的样式,分为带箭头与多圆角两种。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_bubbleStyle.png)

### 设置消息气泡中的内容

你可以通过 `Appearance.chat.contentStyle = [.withReply,.withAvatar,.withNickName,.withDateAndTime]` 设置聊天页面消息中显示内容的可配项数组,默认展示回复消息气泡,消息发送方头像,消息发送方昵称,消息的日期时间。

你可以将不需要的功能移除,也还可添加表情回应(`MessageReaction`)和话题(`MessageThread`)。**注意,添加表情回应和话题功能前,需在[环信即时通讯控制台](https://console.easemob.com/user/login)开通。**

```Swift
//是否显示消息话题。
if self.messageThread {
Appearance.chat.contentStyle.append(.withMessageThread)
}
//是否显示表情回应
if self.messageReaction {
Appearance.chat.contentStyle.append(.withMessageReaction)
}
```

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_contentStyle.png)

### 设置消息文字颜色

你可以通过 `Appearance.chat.receiveTextColor = value`/`Appearance.chat.sendTextColor = value` 设置聊天页面接收方/发送方的消息文字颜色。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_textColor.png)

### 设置消息日期

- `Appearance.chat.dateFormatToday = "HH:mm"`:设置聊天页面消息的当日格式
- `Appearance.chat.dateFormatOtherDay = "MM-dd HH:mm"` 设置聊天页面消息的当日之外的日期格式。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_dateFormat.png)

### 设置附件消息

- 设置语音消息录制的最大时长

你可以通过 `Appearance.chat.audioDuration = value` 设置聊天页面语音消息录制的最大时长,默认为 60 秒。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_audioDuration.png)

- 设置语音消息播放时的动画

1. `Appearance.chat.receiveAudioAnimationImages = value`:设置聊天页面接收方语音消息播放时的动画图片。
2. `Appearance.chat.sendAudioAnimationImages = value`:设置聊天页面发送方语音消息播放时的动画图片。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_receiveAudioAnimationImages.png)

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_bubbleColor.png)

- 设置图片消息圆角

你可以通过 `Appearance.chat.imageMessageCorner = value` 设置聊天页面图片消息圆角,默认为 4。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_imageMessageCorner.png)

- 设置图片/视频消息占位图

- `Appearance.chat.imagePlaceHolder = value`:聊天页面图片消息占位图。

- `Appearance.chat.videoPlaceHolder = value`:聊天页面视频消息占位图。

### 设置消息撤回时间

你可以通过 `Appearance.chat.recallExpiredTime = value` 设置聊天页面消息撤回的有效时间,默认为 120 秒。

### 设置收到新消息时播放音频文件的路径

你可以通过 `Appearance.chat.newMessageSoundPath = value` 设置聊天页面收到新消息时的播放音频文件的路径。

### 设置消息翻译

- `Appearance.chat.enableTranslation = value`:是否开启文本消息长按翻译功能,默认为 `false`,即该功能默认关闭。如需开启该特性,需设置为 `true`
- `Appearance.chat.targetLanguage= .Chinese` 翻译目标语言,默认为中文。文本消息长按后出现**翻译**菜单,点击**翻译**后,设置翻译的目标语言。使用前,你需在[环信即时通讯云控制台](https://console.easemob.com/user/login)申请试用翻译功能,然后将 `Appearance.chat.enableTranslation` 设置为 `true`,才会出现文本消息长按的翻译功能。若后台申请翻译未通过,前端无法成功调用 API 进行翻译。
- `Appearance.chat.receiveTranslationColor = value`:消息接收方翻译文本颜色。
- `Appearance.chat.sendTranslationColor = value`:消息发送方翻译文本颜色。

### 设置消息长按后显示的操作

你可以通过 `Appearance.chat.messageLongPressedActions = value` 设置聊天页面长按消息后的 `ActionSheet` 菜单项。你可以继承 `MessageListController`,重载页面中的方法,移除或添加长按消息后的动作(action)。

```Swift
override func filterMessageActions(message: MessageEntity) -> [ActionSheetItemProtocol] {
if let ext = message.message.ext,let value = ext[callIdentifier] as? String,value == callValue {
return [
ActionSheetItem(title: "barrage_long_press_menu_delete".chat.localize, type: .normal,tag: "Delete",image: UIImage(named: "message_action_delete", in: .chatBundle, with: nil)),
ActionSheetItem(title: "barrage_long_press_menu_multi_select".chat.localize, type: .normal,tag: "MultiSelect",image: UIImage(named: "message_action_multi_select", in: .chatBundle, with: nil)),
ActionSheetItem(title: "barrage_long_press_menu_forward".chat.localize, type: .normal,tag: "Forward",image: UIImage(named: "message_action_forward", in: .chatBundle, with: nil))
]
} else {
return super.filterMessageActions(message: message)
}
}
```

获取某个 action 的点击事件,示例代码:

```Swift
Appearance.chat.messageLongPressedActions.first { $0.tag == "xxx" }?.action = { [weak self ] in
//action handler
}
```

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_messageLongPressedActions.png)

## 设置聊天页面输入框

- `Appearance.chat.maxInputHeight = value`:聊天页面输入框最大输入高度。

- `Appearance.chat.inputPlaceHolder = value`:聊天页面输入框默认占位符。

- `Appearance.chat.inputBarCorner = value`:聊天页面输入框圆角。

- `Appearance.chat.inputExtendActions = value`:聊天页面输入框右侧 `+` 点击后 `ActionSheet` 菜单项。

获取某个 action 的点击事件,示例代码:

```Swift
Appearance.chat.inputExtendActions.first { $0.tag == "xxx" }?.action = { [weak self ] in
//action handler
}
```

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_input.png)

## 设置消息举报功能

你可以通过 `Appearance.chat.reportSelectionTags``Appearance.chat.reportSelectionReasons` 设置消息举报功能的举报标签数组以及对应的原因数组,key-value 格式,二者一 一对应。

![img](/images/uikit/chatuikit/ios/configurationitem/chat/Appearance_chat_report.png)

## 设置跳转事件

对于自定义跳转事件,可以查看聊天页面中的标记为 open 的可重载方法,进行对应的重载,即可跳转自己的业务页面。下表为重载常用的 API:

| 方法 | 描述 | 是否可重载 |
| ---------------------- | -------------------------------- | ---------- |
| `messageBubbleClicked` | 消息气泡点击。 ||
| `messageAvatarClick` | 消息头像点击。 ||
| `audioDialog` | 输入框音频按钮点击事件。 ||
| `attachmentDialog` | 输入框发送附件消息点击事件。 ||

## 拦截原有组件点击事件

拦截后的业务逻辑与 UI 刷新逻辑,你需要自己完全实现,建议使用注册继承即可更快速的实现需求。

消息列表事件如下所示:

- `replyClicked`:消息中引用消息气泡点击。

- `bubbleClicked`:消息气泡点击。

- `bubbleLongPressed`:消息气泡长按。

- `avatarClicked`:头像点击。

- `avatarLongPressed`:头像长按。

## 聊天页面其他设置

1. 其他标记为 open 的方法均为可重载方法。如有需要,可重载对应方法实现自己业务逻辑。

2. 关于聊天页面的其他配置,包括按钮、输入框等空间的色调以及弹窗的设置,详见[通用可配项文档](chatuikit_config_item.html)
Loading

0 comments on commit bb3f70b

Please sign in to comment.