mirror of https://github.com/SnapKit/SnapKit
Switch makerFile/line to use SourceLocation for consistency
Allows removing redundant default location
This commit is contained in:
parent
bbe5b2e49d
commit
0fe4ad005b
|
@ -58,8 +58,7 @@ public class Constraint {
|
||||||
public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||||
public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||||
|
|
||||||
internal var makerFile: String = "Unknown"
|
internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0)
|
||||||
internal var makerLine: UInt = 0
|
|
||||||
|
|
||||||
internal(set) public var location : SourceLocation?
|
internal(set) public var location : SourceLocation?
|
||||||
}
|
}
|
||||||
|
@ -131,7 +130,7 @@ internal class ConcreteConstraint: Constraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override func install() -> [LayoutConstraint] {
|
internal override func install() -> [LayoutConstraint] {
|
||||||
return self.installOnView(updateExisting: false, file: self.makerFile, line: self.makerLine)
|
return self.installOnView(updateExisting: false, location: self.makerLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override func uninstall() -> Void {
|
internal override func uninstall() -> Void {
|
||||||
|
@ -207,12 +206,12 @@ internal class ConcreteConstraint: Constraint {
|
||||||
self.location = location
|
self.location = location
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func installOnView(updateExisting updateExisting: Bool = false, file: String? = nil, line: UInt? = nil) -> [LayoutConstraint] {
|
internal func installOnView(updateExisting updateExisting: Bool = false, location: SourceLocation? = nil) -> [LayoutConstraint] {
|
||||||
var installOnView: View? = nil
|
var installOnView: View? = nil
|
||||||
if self.toItem.view != nil {
|
if self.toItem.view != nil {
|
||||||
installOnView = closestCommonSuperviewFromView(self.fromItem.view, toView: self.toItem.view)
|
installOnView = closestCommonSuperviewFromView(self.fromItem.view, toView: self.toItem.view)
|
||||||
if installOnView == nil {
|
if installOnView == nil {
|
||||||
NSException(name: "Cannot Install Constraint", reason: "No common superview between views (@\(self.makerFile)#\(self.makerLine))", userInfo: nil).raise()
|
NSException(name: "Cannot Install Constraint", reason: "No common superview between views (@\(self.makerLocation.file)#\(self.makerLocation.line))", userInfo: nil).raise()
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +221,7 @@ internal class ConcreteConstraint: Constraint {
|
||||||
} else {
|
} else {
|
||||||
installOnView = self.fromItem.view?.superview
|
installOnView = self.fromItem.view?.superview
|
||||||
if installOnView == nil {
|
if installOnView == nil {
|
||||||
NSException(name: "Cannot Install Constraint", reason: "Missing superview (@\(self.makerFile)#\(self.makerLine))", userInfo: nil).raise()
|
NSException(name: "Cannot Install Constraint", reason: "Missing superview (@\(self.makerLocation.file)#\(self.self.makerLocation.line))", userInfo: nil).raise()
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +229,7 @@ internal class ConcreteConstraint: Constraint {
|
||||||
|
|
||||||
if let installedOnView = self.installInfo?.view {
|
if let installedOnView = self.installInfo?.view {
|
||||||
if installedOnView != installOnView {
|
if installedOnView != installOnView {
|
||||||
NSException(name: "Cannot Install Constraint", reason: "Already installed on different view. (@\(self.makerFile)#\(self.makerLine))", userInfo: nil).raise()
|
NSException(name: "Cannot Install Constraint", reason: "Already installed on different view. (@\(self.makerLocation.file)#\(self.makerLocation.line))", userInfo: nil).raise()
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
return self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] ?? []
|
return self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] ?? []
|
||||||
|
|
|
@ -118,14 +118,12 @@ public class ConstraintMaker {
|
||||||
@available(iOS 8.0, *)
|
@available(iOS 8.0, *)
|
||||||
public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) }
|
public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) }
|
||||||
|
|
||||||
internal init(view: View, file: String, line: UInt) {
|
internal init(view: View, location: SourceLocation) {
|
||||||
self.view = view
|
self.view = view
|
||||||
self.file = file
|
self.location = location
|
||||||
self.line = line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal let file: String
|
internal let location: SourceLocation
|
||||||
internal let line: UInt
|
|
||||||
internal let view: View
|
internal let view: View
|
||||||
internal var constraintDescriptions = [ConstraintDescription]()
|
internal var constraintDescriptions = [ConstraintDescription]()
|
||||||
|
|
||||||
|
@ -136,54 +134,50 @@ public class ConstraintMaker {
|
||||||
return ConstraintDescriptionExtendable(constraintDescription)
|
return ConstraintDescriptionExtendable(constraintDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class func prepareConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
|
internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
|
||||||
let maker = ConstraintMaker(view: view, file: file, line: line)
|
let maker = ConstraintMaker(view: view, location : location)
|
||||||
closure(make: maker)
|
closure(make: maker)
|
||||||
|
|
||||||
let constraints = maker.constraintDescriptions.map { $0.constraint }
|
let constraints = maker.constraintDescriptions.map { $0.constraint }
|
||||||
for constraint in constraints {
|
for constraint in constraints {
|
||||||
constraint.makerFile = maker.file
|
constraint.makerLocation = maker.location
|
||||||
constraint.makerLine = maker.line
|
|
||||||
}
|
}
|
||||||
return constraints
|
return constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class func makeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
|
internal class func makeConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
let maker = ConstraintMaker(view: view, file: file, line: line)
|
let maker = ConstraintMaker(view: view, location: location)
|
||||||
closure(make: maker)
|
closure(make: maker)
|
||||||
|
|
||||||
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
|
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
|
||||||
for constraint in constraints {
|
for constraint in constraints {
|
||||||
constraint.makerFile = maker.file
|
constraint.makerLocation = maker.location
|
||||||
constraint.makerLine = maker.line
|
|
||||||
constraint.installOnView(updateExisting: false)
|
constraint.installOnView(updateExisting: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class func remakeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
|
internal class func remakeConstraints(view view: View, location : SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
let maker = ConstraintMaker(view: view, file: file, line: line)
|
let maker = ConstraintMaker(view: view, location: location)
|
||||||
closure(make: maker)
|
closure(make: maker)
|
||||||
|
|
||||||
self.removeConstraints(view: view)
|
self.removeConstraints(view: view)
|
||||||
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
|
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
|
||||||
for constraint in constraints {
|
for constraint in constraints {
|
||||||
constraint.makerFile = maker.file
|
constraint.makerLocation = maker.location
|
||||||
constraint.makerLine = maker.line
|
|
||||||
constraint.installOnView(updateExisting: false)
|
constraint.installOnView(updateExisting: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class func updateConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
|
internal class func updateConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
let maker = ConstraintMaker(view: view, file: file, line: line)
|
let maker = ConstraintMaker(view: view, location: location)
|
||||||
closure(make: maker)
|
closure(make: maker)
|
||||||
|
|
||||||
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint}
|
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint}
|
||||||
for constraint in constraints {
|
for constraint in constraints {
|
||||||
constraint.makerFile = maker.file
|
constraint.makerLocation = maker.location
|
||||||
constraint.makerLine = maker.line
|
|
||||||
constraint.installOnView(updateExisting: true)
|
constraint.installOnView(updateExisting: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,11 @@ public extension LayoutConstraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var snp_makerFile: String? {
|
internal var snp_makerFile: String? {
|
||||||
return self.snp_constraint?.makerFile
|
return self.snp_constraint?.makerLocation.file
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var snp_makerLine: UInt? {
|
internal var snp_makerLine: UInt? {
|
||||||
return self.snp_constraint?.makerLine
|
return self.snp_constraint?.makerLocation.line
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public extension View {
|
||||||
:returns: the constraints made
|
:returns: the constraints made
|
||||||
*/
|
*/
|
||||||
public func snp_prepareConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
|
public func snp_prepareConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
|
||||||
return ConstraintMaker.prepareConstraints(view: self, file: file, line: line, closure: closure)
|
return ConstraintMaker.prepareConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +137,7 @@ public extension View {
|
||||||
:param: closure that will be passed the `ConstraintMaker` to make the constraints with
|
:param: closure that will be passed the `ConstraintMaker` to make the constraints with
|
||||||
*/
|
*/
|
||||||
public func snp_makeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
public func snp_makeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
||||||
ConstraintMaker.makeConstraints(view: self, file: file, line: line, closure: closure)
|
ConstraintMaker.makeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,7 +148,7 @@ public extension View {
|
||||||
:param: closure that will be passed the `ConstraintMaker` to update the constraints with
|
:param: closure that will be passed the `ConstraintMaker` to update the constraints with
|
||||||
*/
|
*/
|
||||||
public func snp_updateConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
public func snp_updateConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
||||||
ConstraintMaker.updateConstraints(view: self, file: file, line: line, closure: closure)
|
ConstraintMaker.updateConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,7 +157,7 @@ public extension View {
|
||||||
:param: closure that will be passed the `ConstraintMaker` to remake the constraints with
|
:param: closure that will be passed the `ConstraintMaker` to remake the constraints with
|
||||||
*/
|
*/
|
||||||
public func snp_remakeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
public func snp_remakeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void {
|
||||||
ConstraintMaker.remakeConstraints(view: self, file: file, line: line, closure: closure)
|
ConstraintMaker.remakeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue