聊天页(消息流/输入/历史/已读/撤回)(ChatViewController)
聊天页(消息流/输入/历史/已读/撤回):ChatViewController 属于 ViewController(视图 / 生命周期 / 输入)。本页的 props / events / behaviors 来自 sdk-imkit.json → globalUIKit,声明与示例来自 bindings.ios.uikit,不手写漂移。
契约属性(props)
| 属性 | 类型 | 可选 | 说明 |
|---|---|---|---|
viewModel | ChatViewModel | 否 | 页面状态机(ChatListViewModel / ChatViewModel) |
theme | ChatUITheme | 否 | 主题令牌(ChatUITheme),浅色 / 深色预设或自定义 |
delegate | ChatDelegate? | 是 | 交互回调协议实现;只回调,不做导航 |
options | {showHistory:bool,showReadReceipt:bool,showTyping:bool} | 是 | 页面选项(由契约声明的可选字段,例如搜索栏 / 网络横幅 / 历史 / 已读 / typing) |
事件(events)
| 事件 | 参数 | 说明 |
|---|---|---|
send | text | 发送文本 |
tapMessage | message | 点击消息(图片 / 文件 / 位置等) |
tapAvatar | userId | 点击头像 |
requestMore | — | 上拉加载更多历史 |
readDetail | message | 查看已读明细 |
行为(behaviors)
- 消息按 seq 渲染、去重、发送中/失败/已读状态
- 上拉加载历史(beforeSeq 分页)
- 进入会话自动已读(可关闭)
- typing 指示与节流
- 键盘避让与滚动定位
- 撤回/已读明细回调由宿主展示
公开符号与声明
| 语言 | 声明 |
|---|---|
| Swift | IMPChatViewController(viewModel: IMPChatViewModel, theme: IMPChatUITheme, delegate: IMPChatDelegate?, options: IMPChatViewOptions?) |
| Objective-C | - (instancetype)initWithViewModel:(IMPOSGlobalChatViewModel *)viewModel theme:(IMPOSGlobalChatUITheme *)theme delegate:(id<IMPOSGlobalChatDelegate>)delegate options:(IMPOSGlobalChatViewOptions *)options; |
使用示例(Swift / Objective-C)
IMPChatViewController(viewModel: chatViewModel, theme: .light, delegate: nil, options: nil)IMPOSGlobalChatViewController *chatViewController =
[[IMPOSGlobalChatViewController alloc] initWithViewModel:self.viewModel theme:[IMPOSGlobalChatUITheme globalLight] delegate:nil options:nil];示例口径
示例由绑定签名与契约类型生成:构造函数参数、协议方法、属性名均来自契约;实际业务中把示例变量替换为宿主实例即可。
在架构中的位置
| 项 | 值 |
|---|---|
| 层 | ViewController(视图 / 生命周期 / 输入) |
| 依赖 | GlobalUIKit -> IMKit -> IMLib(公开接口) |
| 相关组件 | ChatViewModel、ChatDelegate、ChatInputController、ChatUITheme、ChatRouter |
错误处理
ViewModel 层通过事件上报错误(如 error(err));错误码与处理建议见 Global IM UIKit 错误处理、状态码(运行时 43 条)与 状态码全量对照(440 条)。