Skip to content

Commit

Permalink
feat: bottom controller interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mikhailovskii committed Nov 19, 2024
1 parent 3ab27cf commit a1e39d2
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 27 deletions.
29 changes: 9 additions & 20 deletions PanModal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 55;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -21,6 +21,7 @@
B9E8259F773D27BAA416DCDB /* PanModalPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58F1F9245FCF277E33A16FE /* PanModalPresentationController.swift */; };
BD2A2F384AA6A669BB094AFE /* DimmedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9359135D025D85DF75DE4F5 /* DimmedView.swift */; };
C5212562E96EB66723FA4AF5 /* PanModalNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAE1B81D3CE5D181BF9FEC5 /* PanModalNavigationController.swift */; };
D34C74042CEC2CF3006A7DA7 /* ContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34C74032CEC2CF3006A7DA7 /* ContainerView.swift */; };
DF004916923A0853BE2A6EF3 /* PanModalPresentable+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A6D777902F927D45E55BD58 /* PanModalPresentable+UIViewController.swift */; };
EB726BFFEE56C0BF9E060581 /* PanModalPresentationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666A2C96EA5A339D2BF1AFD7 /* PanModalPresentationDelegate.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -54,6 +55,7 @@
BCF005E45B676AD3F7B78FAD /* PanModalPresentable+LayoutHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PanModalPresentable+LayoutHelpers.swift"; sourceTree = "<group>"; };
BE33C1773BA187DC156A1573 /* PanModalPresentationAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanModalPresentationAnimator.swift; sourceTree = "<group>"; };
CEF747134DCC92CD1E6B1A1C /* PanModalPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanModalPresentable.swift; sourceTree = "<group>"; };
D34C74032CEC2CF3006A7DA7 /* ContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerView.swift; sourceTree = "<group>"; };
D58F1F9245FCF277E33A16FE /* PanModalPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanModalPresentationController.swift; sourceTree = "<group>"; };
D9359135D025D85DF75DE4F5 /* DimmedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DimmedView.swift; sourceTree = "<group>"; };
F99DE1EC61D2721C1D5BD49E /* PanModalKeyboardPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanModalKeyboardPresentable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,6 +148,7 @@
children = (
D9359135D025D85DF75DE4F5 /* DimmedView.swift */,
6182FE3A8D6D219CE0CDCCCF /* PanContainerView.swift */,
D34C74032CEC2CF3006A7DA7 /* ContainerView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -226,8 +229,6 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 9999;
TargetAttributes = {
};
};
buildConfigurationList = CCC9A83A9BFD2A0A523DC090 /* Build configuration list for PBXProject "PanModal" */;
compatibilityVersion = "Xcode 13.0";
Expand Down Expand Up @@ -271,6 +272,7 @@
564E41966241D7803EA68C20 /* PanModalKeyboardPresentable.swift in Sources */,
1D34D9B02EB1AC010D28A788 /* PanModalHeight.swift in Sources */,
7F6A9D4296C19BBC01898E49 /* PanModalPresentable+Defaults.swift in Sources */,
D34C74042CEC2CF3006A7DA7 /* ContainerView.swift in Sources */,
A5E91380A4091F2092B662CE /* PanModalPresentable+LayoutHelpers.swift in Sources */,
DF004916923A0853BE2A6EF3 /* PanModalPresentable+UIViewController.swift in Sources */,
4ADB47FF2175663ADCA39476 /* PanModalPresentable.swift in Sources */,
Expand Down Expand Up @@ -539,10 +541,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
"$(inherited)",
SWIFT_PACKAGE,
);
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SUPPRESS_WARNINGS = YES;
Expand Down Expand Up @@ -590,10 +589,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
"$(inherited)",
SWIFT_PACKAGE,
);
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SUPPRESS_WARNINGS = YES;
Expand Down Expand Up @@ -641,10 +637,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
"$(inherited)",
SWIFT_PACKAGE,
);
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SUPPRESS_WARNINGS = YES;
Expand Down Expand Up @@ -692,11 +685,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
"$(inherited)",
DEBUG,
SWIFT_PACKAGE,
);
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG SWIFT_PACKAGE";
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SUPPRESS_WARNINGS = YES;
Expand Down
4 changes: 4 additions & 0 deletions PanModal/Controller/PanModalNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ open class PanModalNavController: UINavigationController, PanModalPresentable {
self.presentViewController.panModalBackgroundColor
}

open var isInteractiveBottomController: Bool {
self.presentViewController.isInteractiveBottomController
}

open var dragIndicatorBackgroundColor: UIColor {
self.presentViewController.dragIndicatorBackgroundColor
}
Expand Down
29 changes: 24 additions & 5 deletions PanModal/Controller/PanModalPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import UIKit
By conforming to the PanModalPresentable protocol & overriding values
the presented view can define its layout configuration & presentation.
*/

open class PanModalPresentationController: UIPresentationController {

/**
Expand Down Expand Up @@ -115,11 +116,11 @@ open class PanModalPresentationController: UIPresentationController {
} else {
view = DimmedView()
}
view.didTap = { [weak self] _ in
if self?.presentable?.allowsTapToDismiss == true {
self?.presentedViewController.dismiss(animated: true)
}
}
view.didTap = { [weak self] _ in
if self?.presentable?.allowsTapToDismiss == true {
self?.presentedViewController.dismiss(animated: true)
}
}
return view
}()

Expand Down Expand Up @@ -250,6 +251,14 @@ open class PanModalPresentationController: UIPresentationController {
})
}

private func getNotBottomSheetViewController(_ viewController: UIViewController?) -> UIViewController? {
if viewController is PanModalPresentable {
return self.getNotBottomSheetViewController(viewController?.presentingViewController)
}

return viewController
}

}

// MARK: - Public Methods
Expand Down Expand Up @@ -409,6 +418,15 @@ private extension PanModalPresentationController {
backgroundView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true
backgroundView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true
backgroundView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true

if let presentingViewController =
self.getNotBottomSheetViewController(self.presentingViewController) {

self.backgroundView.passthroughViews = [
presentingViewController.view
]
}

}

/**
Expand Down Expand Up @@ -440,6 +458,7 @@ private extension PanModalPresentationController {
enableCustomInteractiveKeyboard = layoutPresentable.enableCustomInteractiveKeyboard

containerView?.isUserInteractionEnabled = layoutPresentable.isUserInteractionEnabled
self.backgroundView.isInteractiveBottomController = layoutPresentable.isInteractiveBottomController
}

/**
Expand Down
4 changes: 4 additions & 0 deletions PanModal/Presentable/PanModalPresentable+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public extension PanModalPresentable where Self: UIViewController {
return true
}

var isInteractiveBottomController: Bool {
false
}

var shouldRoundTopCorners: Bool {
return isPanModalPresented
}
Expand Down
4 changes: 4 additions & 0 deletions PanModal/Presentable/PanModalPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public protocol PanModalPresentable: AnyObject {
*/
var allowsDragToDismiss: Bool { get }

/**
A flag enable user interactions on bottom controller
*/
var isInteractiveBottomController: Bool { get }
/**
A flag to determine if dismissal should be initiated when tapping on the dimmed background view.

Expand Down
25 changes: 25 additions & 0 deletions PanModal/View/ContainerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import UIKit

public class ContainerView: UIView {

var isInteractiveBottomController = false
var passthroughViews = [UIView]()

public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
var hittedView: UIView? = super.hitTest(point, with: event)
if !self.isInteractiveBottomController { return hittedView }

if hittedView == self {
self.passthroughViews.forEach { passthroughView in
hittedView = passthroughView.hitTest(
self.convert(point, to: passthroughView),
with: event
)

if hittedView != nil { return }
}
}

return hittedView
}
}
2 changes: 1 addition & 1 deletion PanModal/View/DimmedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
/**
A dim view for use as an overlay over content you want dimmed.
*/
public class DimmedView: UIView {
public class DimmedView: ContainerView {

/**
Represents the possible states of the dimmed view.
Expand Down
2 changes: 1 addition & 1 deletion PanModal/View/PanContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UIKit
This allows us to make modifications to the presented view without
having to do those changes directly on the view
*/
class PanContainerView: UIView {
public class PanContainerView: UIView {

init(presentedView: UIView, frame: CGRect) {
super.init(frame: frame)
Expand Down

0 comments on commit a1e39d2

Please sign in to comment.