Skip to content

Commit

Permalink
Add convenience for presentation with navigation controller. Document…
Browse files Browse the repository at this point in the history
… new parameters (#24)

* Add convenience to navigation controller. Add new parameters to the demo

* Add docs for new customizations

* Invoke `dismissCompletion` when user dismissed bottom sheet by interactive gesture
  • Loading branch information
mikhailmaslo authored Jul 13, 2023
1 parent c0fd663 commit fcad2cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ final class RootViewController: UIViewController {
let viewController = ResizeViewController(initialHeight: 300)
presentBottomSheetInsideNavigationController(
viewController: viewController,
configuration: .default
configuration: .default,
canBeDismissed: {
// return `true` or `false` based on your business logic
true
},
dismissCompletion: {
// handle dismiss completion if user closed bottom sheet by a gesture
}
)
}
}
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ presentBottomSheet(
cornerRadius: 10,
pullBarConfiguration: .visible(.init(height: 20)),
shadowConfiguration: .init(backgroundColor: UIColor.black.withAlphaComponent(0.6))
)
),
canBeDismissed: {
// return `true` or `false` based on your business logic
true
},
dismissCompletion: {
// handle dismiss completion if user closed bottom sheet by a gesture
}
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public final class DefaultBottomSheetModalDismissalHandler: BottomSheetModalDism
}

public func performDismissal(animated: Bool) {
presentingViewController?.presentedViewController?.dismiss(animated: animated, completion: dismissCompletion)
if let presentedViewController = presentingViewController {
presentedViewController.dismiss(animated: animated, completion: dismissCompletion)
} else {
// User dismissed view controller by swipe-gesture, dismiss handler wasn't invoked
dismissCompletion?()
}
}
}

Expand Down Expand Up @@ -106,8 +111,18 @@ public extension UIViewController {
present(viewController, animated: true, completion: nil)
}

func presentBottomSheetInsideNavigationController(viewController: UIViewController, configuration: BottomSheetConfiguration) {
func presentBottomSheetInsideNavigationController(
viewController: UIViewController,
configuration: BottomSheetConfiguration,
canBeDismissed: @escaping (() -> Bool) = { true },
dismissCompletion: (() -> Void)? = nil
) {
let navigationController = BottomSheetNavigationController(rootViewController: viewController, configuration: configuration)
presentBottomSheet(viewController: navigationController, configuration: configuration)
presentBottomSheet(
viewController: navigationController,
configuration: configuration,
canBeDismissed: canBeDismissed,
dismissCompletion: dismissCompletion
)
}
}

0 comments on commit fcad2cf

Please sign in to comment.