Skip to content

Instantly share code, notes, and snippets.

@Sunilkumarr
Last active April 19, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sunilkumarr/f971f1433846bf2c4dedc797bab48eaf to your computer and use it in GitHub Desktop.
Save Sunilkumarr/f971f1433846bf2c4dedc797bab48eaf to your computer and use it in GitHub Desktop.
Custom back button in one to one or group chat
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