-
Notifications
You must be signed in to change notification settings - Fork 0
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
loinsir
wants to merge
3
commits into
iOS/dev
Choose a base branch
from
iOS/feat#49
base: iOS/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
155 changes: 155 additions & 0 deletions
155
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper+UIView.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,155 @@ | ||
// | ||
// 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 { | ||
|
||
// MARK: Properties | ||
|
||
private let view: UIView | ||
|
||
var edges: ConstraintEdges { | ||
ConstraintEdges(view) | ||
} | ||
|
||
var top: ConstraintEdges { | ||
ConstraintEdges(view).top | ||
} | ||
|
||
var bottom: ConstraintEdges { | ||
ConstraintEdges(view).bottom | ||
} | ||
|
||
var leading: ConstraintEdges { | ||
ConstraintEdges(view).leading | ||
} | ||
|
||
var trailing: ConstraintEdges { | ||
ConstraintEdges(view).trailing | ||
} | ||
|
||
var width: ConstraintEdges { | ||
ConstraintEdges(view).width | ||
} | ||
|
||
var height: ConstraintEdges { | ||
ConstraintEdges(view).height | ||
} | ||
|
||
var centerX: ConstraintEdges { | ||
ConstraintEdges(view).centerX | ||
} | ||
|
||
var centerY: ConstraintEdges { | ||
ConstraintEdges(view).centerY | ||
} | ||
|
||
var center: ConstraintEdges { | ||
ConstraintEdges(view).center | ||
} | ||
|
||
// MARK: Initializer | ||
|
||
init(_ view: UIView) { | ||
self.view = view | ||
} | ||
} | ||
|
||
final class ConstraintEdges { | ||
|
||
// MARK: Properties | ||
|
||
private let view: UIView | ||
|
||
private var topAnchor: NSLayoutYAxisAnchor? | ||
private var leadingAnchor: NSLayoutXAxisAnchor? | ||
private var trailingAnchor: NSLayoutXAxisAnchor? | ||
private var bottomAnchor: NSLayoutYAxisAnchor? | ||
|
||
private var widthAnchor: NSLayoutDimension? | ||
private var heightAnchor: NSLayoutDimension? | ||
|
||
private var centerXAnchor: NSLayoutXAxisAnchor? | ||
private var centerYAnchor: NSLayoutYAxisAnchor? | ||
|
||
// MARK: Builder Pattern Properties | ||
|
||
var top: ConstraintEdges { | ||
topAnchor = view.topAnchor | ||
return self | ||
} | ||
|
||
var leading: ConstraintEdges { | ||
leadingAnchor = view.leadingAnchor | ||
return self | ||
} | ||
|
||
var trailing: ConstraintEdges { | ||
trailingAnchor = view.trailingAnchor | ||
return self | ||
} | ||
|
||
var bottom: ConstraintEdges { | ||
bottomAnchor = view.bottomAnchor | ||
return self | ||
} | ||
|
||
var width: ConstraintEdges { | ||
widthAnchor = view.widthAnchor | ||
return self | ||
} | ||
|
||
var height: ConstraintEdges { | ||
heightAnchor = view.heightAnchor | ||
return self | ||
} | ||
|
||
var centerX: ConstraintEdges { | ||
centerXAnchor = view.centerXAnchor | ||
return self | ||
} | ||
|
||
var centerY: ConstraintEdges { | ||
centerYAnchor = view.centerYAnchor | ||
return self | ||
} | ||
|
||
var center: ConstraintEdges { | ||
centerXAnchor = view.centerXAnchor | ||
centerYAnchor = view.centerYAnchor | ||
return self | ||
} | ||
|
||
// MARK: Intializer | ||
|
||
init(_ view: UIView) { | ||
self.view = view | ||
} | ||
|
||
// MARK: Methods | ||
|
||
func equalToSuperView() { | ||
guard let superView = view.superview else { return } | ||
|
||
NSLayoutConstraint.activate([ | ||
topAnchor?.constraint(equalTo: superView.topAnchor), | ||
leadingAnchor?.constraint(equalTo: superView.leadingAnchor), | ||
trailingAnchor?.constraint(equalTo: superView.trailingAnchor), | ||
bottomAnchor?.constraint(equalTo: superView.bottomAnchor) | ||
].compactMap { $0 }) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper.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,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 { } |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateConstraints도 구현해주세요..
나중에 갖다 써야지..ㅎ