import UIKit
import CometChatUIKitSwift
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Apply custom theme before initializing CometChat
applyBrandTheme()
return true
}
private func applyBrandTheme() {
// Your brand colors
let brandPrimary = UIColor(hex: "#1E88E5") // Blue
let brandSecondary = UIColor(hex: "#FFC107") // Amber
// Apply to CometChat theme
CometChatTheme.primaryColor = brandPrimary
// Customize backgrounds
CometChatTheme.backgroundColor01 = UIColor { trait in
trait.userInterfaceStyle == .dark
? UIColor(hex: "#0D1117")
: UIColor(hex: "#FFFFFF")
}
CometChatTheme.backgroundColor02 = UIColor { trait in
trait.userInterfaceStyle == .dark
? UIColor(hex: "#161B22")
: UIColor(hex: "#F6F8FA")
}
// Customize text
CometChatTheme.textColorPrimary = UIColor { trait in
trait.userInterfaceStyle == .dark
? UIColor(hex: "#C9D1D9")
: UIColor(hex: "#24292F")
}
CometChatTheme.textColorSecondary = UIColor { trait in
trait.userInterfaceStyle == .dark
? UIColor(hex: "#8B949E")
: UIColor(hex: "#57606A")
}
// Alert colors
CometChatTheme.successColor = UIColor(hex: "#238636")
CometChatTheme.errorColor = UIColor(hex: "#DA3633")
CometChatTheme.warningColor = brandSecondary
}
}
// UIColor extension for hex support
extension UIColor {
convenience init(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
var rgb: UInt64 = 0
Scanner(string: hexSanitized).scanHexInt64(&rgb)
let r = CGFloat((rgb & 0xFF0000) >> 16) / 255.0
let g = CGFloat((rgb & 0x00FF00) >> 8) / 255.0
let b = CGFloat(rgb & 0x0000FF) / 255.0
self.init(red: r, green: g, blue: b, alpha: 1.0)
}
}