Skip to content

Commit

Permalink
✨ feat: LayoverConstraintWrapper 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Nov 20, 2023
1 parent 7ffc944 commit a4a69b3
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 2 deletions.
20 changes: 18 additions & 2 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
194552392B05230E00299768 /* HomeCarouselCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194552382B05230E00299768 /* HomeCarouselCollectionViewCell.swift */; };
1945523B2B05258200299768 /* HomeConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1945523A2B05258200299768 /* HomeConfigurator.swift */; };
19743C052B06940D001E405A /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19743C042B06940D001E405A /* PlayerView.swift */; };
19ABC1C32B0B78C800736813 /* LayoverConstraintWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19ABC1C22B0B78C800736813 /* LayoverConstraintWrapper.swift */; };
19ABC1C52B0B7D0100736813 /* LayoverConstraintWrapper+UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19ABC1C42B0B7D0100736813 /* LayoverConstraintWrapper+UIView.swift */; };
19C7AFCE2B02410F003B35F2 /* AuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C7AFCD2B02410F003B35F2 /* AuthManager.swift */; };
19C7AFD62B02584D003B35F2 /* KeychainStored.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C7AFD52B02584D003B35F2 /* KeychainStored.swift */; };
19E79AC02B0A85D0009EA9ED /* LoopingPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */; };
835A61902B067D61002F22A5 /* LOSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A618F2B067D61002F22A5 /* LOSlider.swift */; };
835A61922B067FEC002F22A5 /* LOTagStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A61912B067FEC002F22A5 /* LOTagStackView.swift */; };
835A61942B068096002F22A5 /* LODescriptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A61932B068096002F22A5 /* LODescriptionView.swift */; };
Expand All @@ -42,7 +45,6 @@
835A61A02B068115002F22A5 /* PlaybackModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A619A2B068115002F22A5 /* PlaybackModels.swift */; };
835A61A12B068115002F22A5 /* PlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A619B2B068115002F22A5 /* PlaybackViewController.swift */; };
835A61A22B068115002F22A5 /* PlaybackInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A619C2B068115002F22A5 /* PlaybackInteractor.swift */; };
19E79AC02B0A85D0009EA9ED /* LoopingPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */; };
FC2511A02B045C0A004717BC /* SignUpInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC25119F2B045C0A004717BC /* SignUpInteractor.swift */; };
FC2511A22B045C3F004717BC /* SignUpPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC2511A12B045C3F004717BC /* SignUpPresenter.swift */; };
FC2511A42B045D6C004717BC /* SignUpModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC2511A32B045D6C004717BC /* SignUpModels.swift */; };
Expand Down Expand Up @@ -115,8 +117,11 @@
194552382B05230E00299768 /* HomeCarouselCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCarouselCollectionViewCell.swift; sourceTree = "<group>"; };
1945523A2B05258200299768 /* HomeConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeConfigurator.swift; sourceTree = "<group>"; };
19743C042B06940D001E405A /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = "<group>"; };
19ABC1C22B0B78C800736813 /* LayoverConstraintWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoverConstraintWrapper.swift; sourceTree = "<group>"; };
19ABC1C42B0B7D0100736813 /* LayoverConstraintWrapper+UIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LayoverConstraintWrapper+UIView.swift"; sourceTree = "<group>"; };
19C7AFCD2B02410F003B35F2 /* AuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthManager.swift; sourceTree = "<group>"; };
19C7AFD52B02584D003B35F2 /* KeychainStored.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainStored.swift; sourceTree = "<group>"; };
19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopingPlayerView.swift; sourceTree = "<group>"; };
835A618F2B067D61002F22A5 /* LOSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOSlider.swift; sourceTree = "<group>"; };
835A61912B067FEC002F22A5 /* LOTagStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOTagStackView.swift; sourceTree = "<group>"; };
835A61932B068096002F22A5 /* LODescriptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LODescriptionView.swift; sourceTree = "<group>"; };
Expand All @@ -126,7 +131,6 @@
835A619A2B068115002F22A5 /* PlaybackModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackModels.swift; sourceTree = "<group>"; };
835A619B2B068115002F22A5 /* PlaybackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackViewController.swift; sourceTree = "<group>"; };
835A619C2B068115002F22A5 /* PlaybackInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackInteractor.swift; sourceTree = "<group>"; };
19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopingPlayerView.swift; sourceTree = "<group>"; };
FC25119F2B045C0A004717BC /* SignUpInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpInteractor.swift; sourceTree = "<group>"; };
FC2511A12B045C3F004717BC /* SignUpPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpPresenter.swift; sourceTree = "<group>"; };
FC2511A32B045D6C004717BC /* SignUpModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpModels.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -233,6 +237,15 @@
path = Cell;
sourceTree = "<group>";
};
19ABC1C62B0B8A5B00736813 /* LayoverConstraint */ = {
isa = PBXGroup;
children = (
19ABC1C22B0B78C800736813 /* LayoverConstraintWrapper.swift */,
19ABC1C42B0B7D0100736813 /* LayoverConstraintWrapper+UIView.swift */,
);
path = LayoverConstraint;
sourceTree = "<group>";
};
19BB8A572B07BEE30070B922 /* UIComponents */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -429,6 +442,7 @@
FC7E45812AFF6FF9004F155A /* Extensions */ = {
isa = PBXGroup;
children = (
19ABC1C62B0B8A5B00736813 /* LayoverConstraint */,
FC7E45952AFF7497004F155A /* DummyExtension.swift */,
FC4975982B03439000D8627F /* UIFont+.swift */,
194552012B038B8300299768 /* OSLog+.swift */,
Expand Down Expand Up @@ -617,12 +631,14 @@
835A61922B067FEC002F22A5 /* LOTagStackView.swift in Sources */,
FC7E45902AFF746E004F155A /* DummyWorker.swift in Sources */,
835A61A12B068115002F22A5 /* PlaybackViewController.swift in Sources */,
19ABC1C32B0B78C800736813 /* LayoverConstraintWrapper.swift in Sources */,
1945520F2B03AEA400299768 /* Configurator.swift in Sources */,
835A619F2B068115002F22A5 /* PlaybackRouter.swift in Sources */,
FC2511B12B04EAEC004717BC /* MapModels.swift in Sources */,
FC68E29F2B023315001AABFF /* HTTPMethod.swift in Sources */,
835A619D2B068115002F22A5 /* PlaybackPresenter.swift in Sources */,
FCEE0FFA2B03AF8500195BBE /* SignUpViewController.swift in Sources */,
19ABC1C52B0B7D0100736813 /* LayoverConstraintWrapper+UIView.swift in Sources */,
194551F32B037F2D00299768 /* LoginWorker.swift in Sources */,
835A61902B067D61002F22A5 /* LOSlider.swift in Sources */,
19E79AC02B0A85D0009EA9ED /* LoopingPlayerView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// LayoverConstraintWrapper+UIView.swift
// Layover
//
// Created by 김인환 on 11/20/23.
// Copyright © 2023 CodeBomber. All rights reserved.
//

import UIKit

extension LayoverConstraintWrapper where Base: UIView {

func makeConstraints(_ closure: (ConstraintMaker) -> Void) {
base.translatesAutoresizingMaskIntoConstraints = false
closure(ConstraintMaker(base))
}
}

final class ConstraintMaker {
let view: UIView

init(_ view: UIView) {
self.view = view
}

func topAnchor(equalTo anchor: NSLayoutYAxisAnchor, constant: CGFloat = 0) {
view.topAnchor.constraint(equalTo: anchor, constant: constant).isActive = true
}

func bottomAnchor(equalTo anchor: NSLayoutYAxisAnchor, constant: CGFloat = 0) {
view.bottomAnchor.constraint(equalTo: anchor, constant: constant).isActive = true
}

func leadingAnchor(equalTo anchor: NSLayoutXAxisAnchor, constant: CGFloat = 0) {
view.leadingAnchor.constraint(equalTo: anchor, constant: constant).isActive = true
}

func trailingAnchor(equalTo anchor: NSLayoutXAxisAnchor, constant: CGFloat = 0) {
view.trailingAnchor.constraint(equalTo: anchor, constant: constant).isActive = true
}

func widthAnchor(equalToConstant constant: CGFloat) {
view.widthAnchor.constraint(equalToConstant: constant).isActive = true
}

func widthAnchor(equalTo anchor: NSLayoutDimension, multiplier: CGFloat = 1.0) {
view.widthAnchor.constraint(equalTo: anchor, multiplier: multiplier).isActive = true
}

func heightAnchor(equalToConstant constant: CGFloat) {
view.heightAnchor.constraint(equalToConstant: constant).isActive = true
}

func heightAnchor(equalTo anchor: NSLayoutDimension, multiplier: CGFloat = 1.0) {
view.heightAnchor.constraint(equalTo: anchor, multiplier: multiplier).isActive = true
}

func verticalAnchor(equalTo relativeView: UIView) {
topAnchor(equalTo: relativeView.topAnchor)
bottomAnchor(equalTo: relativeView.bottomAnchor)
}

func horizontalAnchor(equalTo relativeView: UIView) {
leadingAnchor(equalTo: relativeView.leadingAnchor)
trailingAnchor(equalTo: relativeView.trailingAnchor)
}

func equalToSuperView() {
guard let superview = view.superview else { return }
verticalAnchor(equalTo: superview)
horizontalAnchor(equalTo: superview)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// LayoverConstraintWrapper.swift
// Layover
//
// Created by 김인환 on 11/20/23.
// Copyright © 2023 CodeBomber. All rights reserved.
//

import UIKit

struct LayoverConstraintWrapper<Base> {
let base: Base
init(base: Base) {
self.base = base
}
}

protocol LayoverConstraintCompatible {
associatedtype LayoverConstraintBase

var lor: LayoverConstraintWrapper<LayoverConstraintBase> { get }
}

extension LayoverConstraintCompatible {
var lor: LayoverConstraintWrapper<Self> {
get {
return LayoverConstraintWrapper(base: self)
} set { }
}
}

extension UIView: LayoverConstraintCompatible { }
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ final class HomeCarouselCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

private let loopingPlayerView = LoopingPlayerView()

// MARK: - UI Components

// MARK: - Object lifecycle
Expand All @@ -35,7 +37,12 @@ final class HomeCarouselCollectionViewCell: UICollectionViewCell {
}

private func setConstraints() {
addSubviews(loopingPlayerView)
loopingPlayerView.backgroundColor = .green

loopingPlayerView.lor.makeConstraints {
$0.equalToSuperView()
}
}

// MARK: - Methods
Expand Down
1 change: 1 addition & 0 deletions iOS/Layover/Layover/Scenes/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class HomeViewController: BaseViewController, HomeDisplayLogic {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeCarouselCollectionViewCell.identifier,
for: indexPath) as? HomeCarouselCollectionViewCell else { return UICollectionViewCell() }
cell.layer.cornerRadius = 10
cell.clipsToBounds = true
return cell
}

Expand Down

0 comments on commit a4a69b3

Please sign in to comment.