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 + IMKitIMLib + 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 组合(无单一门面)

迁移步骤​

  1. 先接入 IMLib 与 Global UIKit 包(可与 IMKit 共存,互不覆盖)。
  2. 把 IMKit 页面替换为 `ChatListViewController` / `ChatViewController`,宿主实现 Delegate 的导航与详情。
  3. 把页面内的数据拼装逻辑迁到 ViewModel;自定义渲染逻辑迁到 Cell / CellModel 分支。
  4. 把主题从 IMKit 令牌迁到 `ChatUITheme`(palette / typography / layout)。
  5. 把导航迁到 `ChatRouter`(或自定义实现),保持深链与埋点一致。
  6. 回归:会话列表、聊天、发送、已读、撤回、历史分页、断线重连、主题切换。

共存策略​

  • 两套 UI 可同时存在:新页面用 Global UIKit,旧页面保留 IMKit,共享同一个 IMLib 客户端。
  • 不要在同一页面混用两套组件(事件与状态会重复绑定)。
  • 迁移期保持 IMKit 组件版本与 Global UIKit 版本同源(同一 SDK 发行版)。

相关:iOS IMKit、IMKit ConversationListView、Global UIKit 快速开始。