You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
5.8 KiB
200 lines
5.8 KiB
//
|
|
// MainViewController.swift
|
|
//
|
|
//
|
|
// Created by shishir sapkota
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class MainViewController: UITabBarController {
|
|
// MARK: Properties
|
|
|
|
// MARK: ENUMS:
|
|
private enum Items: Int {
|
|
case home = 0
|
|
case sendMoney
|
|
case branch
|
|
case profile
|
|
}
|
|
|
|
var presenter: MainModuleInterface?
|
|
|
|
// MARK: VC's Life cycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.delegate = self
|
|
self.setupAppearance()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.navigationController?.setNavigationBarHidden(true, animated: animated)
|
|
tabBar.items?[0].title = "home_text".localized()
|
|
tabBar.items?[1].title = "send_money_text".localized()
|
|
tabBar.items?[2].title = "branch_text".localized()
|
|
|
|
guard UIStoryboard(name: "Profile", bundle: nil)
|
|
.instantiateViewController(withIdentifier: "ProfileViewController") is ProfileViewController else {
|
|
return
|
|
}
|
|
tabBar.items?[3].title = "profile_text".localized()
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
self.title = ""
|
|
self.navigationController?.setNavigationBarHidden(false, animated: animated)
|
|
}
|
|
|
|
func setup(viewControllers: [UIViewController]) {
|
|
self.viewControllers = viewControllers
|
|
self.setupTab()
|
|
setupTabItem()
|
|
}
|
|
|
|
// MARK: Other functions
|
|
func setupAppearance() {
|
|
UINavigationBar.setInsideAppearance()
|
|
}
|
|
|
|
private func setupTab() {
|
|
|
|
|
|
if #available(iOS 15.0, *) {
|
|
let appearance = UITabBarAppearance()
|
|
appearance.configureWithOpaqueBackground()
|
|
appearance.backgroundColor = .white
|
|
self.tabBar.standardAppearance = appearance
|
|
self.tabBar.scrollEdgeAppearance = tabBar.standardAppearance
|
|
}
|
|
self.tabBar.tintColor = Colors.defaultRed
|
|
self.tabBar.isTranslucent = false
|
|
self.tabBar.shadowImage = Colors.TabBar.shadow.image()
|
|
self.tabBar.backgroundImage = UIImage()
|
|
self.tabBar.barTintColor = UIColor(hex: "#F4F4F4")
|
|
}
|
|
|
|
override func setupTabItem() {
|
|
}
|
|
}
|
|
|
|
extension MainViewController: MainViewInterface {
|
|
|
|
}
|
|
|
|
extension MainViewController: UITabBarControllerDelegate {
|
|
func tabBarController(
|
|
_ tabBarController: UITabBarController,
|
|
shouldSelect viewController: UIViewController
|
|
) -> Bool {
|
|
if let nav = viewController as? UINavigationController {
|
|
if nav.viewControllers.first as? RecipientsViewController != nil {
|
|
NotificationCenter.default.post(
|
|
name: Notification.Name.init(AppConstants.MainWireFrameNotificationName),
|
|
object: nil,
|
|
userInfo: nil
|
|
)
|
|
|
|
return Utility.isVerifiedUser()
|
|
}
|
|
}
|
|
print(tabBarController.selectedIndex)
|
|
return true
|
|
}
|
|
}
|
|
|
|
extension UINavigationBar {
|
|
static func setInsideAppearance() {
|
|
let navBarAppearance = UINavigationBar.appearance()
|
|
navBarAppearance.isTranslucent = false
|
|
navBarAppearance.barTintColor = UIColor.white
|
|
}
|
|
|
|
static func setOutsideAppearance() {
|
|
self.setInsideAppearance()
|
|
let navBarAppearance = UINavigationBar.appearance()
|
|
navBarAppearance.barTintColor = Colors.defaultRed
|
|
let font = Fonts.NavBar.titleFont
|
|
navBarAppearance.titleTextAttributes = [
|
|
NSAttributedString.Key.foregroundColor: UIColor.black,
|
|
NSAttributedString.Key.font: font]
|
|
navBarAppearance.tintColor = UIColor.black
|
|
}
|
|
|
|
static func setupImageAppearance() {
|
|
let navBarAppearance = UINavigationBar.appearance()
|
|
navBarAppearance.barTintColor = Colors.defaultRed
|
|
let font = Fonts.NavBar.titleFont
|
|
navBarAppearance.titleTextAttributes = [
|
|
NSAttributedString.Key.foregroundColor: UIColor.black,
|
|
NSAttributedString.Key.font: font]
|
|
navBarAppearance.tintColor = UIColor.black
|
|
}
|
|
}
|
|
|
|
@objc protocol Setup {
|
|
@objc optional func setupTabItem()
|
|
}
|
|
|
|
extension UIViewController: Setup {
|
|
func setupTabItem() {
|
|
|
|
}
|
|
}
|
|
struct Colors {
|
|
|
|
static let separator = UIColor(hex: "#eeeeee")
|
|
static let defaultRed = UIColor(hex: "#0xec1c24")
|
|
static let cartBadge = UIColor(hex: "#F5951D")
|
|
|
|
struct TabBar {
|
|
static let textItemSelected = Colors.defaultRed
|
|
static let textItemNotSelected = UIColor(hex: "#959595")
|
|
static let shadow = Colors.separator
|
|
}
|
|
|
|
struct NavBar {
|
|
// static let barTint =
|
|
static let tint = UIColor.white
|
|
static let shadow = Colors.separator
|
|
}
|
|
|
|
struct XLTabBar {
|
|
static let titleUnselected = UIColor(hex: "#555555")
|
|
static let titleSelected = Colors.defaultRed
|
|
static let selectedBackground = Colors.defaultRed
|
|
}
|
|
}
|
|
|
|
struct Fonts {
|
|
struct TabBar {
|
|
static let itemFont = UIFont.sanfrancisco(.light, size: 10)
|
|
}
|
|
|
|
struct NavBar {
|
|
static let titleFont = UIFont.sanfrancisco(.regular, size: 17)
|
|
}
|
|
|
|
struct XLTabBar {
|
|
static let itemFont = UIFont.sanfrancisco(.regular, size: 12)
|
|
}
|
|
|
|
struct Error {
|
|
static let font = UIFont.sanfrancisco(.semibold, size: 11)
|
|
}
|
|
}
|
|
|
|
extension UIColor {
|
|
func image(of size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
|
|
let rect = CGRect(origin: .zero, size: size)
|
|
UIGraphicsBeginImageContextWithOptions(size, false, 0)
|
|
self.setFill()
|
|
UIRectFill(rect)
|
|
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
|
|
UIGraphicsEndImageContext()
|
|
return image
|
|
}
|
|
}
|