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: LayoverConstraintWrapper 구현 #50

Open
wants to merge 3 commits into
base: iOS/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,81 @@
//
// 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))
}
Comment on lines +12 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateConstraints도 구현해주세요..
나중에 갖다 써야지..ㅎ

}

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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 음수 -> 양수로 변환해주세요


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 centerXAnchor(equalTo anchor: NSLayoutAnchor<NSLayoutXAxisAnchor>) {
view.centerXAnchor.constraint(equalTo: anchor).isActive = true
}

func centerYAnchor(equalTo anchor: NSLayoutAnchor<NSLayoutYAxisAnchor>) {
view.centerYAnchor.constraint(equalTo: anchor).isActive = true
}

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,29 @@
//
// LayoverConstraintWrapper.swift
// Layover
//
// Created by 김인환 on 11/20/23.
// Copyright © 2023 CodeBomber. All rights reserved.
//

import UIKit

struct LayoverConstraintWrapper<Base> {
let base: Base
}

protocol LayoverConstraintCompatible {
associatedtype LayoverConstraintBase

var lor: LayoverConstraintWrapper<LayoverConstraintBase> { get }
}

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

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