-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split DSL and Kit API to separate Targets (#10)
* Separate DSL and Kit libraries * keep only UIViewKit * Remove labeling of constraints created with DSL in case of interference with custom identifiers * Change some function names and reorganize them * Add swift-snapshot-testing to test target * Fix file header content * Move UIViewKitDevelopmentViews to testTarget and update Carthage project * push toto test * remove file toto from framework * fix carthage fix archive build * fix missing public * test type in extension not published * Fix api scoped with debug * Fix build errors * trying to figure out diff between carthage build and swiftpm * Improving package definition * remove .swiftpm from tracking and update .gitignore * update swiftpm and carthage support * skip ui snapshot tests * remove support for uisnapshot testing
- Loading branch information
Showing
48 changed files
with
766 additions
and
905 deletions.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// IBConstraints.swift | ||
// UIViewKit | ||
// | ||
// Created by Blazej SLEBODA on 30/01/2024. | ||
// | ||
|
||
import UIKit | ||
|
||
public final class IBConstraints { | ||
|
||
private init() {} | ||
|
||
public static func create(from: UIView, to: UIView, guide: LayoutGuide, anchors: ViewAnchor...) -> [NSLayoutConstraint] { | ||
createConstraints(from: from, to: to, guide: guide, anchors: anchors) | ||
} | ||
|
||
static func createConstraints(from: UIView, to: UIView, guide: LayoutGuide, anchors: [ViewAnchor]) -> [NSLayoutConstraint] { | ||
switch guide { | ||
case .view: | ||
return createConstraints(from: from, to: to, anchors: anchors) | ||
case .viewMargins: | ||
return createConstraints(from: from, to: to.layoutMarginsGuide, anchors: anchors) | ||
case .viewSafeArea: | ||
return createConstraints(from: from, to: to.safeAreaLayoutGuide, anchors: anchors) | ||
} | ||
} | ||
|
||
private static func createConstraints(from view: UIView, to target: Any, anchors: [ViewAnchor]) -> [NSLayoutConstraint] { | ||
var constraints: [NSLayoutConstraint] = [] | ||
// swiftlint:disable force_cast | ||
for anchor in anchors { | ||
switch anchor { | ||
case .left(let value): | ||
constraints.append(view.leftAnchor.constraint(equalTo: (target as? UILayoutGuide)?.leftAnchor ?? (target as! UIView).leftAnchor, constant: value)) | ||
case .right(let value): | ||
constraints.append(view.rightAnchor.constraint(equalTo: (target as? UILayoutGuide)?.rightAnchor ?? (target as! UIView).rightAnchor, constant: value)) | ||
case .top(let value): | ||
constraints.append(view.topAnchor.constraint(equalTo: (target as? UILayoutGuide)?.topAnchor ?? (target as! UIView).topAnchor, constant: value)) | ||
case .bottom(let value): | ||
constraints.append(view.bottomAnchor.constraint(equalTo: (target as? UILayoutGuide)?.bottomAnchor ?? (target as! UIView).bottomAnchor, constant: value)) | ||
case .centerX(let value): | ||
constraints.append(view.centerXAnchor.constraint(equalTo: (target as? UILayoutGuide)?.centerXAnchor ?? (target as! UIView).centerXAnchor, constant: value)) | ||
case .centerY(let value): | ||
constraints.append(view.centerYAnchor.constraint(equalTo: (target as? UILayoutGuide)?.centerYAnchor ?? (target as! UIView).centerYAnchor, constant: value)) | ||
case .leading(let value): | ||
constraints.append(view.leadingAnchor.constraint(equalTo: (target as? UILayoutGuide)?.leadingAnchor ?? (target as! UIView).leadingAnchor, constant: value)) | ||
case .trailing(let value): | ||
constraints.append(view.trailingAnchor.constraint(equalTo: (target as? UILayoutGuide)?.trailingAnchor ?? (target as! UIView).trailingAnchor, constant: value)) | ||
case .all: | ||
constraints.append(contentsOf: createConstraints(from: view, to: target, anchors: [.top, .bottom, .left, .right])) | ||
} | ||
} | ||
// swiftlint:enable force_cast | ||
return constraints | ||
} | ||
|
||
public enum LayoutGuide { | ||
case view | ||
case viewMargins | ||
case viewSafeArea | ||
} | ||
|
||
public enum ViewAnchor { | ||
case left(CGFloat) | ||
case right(CGFloat) | ||
case top(CGFloat) | ||
case bottom(CGFloat) | ||
case centerX(CGFloat) | ||
case centerY(CGFloat) | ||
case leading(CGFloat) | ||
case trailing(CGFloat) | ||
case all | ||
static public var left: ViewAnchor { return .left(.zero) } | ||
static public var right: ViewAnchor { return .right(.zero) } | ||
static public var top: ViewAnchor { return .top(.zero) } | ||
static public var bottom: ViewAnchor { return .bottom(.zero) } | ||
static public var centerX: ViewAnchor { return .centerX(.zero) } | ||
static public var centerY: ViewAnchor { return .centerY(.zero) } | ||
static public var leading: ViewAnchor { return .leading(.zero) } | ||
static public var trailing: ViewAnchor { return .trailing(.zero) } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// IBPreview+FreeFormView.swift | ||
// UIViewKit | ||
// | ||
// Created by Blazej SLEBODA on 14/11/2023. | ||
// | ||
|
||
import UIKit | ||
import SwiftUI | ||
|
||
extension IBPreview { | ||
|
||
@available(iOS 13.0, *) | ||
public struct FreeFormView: UIViewControllerRepresentable { | ||
|
||
private let viewMaker: (Context) -> UIView | ||
|
||
public init(_ view: UIView) { | ||
self.viewMaker = { _ in | ||
view | ||
} | ||
} | ||
|
||
public init(viewMaker: @escaping (Context) -> UIView) { | ||
self.viewMaker = viewMaker | ||
} | ||
|
||
public func makeUIViewController(context: Context) -> UIViewController { | ||
let controller = UIViewController() | ||
let view = viewMaker(context) | ||
controller.view.addSubview(view) | ||
view.frame = controller.view.bounds | ||
view.autoresizingMask = [.flexibleHeight, .flexibleWidth] | ||
view.translatesAutoresizingMaskIntoConstraints = true | ||
|
||
let freeFormContainer = ContainerViewController() | ||
_ = freeFormContainer.view | ||
freeFormContainer.childViewController = controller | ||
return freeFormContainer | ||
} | ||
|
||
public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { } | ||
} | ||
} |
Oops, something went wrong.