diff --git a/Examples/SingleNavigator/01-SingleBasic/SingleBasic/Page/Home/HomeView.swift b/Examples/SingleNavigator/01-SingleBasic/SingleBasic/Page/Home/HomeView.swift index b98ecc1..f1ea6bc 100644 --- a/Examples/SingleNavigator/01-SingleBasic/SingleBasic/Page/Home/HomeView.swift +++ b/Examples/SingleNavigator/01-SingleBasic/SingleBasic/Page/Home/HomeView.swift @@ -42,7 +42,7 @@ struct HomeView: View { Text("open Page 2 as Sheet") .foregroundColor(.purple) } - + Button(action: { if #available(iOS 15.0, *) { navigator.detentSheet(linkItem: .init(pathList: ["page1", "page2"]), isAnimated: true, configuration: .default) diff --git a/Sources/LinkNavigator/Core/Core/DetentConfiguration.swift b/Sources/LinkNavigator/Core/Core/DetentConfiguration.swift index 262152d..c916175 100644 --- a/Sources/LinkNavigator/Core/Core/DetentConfiguration.swift +++ b/Sources/LinkNavigator/Core/Core/DetentConfiguration.swift @@ -2,18 +2,9 @@ import UIKit @available(iOS 15.0, *) public struct DetentConfiguration { - - public static let `default` = DetentConfiguration(detents: [.medium(), .large()]) - - public let detents: [UISheetPresentationController.Detent] - public let cornerRadius: CGFloat? - public let largestUndimmedDetentIdentifier: UISheetPresentationController.Detent.Identifier? - public let prefersScrollingExpandsWhenScrolledToEdge: Bool - public let prefersGrabberVisible: Bool - public let prefersEdgeAttachedInCompactHeight: Bool - public let widthFollowsPreferredContentSizeWhenEdgeAttached: Bool - public let selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? - + + // MARK: Lifecycle + /// Initializes a new DetentConfiguration. /// /// - Parameters: @@ -33,8 +24,8 @@ public struct DetentConfiguration { prefersGrabberVisible: Bool = false, prefersEdgeAttachedInCompactHeight: Bool = false, widthFollowsPreferredContentSizeWhenEdgeAttached: Bool = false, - selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? = nil - ) { + selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? = nil) + { self.detents = detents self.cornerRadius = cornerRadius self.largestUndimmedDetentIdentifier = largestUndimmedDetentIdentifier @@ -44,4 +35,17 @@ public struct DetentConfiguration { self.widthFollowsPreferredContentSizeWhenEdgeAttached = widthFollowsPreferredContentSizeWhenEdgeAttached self.selectedDetentIdentifier = selectedDetentIdentifier } + + // MARK: Public + + public static let `default` = DetentConfiguration(detents: [.medium(), .large()]) + + public let detents: [UISheetPresentationController.Detent] + public let cornerRadius: CGFloat? + public let largestUndimmedDetentIdentifier: UISheetPresentationController.Detent.Identifier? + public let prefersScrollingExpandsWhenScrolledToEdge: Bool + public let prefersGrabberVisible: Bool + public let prefersEdgeAttachedInCompactHeight: Bool + public let widthFollowsPreferredContentSizeWhenEdgeAttached: Bool + public let selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? } diff --git a/Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift b/Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift index 0f320d8..18bbffe 100644 --- a/Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift +++ b/Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift @@ -140,7 +140,7 @@ extension SingleLinkNavigator { private func _sheet(linkItem: LinkItem, isAnimated: Bool) { sheetOpen(item: linkItem, isAnimated: isAnimated) } - + /// Opens a sheet with the specified link item and an option to animate the presentation. /// /// - Parameters: @@ -151,9 +151,9 @@ extension SingleLinkNavigator { /// - Available from iOS 15.0 and later. @available(iOS 15.0, *) private func _detentSheet(linkItem: LinkItem, isAnimated: Bool, configuration: DetentConfiguration) { - detentSheetOpen(item: linkItem, isAnimated: isAnimated, configuration: configuration) - } - + detentSheetOpen(item: linkItem, isAnimated: isAnimated, configuration: configuration) + } + /// Opens a full-screen sheet with options for animation and large titles. /// /// - Parameters: @@ -414,7 +414,7 @@ extension SingleLinkNavigator { subController = newController } } - + @available(iOS 15.0, *) public func detentSheetOpen( item: LinkItem, @@ -427,15 +427,17 @@ extension SingleLinkNavigator { rootController.dismiss(animated: true) let newController = UINavigationController() - + if let sheetPresentationController = newController.sheetPresentationController { sheetPresentationController.detents = configuration.detents sheetPresentationController.preferredCornerRadius = configuration.cornerRadius sheetPresentationController.largestUndimmedDetentIdentifier = configuration.largestUndimmedDetentIdentifier - sheetPresentationController.prefersScrollingExpandsWhenScrolledToEdge = configuration.prefersScrollingExpandsWhenScrolledToEdge + sheetPresentationController.prefersScrollingExpandsWhenScrolledToEdge = configuration + .prefersScrollingExpandsWhenScrolledToEdge sheetPresentationController.prefersGrabberVisible = configuration.prefersGrabberVisible sheetPresentationController.prefersEdgeAttachedInCompactHeight = configuration.prefersEdgeAttachedInCompactHeight - sheetPresentationController.widthFollowsPreferredContentSizeWhenEdgeAttached = configuration.widthFollowsPreferredContentSizeWhenEdgeAttached + sheetPresentationController.widthFollowsPreferredContentSizeWhenEdgeAttached = configuration + .widthFollowsPreferredContentSizeWhenEdgeAttached sheetPresentationController.selectedDetentIdentifier = configuration.selectedDetentIdentifier } @@ -444,7 +446,7 @@ extension SingleLinkNavigator { animated: false) rootController.present(newController, animated: isAnimated) - + subController = newController } } @@ -482,13 +484,13 @@ extension SingleLinkNavigator: LinkNavigatorProtocol { public func sheet(linkItem: LinkItem, isAnimated: Bool) { _sheet(linkItem: linkItem, isAnimated: isAnimated) } - + @available(iOS 15.0, *) public func detentSheet( linkItem: LinkItem, isAnimated: Bool, - configuration: DetentConfiguration - ) { + configuration: DetentConfiguration) + { _detentSheet(linkItem: linkItem, isAnimated: isAnimated, configuration: configuration) } diff --git a/Sources/LinkNavigator/Core/Protocol/LinkNavigatorProtocol.swift b/Sources/LinkNavigator/Core/Protocol/LinkNavigatorProtocol.swift index a0947b3..7f70664 100644 --- a/Sources/LinkNavigator/Core/Protocol/LinkNavigatorProtocol.swift +++ b/Sources/LinkNavigator/Core/Protocol/LinkNavigatorProtocol.swift @@ -25,7 +25,7 @@ public protocol LinkNavigatorProtocol { /// - linkItem: The link item to present. /// - isAnimated: A Boolean value that determines whether the presentation is animated. func sheet(linkItem: LinkItem, isAnimated: Bool) - + /// Presents a sheet with the given link item. /// /// - Parameters: @@ -36,11 +36,10 @@ public protocol LinkNavigatorProtocol { /// - Available from iOS 15.0 and later. @available(iOS 15.0, *) func detentSheet( - linkItem: LinkItem, - isAnimated: Bool, - configuration: DetentConfiguration - ) - + linkItem: LinkItem, + isAnimated: Bool, + configuration: DetentConfiguration) + /// Presents a full sheet with the given link item. /// /// - Parameters: diff --git a/Sources/LinkNavigator/Test/SingleLinkNavigatorMock.swift b/Sources/LinkNavigator/Test/SingleLinkNavigatorMock.swift index 9840f6f..463539b 100644 --- a/Sources/LinkNavigator/Test/SingleLinkNavigatorMock.swift +++ b/Sources/LinkNavigator/Test/SingleLinkNavigatorMock.swift @@ -118,9 +118,9 @@ extension SingleLinkNavigatorMock: LinkNavigatorProtocol { public func sheet(linkItem _: LinkItem, isAnimated _: Bool) { event.sheet += 1 } - + @available(iOS 15.0, *) - public func detentSheet(linkItem: LinkItem, isAnimated: Bool, configuration: DetentConfiguration) { + public func detentSheet(linkItem _: LinkItem, isAnimated _: Bool, configuration _: DetentConfiguration) { event.sheet += 1 }