|
| 1 | +// |
| 2 | +// CustomTabBarController.swift |
| 3 | +// HomeCafeRecipes |
| 4 | +// |
| 5 | +// Created by 김건호 on 6/20/24. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | + |
| 10 | +class MainTabBarController: UITabBarController, UITabBarControllerDelegate { |
| 11 | + |
| 12 | + private let addButton = UIButton(type: .custom) |
| 13 | + private let buttonSize = CGSize(all: 64.0) |
| 14 | + |
| 15 | + override func viewDidLoad() { |
| 16 | + super.viewDidLoad() |
| 17 | + self.delegate = self |
| 18 | + setupButton() |
| 19 | + setupTabBar() |
| 20 | + setupActionButton() |
| 21 | + } |
| 22 | + |
| 23 | + private func setupButton() { |
| 24 | + addButton.backgroundColor = .blue |
| 25 | + addButton.setTitle("+", for: .normal) |
| 26 | + addButton.titleLabel?.font = UIFont.systemFont(ofSize: 40) |
| 27 | + addButton.setTitleColor(.white, for: .normal) |
| 28 | + addButton.layer.cornerRadius = buttonSize.width * 0.5 |
| 29 | + addButton.layer.shadowColor = UIColor.black.cgColor |
| 30 | + addButton.layer.shadowOpacity = 0.3 |
| 31 | + addButton.layer.shadowOffset = CGSize(width: 0, height: 2) |
| 32 | + addButton.layer.shadowRadius = 10 |
| 33 | + } |
| 34 | + |
| 35 | + private func setupTabBar() { |
| 36 | + let baseneworkServie = BaseNetworkService() |
| 37 | + let networkService = RecipeFetchServiceImpl(networkService: baseneworkServie) |
| 38 | + let repository = FeedListRepositoryImpl(networkService: networkService) |
| 39 | + let searchrepository = SearchFeedRepositoryImpl(networkService: networkService) |
| 40 | + let fetchFeedListUseCase = FetchFeedListUseCaseImpl(repository: repository) |
| 41 | + let searchFeedListUsecase = SearchFeedListUseCaseImpl(repository: searchrepository) |
| 42 | + |
| 43 | + let recipeListViewModel = RecipeListInteractor(fetchFeedListUseCase: fetchFeedListUseCase, searchFeedListUseCase: searchFeedListUsecase) |
| 44 | + |
| 45 | + let recipeListVC = RecipeListViewController(interactor: recipeListViewModel) |
| 46 | + recipeListVC.tabBarItem = UITabBarItem(title: "Recipes", image: UIImage(systemName: "list.bullet"), tag: 0) |
| 47 | + |
| 48 | + let favoritesVC = UIViewController() |
| 49 | + favoritesVC.view.backgroundColor = .white |
| 50 | + favoritesVC.tabBarItem = UITabBarItem(title: "Favorites", image: UIImage(systemName: "bookmark"), tag: 1) |
| 51 | + |
| 52 | + viewControllers = [recipeListVC, favoritesVC] |
| 53 | + } |
| 54 | + |
| 55 | + private func setupActionButton() { |
| 56 | + addButton.addTarget(self, action: #selector(didTapActionButton), for: .touchUpInside) |
| 57 | + self.view.addSubview(addButton) |
| 58 | + addButton.translatesAutoresizingMaskIntoConstraints = false |
| 59 | + NSLayoutConstraint.activate([ |
| 60 | + addButton.centerXAnchor.constraint(equalTo: tabBar.centerXAnchor), |
| 61 | + addButton.centerYAnchor.constraint(equalTo: tabBar.topAnchor), |
| 62 | + addButton.widthAnchor.constraint(equalToConstant: buttonSize.width), |
| 63 | + addButton.heightAnchor.constraint(equalToConstant: buttonSize.height) |
| 64 | + ]) |
| 65 | + } |
| 66 | + |
| 67 | + @objc private func didTapActionButton() { |
| 68 | + let alert = UIAlertController(title: "게시물 작성", message: "어떤 게시물을 작성하실 건가요?", preferredStyle: .actionSheet) |
| 69 | + alert.addAction(UIAlertAction(title: "Coffee", style: .default, handler: { [weak self] _ in |
| 70 | + guard let self else { return } |
| 71 | + let addRecipeVC = AddRecipeViewController(recipeType: .coffee) |
| 72 | + self.navigationController?.pushViewController(addRecipeVC, animated: true) |
| 73 | + })) |
| 74 | + alert.addAction(UIAlertAction(title: "Dessert", style: .default, handler: { [weak self] _ in |
| 75 | + guard let self else { return } |
| 76 | + let addRecipeVC = AddRecipeViewController(recipeType: .dessert) |
| 77 | + self.navigationController?.pushViewController(addRecipeVC, animated: true) |
| 78 | + })) |
| 79 | + alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) |
| 80 | + self.present(alert, animated: true, completion: nil) |
| 81 | + } |
| 82 | +} |
0 commit comments