Files
Woka_Native_iOS/WOKA/Home/Controller/HomeVC.swift
BilalKhanWDI 0e921c3113 - Handled the star and moon to show only at the night time.
- Added a star above the grass and added it to the animation.
- Woke Client call 1:15 - 1:40
- Added Sidebar theme clicks and added userdefaults with checks for default loading. Also added to logout
- Handled the Theme change from sidebar, also handled the default theme selected and loading it at the time of startup
- Fixed issue of sidebar showing up, left side blacktint was not coming. It was the issue of ViewLifeCycle
- Theme 2  Explore woka items size ratio updated for auto layouts
- Worked on RootView Navigation.
2024-05-27 19:42:56 +05:30

89 lines
3.2 KiB
Swift

//
// HomeVC.swift
// WOKA
//
// Created by Bilal on 24/05/2024.
//
import UIKit
protocol ChildViewControllerDelegate: AnyObject {
func didPressSwitchButton(from viewController: UIViewController)
}
class HomeVC: UIViewController ,ChildViewControllerDelegate{
@IBOutlet weak var containerView: UIView!
var currentChildViewController: UIViewController?
override func viewDidLoad() {
super.viewDidLoad()
switch AuthFunc.shareInstance.selectedTheme {
case .theme1:
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
if let firstVC = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Theme.themeOneVC) as? ThemeOneVC {
add(asChildViewController: firstVC)
firstVC.delegate = self
}
case .theme2:
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
if let firstVC = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Theme.themeTwoVC) as? ThemeTwoVC {
add(asChildViewController: firstVC)
firstVC.delegate = self
}
}
}
func didPressSwitchButton(from viewController: UIViewController) {
if viewController is ThemeOneVC {
switchToViewController(withIdentifier: K.StoryBoardID.Theme.themeTwoVC)
} else if viewController is ThemeTwoVC {
switchToViewController(withIdentifier: K.StoryBoardID.Theme.themeOneVC)
}
}
private func switchToViewController(withIdentifier identifier: String) {
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
let newVC = sb.instantiateViewController(withIdentifier: identifier)
if let newVC = newVC as? ThemeOneVC {
newVC.delegate = self
} else if let newVC = newVC as? ThemeTwoVC {
newVC.delegate = self
}
print("Switching to view controller with identifier \(identifier)")
replaceCurrentChildViewController(with: newVC)
}
private func add(asChildViewController viewController: UIViewController) {
print("Adding child view controller: \(viewController)")
addChild(viewController)
viewController.view.frame = containerView.bounds
containerView.addSubview(viewController.view)
viewController.didMove(toParent: self)
currentChildViewController = viewController
}
private func remove(asChildViewController viewController: UIViewController) {
print("Removing child view controller: \(viewController)")
viewController.willMove(toParent: nil)
viewController.view.removeFromSuperview()
viewController.removeFromParent()
}
private func replaceCurrentChildViewController(with newViewController: UIViewController) {
// Clear previous views
containerView.subviews.forEach { $0.removeFromSuperview() }
// Remove current child view controller if exists
if let currentVC = currentChildViewController {
remove(asChildViewController: currentVC)
}
// Add new child view controller
add(asChildViewController: newViewController)
}
}