Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #69 - NaverMapContainer 메인 뷰에 통합하기 #77

Merged
merged 8 commits into from
Jul 15, 2022
2 changes: 1 addition & 1 deletion HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,10 @@
EB6A44C828737BF700749582 /* Detail */ = {
isa = PBXGroup;
children = (
EB6A44C928737C4600749582 /* MainDetailScene */,
3BC01F7C287E91F7006C2181 /* BlogReviewTabScene */,
695758BA287DA4A400E36789 /* ReviewWriteScene */,
697074FB28737D78001A607F /* MenuTabScene */,
EB6A44C928737C4600749582 /* MainDetailScene */,
);
path = Detail;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum PointerType {
struct MainMapCategory {
let menuName: String
let menuIcon: UIImage
let isDietMenu: Bool

static let categorySample: [MainMapCategory] = [MainMapCategory(menuName: "샐러드", menuIcon: ImageLiterals.Map.saladIcon!), MainMapCategory(menuName: "포케", menuIcon: ImageLiterals.Map.pokeIcon!), MainMapCategory(menuName: "키토김밥", menuIcon: ImageLiterals.Map.kimbapIcon!), MainMapCategory(menuName: "샌드위치", menuIcon: ImageLiterals.Map.sandwichIcon!), MainMapCategory(menuName: "샤브샤브", menuIcon: ImageLiterals.Map.shabushabuIcon!), MainMapCategory(menuName: "보쌈", menuIcon: ImageLiterals.Map.bossamIcon!), MainMapCategory(menuName: "고깃집", menuIcon: ImageLiterals.Map.meatIcon!), MainMapCategory(menuName: "덮밥", menuIcon: ImageLiterals.Map.dupbapIcon!)]
static let categorySample: [MainMapCategory] = [MainMapCategory(menuName: "샐러드", menuIcon: ImageLiterals.Map.saladIcon!, isDietMenu: true), MainMapCategory(menuName: "포케", menuIcon: ImageLiterals.Map.pokeIcon!, isDietMenu: true), MainMapCategory(menuName: "키토김밥", menuIcon: ImageLiterals.Map.kimbapIcon!, isDietMenu: true), MainMapCategory(menuName: "샌드위치", menuIcon: ImageLiterals.Map.sandwichIcon!, isDietMenu: false), MainMapCategory(menuName: "샤브샤브", menuIcon: ImageLiterals.Map.shabushabuIcon!, isDietMenu: false), MainMapCategory(menuName: "보쌈", menuIcon: ImageLiterals.Map.bossamIcon!, isDietMenu: false), MainMapCategory(menuName: "고깃집", menuIcon: ImageLiterals.Map.meatIcon!, isDietMenu: false), MainMapCategory(menuName: "덮밥", menuIcon: ImageLiterals.Map.dupbapIcon!, isDietMenu: false)]
}
4 changes: 4 additions & 0 deletions HealthFoodMe/HealthFoodMe/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>사용자의 위치를 받습니다</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>사용자의 위치를 받습니다</string>
<key>CFBundleIdentifier</key>
<string></string>
<key>UIUserInterfaceStyle</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ final class DetailSummaryView: UIView {
return st
}()

private let starStackView: UIStackView = {
let st = UIStackView()
st.axis = .horizontal
st.spacing = 2
st.distribution = .equalSpacing
private let starRateView: StarRatingView = {
let st = StarRatingView(starScale: 14)
st.rate = 4.3
return st
}()

Expand Down Expand Up @@ -108,8 +106,12 @@ extension DetailSummaryView {
}

titleStackView.addArrangedSubviews(restaurantNameLabel, starRateStackView)
starRateStackView.addArrangedSubviews(starStackView, rateLabel)
setStarStackView()
starRateStackView.addArrangedSubviews(starRateView, rateLabel)

starRateView.snp.makeConstraints { make in
make.width.equalTo(70)
make.centerY.equalToSuperview()
}

restaurantNameLabel.snp.makeConstraints { make in
make.width.lessThanOrEqualTo(200)
Expand All @@ -124,18 +126,4 @@ extension DetailSummaryView {
make.centerY.equalTo(logoImageView)
}
}

private func setStarStackView() {
for starNumber in 1...5 {
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
imageView.contentMode = .scaleAspectFill
if starNumber < 5 {
imageView.image = ImageLiterals.MainDetail.starIcon_filled
} else {
imageView.image = ImageLiterals.MainDetail.starIcon
}
imageView.tag = starNumber
starStackView.addArrangedSubviews(imageView)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ final class MenuCategoryCVC: UICollectionViewCell, UICollectionViewRegisterable
// MARK: - Properties

static var isFromNib: Bool = false

override var isSelected: Bool {
didSet {

resetUI()
}
}
var isDietMenu: Bool = true
private var originalImage: UIImage = UIImage()

// MARK: - UI Components

private let menuImageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .center
iv.image = ImageLiterals.Map.manifyingIcon
iv.image = UIImage()
iv.adjustsImageSizeForAccessibilityContentSizeCategory = true
iv.tintColor = .helfmeWhite
return iv
}()

Expand Down Expand Up @@ -60,6 +63,18 @@ extension MenuCategoryCVC {
self.backgroundColor = .white
}

private func resetUI() {
if isSelected {
menuNameLabel.textColor = .helfmeWhite
menuImageView.image = menuImageView.image?.withRenderingMode(.alwaysTemplate)
self.backgroundColor = isDietMenu ? .helfmeGreenSubDark : .mainRed
} else {
menuNameLabel.textColor = .helfmeBlack
menuImageView.image = originalImage
self.backgroundColor = .helfmeWhite
}
}

private func setLayout() {
self.addSubviews(menuImageView, menuNameLabel)

Expand All @@ -79,5 +94,6 @@ extension MenuCategoryCVC {
func setData(data: MainMapCategory) {
self.menuNameLabel.text = data.menuName
self.menuImageView.image = data.menuIcon
self.originalImage = data.menuIcon
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ import NMapsMap
import RxSwift
import SnapKit

class MainMapVC: UIViewController {
class MainMapVC: UIViewController, NMFLocationManagerDelegate {

// MARK: - Properties

private let disposeBag = DisposeBag()
private var locationManager = CLLocationManager()
private var currentLatitude: Double?
private var currentLongitude: Double?
private let locationManager = NMFLocationManager.sharedInstance()
private var selectedCategories: [Bool] = [false, false, false,
false, false, false,
false, false] {
didSet {
categoryCollectionView.reloadData()
}
}
var viewModel: MainMapViewModel!

// MARK: - UI Components

private lazy var mapView: NMFMapView = {
let map = NMFMapView()
map.locationOverlay.hidden = false
private lazy var mapView: NaverMapContainerView = {
let map = NaverMapContainerView()
return map
}()

private lazy var hamburgerButton: UIButton = {
let bt = UIButton()
bt.setImage(ImageLiterals.Map.menuIcon, for: .normal)
bt.addAction(UIAction(handler: { _ in
self.makeVibrate()
let nextVC = ModuleFactory.resolve().makeHamburgerBarVC()
nextVC.modalPresentationStyle = .overFullScreen
self.present(nextVC, animated: false)
Expand Down Expand Up @@ -79,14 +84,16 @@ class MainMapVC: UIViewController {
let cv = UICollectionView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 32), collectionViewLayout: layout)
cv.showsHorizontalScrollIndicator = false
cv.backgroundColor = .clear
cv.allowsMultipleSelection = true
return cv
}()

private let scrapButton: UIButton = {
private lazy var scrapButton: UIButton = {
let bt = UIButton()
bt.setImage(ImageLiterals.Map.scrapIcon, for: .normal)
bt.setImage(ImageLiterals.MainDetail.scrapIcon_filled, for: .selected)
bt.addAction(UIAction(handler: { _ in
self.makeVibrate()
bt.isSelected.toggle()
}), for: .touchUpInside)
bt.backgroundColor = .helfmeWhite
Expand All @@ -96,11 +103,15 @@ class MainMapVC: UIViewController {
return bt
}()

private let myLocationButton: UIButton = {
private lazy var myLocationButton: UIButton = {
let bt = UIButton()
bt.setImage(ImageLiterals.Map.mylocationIcon, for: .normal)
bt.addAction(UIAction(handler: { _ in

self.makeVibrate()
let NMGPosition = self.locationManager?.currentLatLng()
if let position = NMGPosition {
self.mapView.moveCameraPosition(position)
}
}), for: .touchUpInside)
bt.backgroundColor = .helfmeWhite
bt.clipsToBounds = true
Expand All @@ -121,6 +132,9 @@ class MainMapVC: UIViewController {
setDelegate()
registerCell()
setPanGesture()
setMapView()
bindMapView()
sampleViewInputEvent()
self.bindViewModels()
}

Expand Down Expand Up @@ -182,7 +196,7 @@ extension MainMapVC {

mapDetailSummaryView.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalToSuperview().inset(UIScreen.main.bounds.height - 189)
make.top.equalToSuperview().inset(UIScreen.main.bounds.height)
make.height.equalTo(UIScreen.main.bounds.height + 300)
}

Expand Down Expand Up @@ -243,7 +257,7 @@ extension MainMapVC {
} completion: { _ in
self?.transitionAndPresentMainDetailVC()
}

} else {
let summaryViewHeight: CGFloat = 189
self?.mapDetailSummaryView.snp.updateConstraints { make in
Expand All @@ -264,33 +278,64 @@ extension MainMapVC {
}

private func bindViewModels() {
let input = MainMapViewModel.Input()
let input = MainMapViewModel.Input(myLocationButtonTapped: myLocationButton.rx.tap.asObservable(), scrapButtonTapped: scrapButton.rx.tap.asObservable())
let output = self.viewModel.transform(from: input, disposeBag: self.disposeBag)
}

private func resetUI() {
navigationController?.isNavigationBarHidden = true
}

@objc
private func presentSearchVC() {
let nextVC = ModuleFactory.resolve().makeSearchVC()
self.navigationController?.pushViewController(nextVC, animated: true)
private func setMapView() {
locationManager?.add(self)
}

@objc
private func presentDetailVC() {
self.scrapButton.isHidden = true
self.myLocationButton.isHidden = true
self.mapDetailSummaryView.snp.updateConstraints { make in
make.top.equalToSuperview().inset(44)
}
private func bindMapView() {
mapView.rx.mapViewClicked
.subscribe(onNext: { _ in
self.mapView.disableSelectPoint.accept(())
self.mapDetailSummaryView.snp.updateConstraints { make in
make.top.equalToSuperview().inset(UIScreen.main.bounds.height)
}
UIView.animate(withDuration: 0.3, delay: 0) {
self.mapDetailSummaryView.transform = CGAffineTransform(translationX: 0, y: 0)
self.view.layoutIfNeeded()
}
}).disposed(by: self.disposeBag)

UIView.animate(withDuration: 0.3, delay: 0) {
self.mapDetailSummaryView.transform = CGAffineTransform(translationX: 0, y: 0)
self.view.layoutIfNeeded()
} completion: { _ in
self.transitionAndPresentMainDetailVC()
mapView.setSelectPoint
.subscribe(onNext: { [weak self] dataModel in
let summaryViewHeight: CGFloat = 189
self?.mapDetailSummaryView.snp.updateConstraints { make in
make.top.equalToSuperview().inset(UIScreen.main.bounds.height - summaryViewHeight)
}
UIView.animate(withDuration: 0.3, delay: 0) {
self?.mapDetailSummaryView.transform = CGAffineTransform(translationX: 0, y: 0)
self?.view.layoutIfNeeded()
}
}).disposed(by: self.disposeBag)
}

private func sampleViewInputEvent() {
makeDummyPoints()
.bind(to: mapView.rx.pointList)
.disposed(by: self.disposeBag)
}

private func makeDummyPoints() -> Observable<[MapPointDataModel]> {
return .create { observer in
let pointList: [MapPointDataModel] = .init([
MapPointDataModel.init(latitude: 37.5666805, longtitude: 126.9784147, type: .normalFood),
MapPointDataModel.init(latitude: 37.567, longtitude: 126.9784147, type: .healthFood),
MapPointDataModel.init(latitude: 37.568, longtitude: 126.9784147, type: .normalFood),
MapPointDataModel.init(latitude: 37.569, longtitude: 126.9784147, type: .normalFood),
MapPointDataModel.init(latitude: 37.557, longtitude: 126.9784147, type: .healthFood),
MapPointDataModel.init(latitude: 37.571, longtitude: 126.9784147, type: .normalFood),
MapPointDataModel.init(latitude: 37.572, longtitude: 126.9784147, type: .normalFood),
MapPointDataModel.init(latitude: 37.010, longtitude: 126.9784147, type: .normalFood)
])
observer.onNext(pointList)
return Disposables.create()
}
}

Expand Down Expand Up @@ -323,12 +368,42 @@ extension MainMapVC {
self.categoryCollectionView.isHidden = true
}
}

@objc
private func presentSearchVC() {
self.makeVibrate()
let nextVC = ModuleFactory.resolve().makeSearchVC()
self.navigationController?.pushViewController(nextVC, animated: true)
}

@objc
private func presentDetailVC() {
self.scrapButton.isHidden = true
self.myLocationButton.isHidden = true
self.mapDetailSummaryView.snp.updateConstraints { make in
make.top.equalToSuperview().inset(44)
}

UIView.animate(withDuration: 0.3, delay: 0) {
self.mapDetailSummaryView.transform = CGAffineTransform(translationX: 0, y: 0)
self.view.layoutIfNeeded()
} completion: { _ in
self.transitionAndPresentMainDetailVC()
}
}
}

// MARK: - CollectionView Delegate

extension MainMapVC: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
makeVibrate()
}

func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
selectedCategories[indexPath.row].toggle()
return true
}
}

extension MainMapVC: UICollectionViewDelegateFlowLayout {
Expand All @@ -344,7 +419,9 @@ extension MainMapVC: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuCategoryCVC.className, for: indexPath) as? MenuCategoryCVC else { return UICollectionViewCell() }
cell.isDietMenu = MainMapCategory.categorySample[indexPath.row].isDietMenu
cell.setData(data: MainMapCategory.categorySample[indexPath.row])
cell.isSelected = selectedCategories[indexPath.row]
return cell
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import RxSwift
import RxRelay

final class MainMapViewModel: ViewModelType {

Expand All @@ -15,13 +16,14 @@ final class MainMapViewModel: ViewModelType {
// MARK: - Inputs

struct Input {

let myLocationButtonTapped: Observable<Void>
let scrapButtonTapped: Observable<Void>
}

// MARK: - Outputs

struct Output {

var moveToMyLocation = PublishRelay<String>()
}

init(useCase: MainMapUseCase) {
Expand Down
Loading