Skip to content

Commit

Permalink
✨ 지도 하단 그라디언트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyJunnos committed Jan 11, 2024
1 parent db2c736 commit 0aa0713
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public final class MapViewController: UIViewController {
return mapView
}()

private let gradientLayer: MSGradientLayer = {
let gradientLayer = MSGradientLayer()
gradientLayer.gradientColors = [
.msColor(.primaryBackground).withAlphaComponent(.zero),
.msColor(.primaryBackground).withAlphaComponent(0.7)
]
gradientLayer.locations = [0.55, 0.95]
return gradientLayer
}()

/// HomeMap 내 우상단 버튼 View
private lazy var buttonStackView: ButtonStackView = {
let stackView = ButtonStackView()
Expand Down Expand Up @@ -117,10 +127,23 @@ public final class MapViewController: UIViewController {
super.viewDidLoad()

self.configureLayout()
self.configureStyles()
self.configureCoreLocation()
self.bind(self.viewModel)
}

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

self.gradientLayer.frame = self.view.bounds
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

self.updateGradientColors()
}

// MARK: - Combine Binding

func swapViewModel(to viewModel: any MapViewModel) {
Expand Down Expand Up @@ -262,6 +285,7 @@ private extension MapViewController {

func configureLayout() {
self.view = self.mapView
self.mapView.layer.addSublayer(self.gradientLayer)

self.view.addSubview(self.buttonStackView)
self.buttonStackView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -273,6 +297,21 @@ private extension MapViewController {
])
}

func configureStyles() {
if #available(iOS 17.0, *) {
self.registerForTraitChanges([UITraitUserInterfaceStyle.self]) { [weak self] (_: Self, _) in
self?.updateGradientColors()
}
}
}

private func updateGradientColors() {
self.gradientLayer.gradientColors = [
.msColor(.primaryBackground).withAlphaComponent(.zero),
.msColor(.primaryBackground).withAlphaComponent(0.7)
]
}

private func configureCoreLocation() {
self.locationManager.delegate = self
switch self.locationManager.authorizationStatus {
Expand Down
30 changes: 30 additions & 0 deletions iOS/MSUIKit/Sources/MSUIKit/MSGradientLayer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// MSGradientLayer.swift
// MSUIKit
//
// Created by 이창준 on 2024.01.11.
//

import UIKit

public class MSGradientLayer: CAGradientLayer {

// MARK: - Properties

public var gradientColors: [UIColor] = [] {
didSet { self.updateColors() }
}

// MARK: - Functions

// swiftlint:disable identifier_name
public override func hitTest(_ p: CGPoint) -> CALayer? {
return nil
}
// swiftlint:enable identifier_name

private func updateColors() {
self.colors = self.gradientColors.map { $0.cgColor }
}

}

0 comments on commit 0aa0713

Please sign in to comment.