Skip to content

Commit

Permalink
style: Auto Lint & Format
Browse files Browse the repository at this point in the history
  • Loading branch information
interactord committed Sep 23, 2024
1 parent ba51165 commit 808471e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 18 additions & 14 deletions Sources/LinkNavigator/Core/Core/DetentConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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?
}
26 changes: 14 additions & 12 deletions Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -414,7 +414,7 @@ extension SingleLinkNavigator {
subController = newController
}
}

@available(iOS 15.0, *)
public func detentSheetOpen(
item: LinkItem,
Expand All @@ -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
}

Expand All @@ -444,7 +446,7 @@ extension SingleLinkNavigator {
animated: false)

rootController.present(newController, animated: isAnimated)

subController = newController
}
}
Expand Down Expand Up @@ -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)
}

Expand Down
11 changes: 5 additions & 6 deletions Sources/LinkNavigator/Core/Protocol/LinkNavigatorProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Sources/LinkNavigator/Test/SingleLinkNavigatorMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 808471e

Please sign in to comment.