默认
发表评论 0
想开发IM:买成品怕坑?租第3方怕贵?找开源自已撸?尽量别走弯路了... 找站长给点建议
SwiftUI 集成 IMKit
阅读(757) | 评论(0 收藏 淘帖
Swift UI 集成 IMKit
在 SwiftUI 中,集成 IMKit 中 RCConversationListViewController 和 RCConversationViewController 两页面可能存在以下问题:
1、直接在 View 中使用,两个页面会错位;
2、用 NavigationView 集成会话列表和会话页面,标题失效;

分析
这两个页面强依赖导航 UINavigationController,并且内部用的 frame 结算的布局。直接用放入 View 中会导致安全区域失效,导致 frame 计算错误。

struct ContentView: View {
var body: some View {
ChatListView()
}
}
在 SwiftUI 中,UIKit 的 UINavigationController 和 NavigationView 的标题兼容性不太好,在二级页面设置 navigationBar 的 title 不生效。

解决方案
开发者需要用 UIViewControllerRepresentable 将 UIKit 的页面转换一下:

struct ChatListView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let displayConversationTypeArray = [
RCConversationType.ConversationType_PRIVATE.rawValue,
RCConversationType.ConversationType_GROUP.rawValue,
]
let collectionConversationType = [
RCConversationType.ConversationType_SYSTEM.rawValue
]
guard let conversationList = RCDChatsViewController(
displayConversationTypes: displayConversationTypeArray,
collectionConversationType: collectionConversationType
) else {
return UIViewController()
}
return UINavigationController(rootViewController: conversationList);
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}
然后在合适的地方使用,比如 ContentView 中,注意,需要使用 ignoresSafeArea 忽略安全区域。

struct ContentView: View {
var body: some View {
ChatListView()
.ignoresSafeArea()
}
}

即时通讯网 - 即时通讯开发者社区! 来源: - 即时通讯开发者社区!

上一篇:群聊中如何开启位置实时共享下一篇:没有点击挂断,一端杀死程序另一端需等待1分钟响应
推荐方案
打赏楼主 ×
使用微信打赏! 使用支付宝打赏!

返回顶部