Last active
April 19, 2021 10:20
-
-
Save Sunilkumarr/f971f1433846bf2c4dedc797bab48eaf to your computer and use it in GitHub Desktop.
Custom back button in one to one or group chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Find the method launchChatWith(contactId in ALChatmanager.swift file and replace it with below code for adding custom back button | |
func launchChatWith(contactId: String, from viewController: UIViewController, configuration: ALKConfiguration, prefilledMessage: String? = nil) { | |
let alContactDbService = ALContactDBService() | |
var title = "" | |
if let alContact = alContactDbService.loadContact(byKey: "userId", value: contactId), let name = alContact.getDisplayName() { | |
title = name | |
} | |
title = title.isEmpty ? "No name" : title | |
let convViewModel = ALKConversationViewModel(contactId: contactId, channelKey: nil, localizedStringFileName: configuration.localizedStringFileName, prefilledMessage: prefilledMessage) | |
let conversationViewController = ALKConversationViewController(configuration: configuration) | |
conversationViewController.viewModel = convViewModel | |
var backImage = UIImage(named: "icon_back", in: Bundle(for: ALKConversationListViewController.self), compatibleWith: nil) | |
backImage = backImage?.imageFlippedForRightToLeftLayoutDirection() | |
let backButton = UIBarButtonItem( | |
image: backImage, | |
style: .plain, | |
target: self, | |
action: #selector(self.customBackAction) | |
) | |
conversationViewController.navigationItem.leftBarButtonItems = [backButton] | |
launch(viewController: conversationViewController, from: viewController) | |
} | |
@objc func customBackAction() { | |
let pushassets = ALPushAssist() | |
let topVC = pushassets.topViewController | |
guard let nav = topVC?.navigationController else { return } | |
let poppedVC = nav.popViewController(animated: true) | |
if poppedVC == nil { | |
topVC?.dismiss(animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment