Skip to content

Commit

Permalink
Invoke dismiss completion when BottomSheet was dismissed programmatic…
Browse files Browse the repository at this point in the history
…ly (#37)

* Invoke dismiss completion when BottomSheet was dismissed programmaticly

* Make naming more clear

* Adjust BottomSheet documentation
  • Loading branch information
mikhailmaslo authored Jan 10, 2024
1 parent be7cbb5 commit 15ab2cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class RootViewController: UIViewController {
true
},
dismissCompletion: {
// handle dismiss completion if user closed bottom sheet by a gesture
// handle bottom sheet dismissal completion
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ presentBottomSheet(
true
},
dismissCompletion: {
// handle dismiss completion if user closed bottom sheet by a gesture
// handle bottom sheet dismissal completion
}
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public final class DefaultBottomSheetModalDismissalHandler: BottomSheetModalDism
private let _canBeDismissed: () -> Bool
private let dismissCompletion: (() -> Void)?

private var didInvokeDismissal = false

// MARK: - Init

init(
Expand All @@ -75,6 +77,14 @@ public final class DefaultBottomSheetModalDismissalHandler: BottomSheetModalDism
// User dismissed view controller by swipe-gesture, dismiss handler wasn't invoked
dismissCompletion?()
}

didInvokeDismissal = true
}

public func didEndDismissal() {
guard !didInvokeDismissal else { return }

dismissCompletion?()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public protocol BottomSheetModalDismissalHandler {
var canBeDismissed: Bool { get }

func performDismissal(animated: Bool)

func didEndDismissal()
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public final class BottomSheetPresentationController: UIPresentationController {
removeScrollTrackingIfNeeded()

state = .dismissed
dismissalHandler.didEndDismissal()
} else {
state = .presented
}
Expand Down

0 comments on commit 15ab2cf

Please sign in to comment.