I want to integrate a third party chat SDK and they don't have React Native support. It's my first time working with Native Modules and from what I've seen I can only derive from NSObject to expose my swift module to obj C then that gets exposed to React Native side.
Right now, I have this native module code snippet in swift:
@objc
@IBAction func showAnswerBot() {
do {
let answerBotEngine = try AnswerBotEngine.engine()
let supportEngine = try SupportEngine.engine()
let messagingConfiguration = MessagingConfiguration()
DispatchQueue.main.async {
if let viewController = try? Messaging.instance.buildUI(engines: [answerBotEngine, supportEngine],
configs: [messagingConfiguration]) {
let nvc = UINavigationController(rootViewController: viewController)
nvc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "back", style: .plain, target: self, action: "backAction")
UIApplication.shared.keyWindow?.rootViewController?.present(nvc, animated: true, completion: nil)
}
}
} catch {
// do something with error
}
}
@objc
@IBAction func backAction() -> Void {
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true)
}
Here is my interface for objc code:
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(ZendeskMessagingChatModule, NSObject)
RCT_EXTERN_METHOD(showAnswerBot)
@end
Right now "this works" in that it exposes the chat window as a modal window in my app but the user can't go back or cancel the chat/close the window even though I set the backbutton on the navigation item. I want to add the cancel button at the top but I'm not sure what I'm doing wrong here?
What am I missing above?
Thanks!