会话页面
自定义会话页面按钮UI
从 1.6.0 版本开始,IMKit 支持配置会话页面的 UI 组件。可通过 setConversationContentComponentConfig 接口设置自定义组件配置。
接口定义
TypeScript
setInputAreaComponentConfig(componentConfig: InputAreaComponentConfig): void;
参数说明
ConversationContentComponentConfig
| 参数名 | 类型 | 必填 | 说明 | 支持版本 |
|---|---|---|---|---|
identifier | ComponentIdentifier | 是 | 组件标识,支持的类型:ConversationUnreadMessageButton(未读消息按钮)、ConversationUnreadMentionedMessageButton(未读@我的消息按钮)、ConversationNewReceivedUnreadMessageButton(新收到的未读消息按钮) | 1.6.0 |
component | WrappedBuilder<[ConversationContentComponentData]> | 是 | 自定义组件构建器 | 1.6.0 |
ConversationContentComponentData
| 参数名 | 类型 | 说明 | 支持版本 |
|---|---|---|---|
context | Context | 应用上下文对象 | 1.6.0 |
convId | ConversationIdentifier | 会话标识对象 | 1.6.0 |
data | number | 透传参数。当 identifier 为 ConversationNewReceivedUnreadMessageButton 时,代表在会话中新收到的未读消息的数量;当 identifier 为 ConversationUnreadMessageButton 时,代表会话中的未读消息数量;当 identifier 为 ConversationUnreadMentionedMessageButton 时,代表当前@自己的未读消息的数量 | 1.6.0 |
conversationViewModel | IConversationViewModel | 会话页面 ViewModel,用来执行后续的事件。当 identifier 为 ConversationNewReceivedUnreadMessageButton 时,调用 onClickNewReceivedUnreadMessageButton 执行新收到未读消息的点击事件;当 identifier 为 ConversationUnreadMessageButton 时,调用 onClickUnreadMessageButton 执行未读消息的点击事件;当 identifier 为 ConversationUnreadMentionedMessageButton 时,调用 onClickUnreadMentionedMessageButton 执行未读@我的消息的点击事件 | 1.6.0 |
IConversationViewModel
| 方法名 | 返回值 | 说明 | 支持版本 |
|---|---|---|---|
onClickUnreadMessageButton | void | 进入会话时展示的未读消息的组件点击事件 | 1.6.0 |
onClickUnreadMentionedMessageButton | void | 进入会话时展示的未读@我的消息的组件点击事件 | 1.6.0 |
onClickNewReceivedUnreadMessageButton | void | 在进入会话后收到未读新消息的组件点击事件 | 1.6.0 |
getInputTextAreaContent | string | 获取输入框当前的文本输入组件的内容 | 1.7.1 |
getMessageList | UiMessage[] | 获取消息列表。注意:该返回列表仅用于读取,不建议修改 | 1.7.1 |
refreshUiMessage | void | 刷新某条消息 | 1.7.1 |
使用示例
以下展示了进入会话后收到未读新消息的组件的自定义示例:
- 使用
alignRules控制在屏幕中的位置 - 使用
ConversationContentComponentData.data观察未读消息数 - 使用
ConversationContentComponentData.conversationViewModel暴露 会话页面能力,用来处理点击事件
示例 1:自定义未读消息按钮
TypeScript
@Builder
export function buildCustomConversationTopUnreadMessageButton(data: ConversationContentComponentData) {
CustomConversationTopUnreadMessageButton({ context: data.context, convId: data.convId, unreadMessageCount: data.data, viewModel:data.conversationViewModel })
}
@Component
export struct CustomConversationTopUnreadMessageButton {
@Prop context: Context;
@Prop convId: ConversationIdentifier;
@Prop unreadMessageCount: number;
@Prop viewModel: IConversationViewModel;
build() {
if (this.unreadMessageCount > 10) {
Row() {
Image($r('app.media.rc_arrow')).width(12).height(9).objectFit(ImageFit.Contain)
Text((this.unreadMessageCount > 99 ? "99+" : this.unreadMessageCount) + "条新消息")
.fontSize(14)
.fontColor($r('app.color.rc_color_111F2C'))
.margin({ left: 6 })
}
.borderRadius({ topLeft: 24, bottomLeft: 24 })
.height(48)
.padding({ left: 10, right: 10 })
.backgroundColor($r('app.color.rc_color_FFFFFF'))
.alignRules({
center: { anchor: "__container__", align: VerticalAlign.Center },
right: { anchor: "__container__", align: HorizontalAlign.End }
})
.margin({ top: 14 })
.onClick(() => {
this.viewModel.onClickUnreadMessageButton()
})
}
}
}
// 设置UI组件
let ConversationUnreadMessageButton: ConversationContentComponentConfig = {
identifier: ComponentIdentifier.ConversationUnreadMessageButton,
component: wrapBuilder(buildCustomConversationTopUnreadMessageButton),
}
RongIM.getInstance().conversationService().setConversationContentComponentConfig(ConversationUnreadMessageButton)
示例 2:设置其他按钮组件
TypeScript
// 自定义收到新的未读消息的UI组件
let ConversationNewReceivedUnreadMessageButton: ConversationContentComponentConfig = {
identifier: ComponentIdentifier.ConversationNewReceivedUnreadMessageButton,
component: wrapBuilder(buildCustomConversationBottomUnreadMessageButton),
}
RongIM.getInstance().conversationService().setConversationContentComponentConfig(ConversationNewReceivedUnreadMessageButton)
// 自定义顶部未读@我的消息的UI组件
let ConversationUnreadMentionedMessageButton: ConversationContentComponentConfig = {
identifier: ComponentIdentifier.ConversationUnreadMentionedMessageButton,
component: wrapBuilder(buildCustomConversationTopUnreadMentionedMessageButton),
}
RongIM.getInstance().conversationService().setConversationContentComponentConfig(ConversationUnreadMentionedMessageButton)
修改消息可撤回的最大时间
IMKit 默认允许在消息发送后 180 秒内撤回。您可以通过全局配置调整该上限,需要在会话页面展示前设置。
接口定义
TypeScript
setMaxRecallDuration(duration: number): void