-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
HomeCafeRecipes/HomeCafeRecipes/Presentation/Tabbar/MainTabBarController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// CustomTabBarController.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/20/24. | ||
// | ||
|
||
import UIKit | ||
|
||
class MainTabBarController: UITabBarController, UITabBarControllerDelegate { | ||
|
||
private let addButton = UIButton(type: .custom) | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
self.delegate = self | ||
setupButton() | ||
setupTabBar() | ||
setupActionButton() | ||
} | ||
|
||
private func setupButton() { | ||
addButton.backgroundColor = .blue | ||
addButton.setTitle("+", for: .normal) | ||
addButton.setTitleColor(.white, for: .normal) | ||
addButton.layer.cornerRadius = 32 | ||
addButton.layer.shadowColor = UIColor.black.cgColor | ||
addButton.layer.shadowOpacity = 0.3 | ||
addButton.layer.shadowOffset = CGSize(width: 0, height: 2) | ||
addButton.layer.shadowRadius = 10 | ||
} | ||
|
||
private func setupTabBar() { | ||
let baseneworkServie = BaseNetworkService() | ||
let networkService = DefaultRecipeFetchService(networkService: baseneworkServie) | ||
let repository = DefaultFeedListRepository(networkService: networkService) | ||
let searchrepository = DefaultSearchFeedRepository(networkService: networkService) | ||
let fetchFeedListUseCase = DefaultFetchFeedListUseCase(repository: repository) | ||
let searchFeedListUsecase = DefaultSearchFeedListUseCase(repository: searchrepository) | ||
|
||
let recipeListViewModel = RecipeListInteractor(fetchFeedListUseCase: fetchFeedListUseCase, searchFeedListUseCase: searchFeedListUsecase) | ||
|
||
let recipeListVC = RecipeListViewController(interactor: recipeListViewModel) | ||
recipeListVC.tabBarItem = UITabBarItem(title: "Recipes", image: UIImage(systemName: "list.bullet"), tag: 0) | ||
|
||
let favoritesVC = UIViewController() | ||
favoritesVC.view.backgroundColor = .white | ||
favoritesVC.tabBarItem = UITabBarItem(title: "Favorites", image: UIImage(systemName: "bookmark"), tag: 1) | ||
|
||
viewControllers = [recipeListVC, favoritesVC] | ||
} | ||
|
||
private func setupActionButton() { | ||
addButton.addTarget(self, action: #selector(didTapActionButton), for: .touchUpInside) | ||
self.view.addSubview(addButton) | ||
addButton.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
addButton.centerXAnchor.constraint(equalTo: tabBar.centerXAnchor), | ||
addButton.centerYAnchor.constraint(equalTo: tabBar.topAnchor), | ||
addButton.widthAnchor.constraint(equalToConstant: 64), | ||
addButton.heightAnchor.constraint(equalToConstant: 64) | ||
]) | ||
} | ||
|
||
@objc private func didTapActionButton() { | ||
let alert = UIAlertController(title: "게시물 작성", message: "어떤 게시물을 작성하실 건가요?", preferredStyle: .actionSheet) | ||
alert.addAction(UIAlertAction(title: "Coffee", style: .default, handler: { [weak self] _ in | ||
guard let self = self else { return } | ||
let addRecipeVC = AddRecipeViewController(recipeType: .coffee) | ||
self.navigationController?.pushViewController(addRecipeVC, animated: true) | ||
})) | ||
alert.addAction(UIAlertAction(title: "Dessert", style: .default, handler: { [weak self] _ in | ||
guard let self = self else { return } | ||
let addRecipeVC = AddRecipeViewController(recipeType: .dessert) | ||
self.navigationController?.pushViewController(addRecipeVC, animated: true) | ||
})) | ||
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) | ||
self.present(alert, animated: true, completion: nil) | ||
} | ||
} |