Skip to content

Commit bf96d2f

Browse files
author
Semen Osipov
committed
Remove SnapKit dependency in favor of native AutoLayout
Made-with: Cursor
1 parent 7036928 commit bf96d2f

7 files changed

Lines changed: 32 additions & 71 deletions

File tree

ARBottomSheetViewController.xcodeproj/project.pbxproj

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
064ACDB02B7CDB5300C82CBB /* ARBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064ACDAF2B7CDB5300C82CBB /* ARBottomSheetViewController.swift */; };
1414
064ACDB22B7CDB5600C82CBB /* ARInitialTouchPanGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064ACDB12B7CDB5600C82CBB /* ARInitialTouchPanGestureRecognizer.swift */; };
1515
064ACDC12B7CDB6000C82CBB /* ARBottomSheetConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064ACDC02B7CDB6000C82CBB /* ARBottomSheetConfiguration.swift */; };
16-
064ACDB52B7CDBDA00C82CBB /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 064ACDB42B7CDBDA00C82CBB /* SnapKit */; };
1716
064ACDBC2B7CDC3200C82CBB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 064ACDBA2B7CDC0900C82CBB /* UIKit.framework */; platformFilter = ios; };
1817
064ACDBD2B7CDC3200C82CBB /* UIKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 064ACDBA2B7CDC0900C82CBB /* UIKit.framework */; platformFilter = ios; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1918
/* End PBXBuildFile section */
@@ -48,7 +47,6 @@
4847
isa = PBXFrameworksBuildPhase;
4948
buildActionMask = 2147483647;
5049
files = (
51-
064ACDB52B7CDBDA00C82CBB /* SnapKit in Frameworks */,
5250
064ACDBC2B7CDC3200C82CBB /* UIKit.framework in Frameworks */,
5351
);
5452
runOnlyForDeploymentPostprocessing = 0;
@@ -132,7 +130,6 @@
132130
);
133131
name = ARBottomSheetViewController;
134132
packageProductDependencies = (
135-
064ACDB42B7CDBDA00C82CBB /* SnapKit */,
136133
);
137134
productName = ARBottomSheetViewController;
138135
productReference = 064ACD972B7CB55000C82CBB /* ARBottomSheetViewController.framework */;
@@ -162,7 +159,6 @@
162159
);
163160
mainGroup = 064ACD8D2B7CB55000C82CBB;
164161
packageReferences = (
165-
064ACDB32B7CDBDA00C82CBB /* XCRemoteSwiftPackageReference "SnapKit" */,
166162
);
167163
productRefGroup = 064ACD982B7CB55000C82CBB /* Products */;
168164
projectDirPath = "";
@@ -421,22 +417,9 @@
421417
/* End XCConfigurationList section */
422418

423419
/* Begin XCRemoteSwiftPackageReference section */
424-
064ACDB32B7CDBDA00C82CBB /* XCRemoteSwiftPackageReference "SnapKit" */ = {
425-
isa = XCRemoteSwiftPackageReference;
426-
repositoryURL = "https://github.com/SnapKit/SnapKit.git";
427-
requirement = {
428-
kind = upToNextMajorVersion;
429-
minimumVersion = 5.0.1;
430-
};
431-
};
432420
/* End XCRemoteSwiftPackageReference section */
433421

434422
/* Begin XCSwiftPackageProductDependency section */
435-
064ACDB42B7CDBDA00C82CBB /* SnapKit */ = {
436-
isa = XCSwiftPackageProductDependency;
437-
package = 064ACDB32B7CDBDA00C82CBB /* XCRemoteSwiftPackageReference "SnapKit" */;
438-
productName = SnapKit;
439-
};
440423
/* End XCSwiftPackageProductDependency section */
441424
};
442425
rootObject = 064ACD8E2B7CB55000C82CBB /* Project object */;

ARBottomSheetViewController.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 14 deletions
This file was deleted.

ARBottomSheetViewController/Sources/ARBottomSheetPresentationController.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import UIKit
9-
import SnapKit
109

1110
protocol ARBottomSheetPresentationControllerDelegate: AnyObject {
1211
var preferredControllerHeight: CGFloat {get}
@@ -80,9 +79,13 @@ class ARBottomSheetPresentationController: UIPresentationController {
8079
}
8180
}
8281

83-
dimmingView.snp.makeConstraints {
84-
$0.top.bottom.leading.trailing.equalToSuperview()
85-
}
82+
dimmingView.translatesAutoresizingMaskIntoConstraints = false
83+
NSLayoutConstraint.activate([
84+
dimmingView.topAnchor.constraint(equalTo: containerView.topAnchor),
85+
dimmingView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
86+
dimmingView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
87+
dimmingView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
88+
])
8689

8790
dimmingView.backgroundColor = .black.withAlphaComponent(0)
8891
if let coordinator = presentedViewController.transitionCoordinator {

ARBottomSheetViewController/Sources/ARBottomSheetViewController.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import UIKit
9-
import SnapKit
109

1110
public protocol ARBottomSheetViewControllerDelegate: AnyObject {
1211
var contentHeight: CGFloat {get}
@@ -87,21 +86,23 @@ open class ARBottomSheetViewController: UIViewController {
8786
stickView.isHidden = !configuration.showsHandle
8887
stickView.layer.cornerRadius = configuration.handleSize.height / 2
8988

90-
stickView.snp.makeConstraints {
91-
$0.centerX.equalToSuperview()
92-
$0.width.equalTo(configuration.handleSize.width)
93-
$0.height.equalTo(configuration.handleSize.height)
94-
$0.top.equalToSuperview().inset(configuration.handleTopInset)
95-
}
89+
stickView.translatesAutoresizingMaskIntoConstraints = false
90+
NSLayoutConstraint.activate([
91+
stickView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
92+
stickView.widthAnchor.constraint(equalToConstant: configuration.handleSize.width),
93+
stickView.heightAnchor.constraint(equalToConstant: configuration.handleSize.height),
94+
stickView.topAnchor.constraint(equalTo: view.topAnchor, constant: configuration.handleTopInset)
95+
])
9696

97-
contentView.snp.makeConstraints {
98-
$0.leading.trailing.bottom.equalToSuperview()
99-
if configuration.showsHandle {
100-
$0.top.equalTo(stickView.snp.bottom).offset(configuration.handleBottomInset)
101-
} else {
102-
$0.top.equalToSuperview()
103-
}
104-
}
97+
contentView.translatesAutoresizingMaskIntoConstraints = false
98+
NSLayoutConstraint.activate([
99+
contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
100+
contentView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
101+
contentView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
102+
configuration.showsHandle
103+
? contentView.topAnchor.constraint(equalTo: stickView.bottomAnchor, constant: configuration.handleBottomInset)
104+
: contentView.topAnchor.constraint(equalTo: view.topAnchor)
105+
])
105106
}
106107
}
107108

Package.resolved

Lines changed: 0 additions & 14 deletions
This file was deleted.

Package.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ let package = Package(
1414
name: "ARBottomSheetViewController",
1515
targets: ["ARBottomSheetViewController"]),
1616
],
17-
dependencies: [
18-
.package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
19-
],
17+
dependencies: [],
2018
targets: [
2119
// Targets are the basic building blocks of a package, defining a module or a test suite.
2220
// Targets can depend on other targets in this package and products from dependencies.
2321
.target(
2422
name: "ARBottomSheetViewController",
25-
dependencies: ["SnapKit"],
23+
dependencies: [],
2624
path: "ARBottomSheetViewController/Sources")
2725
]
2826
)

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ bottomSheet.sheetDelegate = self
5050
let label = UILabel()
5151
label.text = "Hello, Bottom Sheet!"
5252
bottomSheet.contentBackgroundView.addSubview(label)
53-
label.snp.makeConstraints {
54-
$0.edges.equalToSuperview().inset(16)
55-
}
53+
label.translatesAutoresizingMaskIntoConstraints = false
54+
NSLayoutConstraint.activate([
55+
label.topAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.topAnchor, constant: 16),
56+
label.leadingAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.leadingAnchor, constant: 16),
57+
label.trailingAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.trailingAnchor, constant: -16),
58+
label.bottomAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.bottomAnchor, constant: -16)
59+
])
5660
```
5761

5862
### 3. Present it

0 commit comments

Comments
 (0)