Skip to content

Commit ce07794

Browse files
Merge branch 'modal-uikit' into modal-swiftui
2 parents 894f999 + c661a60 commit ce07794

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

Sources/ComponentsKit/Modal/UIKit/Helpers/ContentSizedScrollView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import UIKit
22

3-
public final class ContentSizedScrollView: UIScrollView {
4-
public override var contentSize: CGSize {
3+
/// A custom `UIScrollView` subclass that automatically adjusts its intrinsic content size
4+
/// based on its content size, ensuring it fits its content vertically.
5+
final class ContentSizedScrollView: UIScrollView {
6+
override var contentSize: CGSize {
57
didSet {
68
self.invalidateIntrinsicContentSize()
79
}
810
}
911

10-
public override var intrinsicContentSize: CGSize {
12+
override var intrinsicContentSize: CGSize {
1113
self.layoutIfNeeded()
1214
return CGSize(
1315
width: UIView.noIntrinsicMetric,

Sources/ComponentsKit/Modal/UIKit/UKBottomModalController.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import UIKit
22

3+
/// A bottom-aligned modal controller.
34
public class UKBottomModalController: UKModalController<BottomModalVM> {
5+
// MARK: - Initialization
6+
7+
/// Initializer.
8+
///
9+
/// - Parameters:
10+
/// - model: A model that defines the appearance properties.
11+
/// - header: An optional content block for the modal's header.
12+
/// - body: The main content block for the modal.
13+
/// - footer: An optional content block for the modal's footer.
414
public override init(
515
model: BottomModalVM = .init(),
616
header: Content? = nil,
@@ -14,6 +24,8 @@ public class UKBottomModalController: UKModalController<BottomModalVM> {
1424
fatalError("init(coder:) has not been implemented")
1525
}
1626

27+
// MARK: - Lifecycle
28+
1729
public override func viewWillAppear(_ animated: Bool) {
1830
super.viewWillAppear(animated)
1931

@@ -30,6 +42,8 @@ public class UKBottomModalController: UKModalController<BottomModalVM> {
3042
}
3143
}
3244

45+
// MARK: - Setup
46+
3347
public override func setup() {
3448
super.setup()
3549

@@ -39,12 +53,16 @@ public class UKBottomModalController: UKModalController<BottomModalVM> {
3953
))
4054
}
4155

56+
// MARK: - Layout
57+
4258
public override func layout() {
4359
super.layout()
4460

4561
self.container.bottom(self.model.outerPaddings.bottom, safeArea: true)
4662
}
4763

64+
// MARK: - UIViewController Methods
65+
4866
public override func dismiss(
4967
animated flag: Bool,
5068
completion: (() -> Void)? = nil

Sources/ComponentsKit/Modal/UIKit/UKCenterModalController.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import UIKit
22

3+
/// A center-aligned modal controller.
34
public class UKCenterModalController: UKModalController<CenterModalVM> {
5+
// MARK: - Initialization
6+
7+
/// Initializer.
8+
///
9+
/// - Parameters:
10+
/// - model: A model that defines the appearance properties.
11+
/// - header: An optional content block for the modal's header.
12+
/// - body: The main content block for the modal.
13+
/// - footer: An optional content block for the modal's footer.
414
public override init(
515
model: CenterModalVM = .init(),
616
header: Content? = nil,
@@ -14,6 +24,8 @@ public class UKCenterModalController: UKModalController<CenterModalVM> {
1424
fatalError("init(coder:) has not been implemented")
1525
}
1626

27+
// MARK: - Lifecycle
28+
1729
public override func viewWillAppear(_ animated: Bool) {
1830
super.viewWillAppear(animated)
1931

@@ -30,6 +42,8 @@ public class UKCenterModalController: UKModalController<CenterModalVM> {
3042
}
3143
}
3244

45+
// MARK: - Layout
46+
3347
public override func layout() {
3448
super.layout()
3549

@@ -40,6 +54,8 @@ public class UKCenterModalController: UKModalController<CenterModalVM> {
4054
self.container.centerVertically()
4155
}
4256

57+
// MARK: - UIViewController Methods
58+
4359
public override func dismiss(
4460
animated flag: Bool,
4561
completion: (() -> Void)? = nil

Sources/ComponentsKit/Modal/UIKit/UKModalController.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
import AutoLayout
22
import UIKit
33

4+
/// A generic class that defines shared behavior for modal controllers.
45
open class UKModalController<VM: ModalVM>: UIViewController {
6+
// MARK: - Typealiases
7+
8+
/// A typealias for content providers, which create views for the header, body, or footer.
9+
/// The content provider closure receives a dismiss action that can be called to close the modal.
510
public typealias Content = (_ dismiss: @escaping (_ animated: Bool) -> Void) -> UIView
611

12+
// MARK: - Properties
13+
14+
/// A model that defines the appearance properties.
715
public let model: VM
816

17+
/// The optional header view of the modal.
918
public var header: UIView?
19+
/// The main body view of the modal.
1020
public var body = UIView()
21+
/// The optional footer view of the modal.
1122
public var footer: UIView?
12-
public var container = UIView()
23+
/// The container view that holds the modal's content.
24+
public let container = UIView()
25+
/// The content view inside the container, holding the header, body, and footer.
1326
public let content = UIView()
14-
public let bodyWrapper = ContentSizedScrollView()
27+
/// A scrollable wrapper for the body content.
28+
public let bodyWrapper: UIScrollView = ContentSizedScrollView()
29+
/// The overlay view that appears behind the modal.
1530
public let overlay: UIView
1631

32+
// MARK: - Initialization
33+
1734
init(
1835
model: VM = .init(),
1936
header: Content? = nil,
@@ -49,6 +66,8 @@ open class UKModalController<VM: ModalVM>: UIViewController {
4966
fatalError("init(coder:) has not been implemented")
5067
}
5168

69+
// MARK: - Lifecycle
70+
5271
open override func viewDidLoad() {
5372
super.viewDidLoad()
5473

@@ -59,6 +78,7 @@ open class UKModalController<VM: ModalVM>: UIViewController {
5978

6079
// MARK: - Setup
6180

81+
/// Sets up the modal's subviews and gesture recognizers.
6282
open func setup() {
6383
self.view.addSubview(self.overlay)
6484
self.view.addSubview(self.container)
@@ -86,6 +106,7 @@ open class UKModalController<VM: ModalVM>: UIViewController {
86106

87107
// MARK: - Style
88108

109+
/// Applies styling to the modal's components based on the model.
89110
open func style() {
90111
Self.Style.overlay(self.overlay, model: self.model)
91112
Self.Style.container(self.container, model: self.model)
@@ -95,6 +116,7 @@ open class UKModalController<VM: ModalVM>: UIViewController {
95116

96117
// MARK: - Layout
97118

119+
/// Configures the layout of the modal's components.
98120
open func layout() {
99121
self.overlay.allEdges()
100122
self.content.allEdges()

0 commit comments

Comments
 (0)