Global IM UIKit 与 IMKit 的关系与迁移
两套 UI 都基于 IMLib,但结构不同:IMKit 是「继承式 ViewController + 组件协议」,Global IM UIKit 是「MVVM + 数据源/回调协议」。本页给出组件映射、迁移步骤与共存策略。
两代 UI 对比
| 维度 | IMKit(继承式) | Global IM UIKit(MVVM) |
|---|---|---|
| 入口 | `IMKitFacade` 门面 + 10 个组件 | 12 个组件:VC / VM / DataSource / Delegate / CellModel / Theme / Router |
| 状态 | ViewController 持有并直接更新视图 | ViewModel 持有状态机,视图订阅状态 |
| 定制 | 实现组件协议、替换渲染器、主题令牌 | 替换 ViewModel / DataSource / Router / Theme |
| 导航 | 宿主自行 push | `ChatRouter` 默认实现 + 可替换 |
| 依赖 | IMLib + IMKit | IMLib + IMKit(Global UIKit 依赖 IMKit 语义) |
| 适用 | 已有页面、轻量接入 | 新页面、需要可测试状态机与更强定制 |
组件映射
| IMKit 组件 | 职责 | Global IM UIKit 对应 |
|---|---|---|
ConversationListView | 会话列表 | ChatListViewController / ChatListViewModel / ChatListDataSource / ChatListDelegate |
ChatView | 会话详情(消息流 + 输入区) | ChatViewController / ChatViewModel / ChatDataSource / ChatDelegate |
MessageBubble | 消息气泡(按内容类型渲染) | ChatCellModel(渲染模型)+ 宿主 Cell |
MessageInput | 输入区 | ChatInputController |
Avatar | 头像 | 宿主 Cell / 头像视图(ChatCellModel.showAvatar 控制显隐) |
UnreadBadge | 未读/提及角标 | ChatListViewController 内建未读 / @ 角标 |
TimeSeparator | 时间分隔/格式化 | ChatCellModel.showTime(5 分钟规则) |
MessageStatusIndicator | 发送状态 | ChatCellModel.sendState / readCount |
Theme | 主题令牌 | ChatUITheme |
IMKitFacade | 组件门面/挂载入口 | ChatRouter + ViewController 组合(无单一门面) |
迁移步骤
- 先接入 IMLib 与 Global UIKit 包(可与 IMKit 共存,互不覆盖)。
- 把 IMKit 页面替换为 `ChatListViewController` / `ChatViewController`,宿主实现 Delegate 的导航与详情。
- 把页面内的数据拼装逻辑迁到 ViewModel;自定义渲染逻辑迁到 Cell / CellModel 分支。
- 把主题从 IMKit 令牌迁到 `ChatUITheme`(palette / typography / layout)。
- 把导航迁到 `ChatRouter`(或自定义实现),保持深链与埋点一致。
- 回归:会话列表、聊天、发送、已读、撤回、历史分页、断线重连、主题切换。
共存策略
- 两套 UI 可同时存在:新页面用 Global UIKit,旧页面保留 IMKit,共享同一个 IMLib 客户端。
- 不要在同一页面混用两套组件(事件与状态会重复绑定)。
- 迁移期保持 IMKit 组件版本与 Global UIKit 版本同源(同一 SDK 发行版)。