Custom Dismiss Action

#170 · closed · 1 comments

View on GitHub ↗

hadyhelal

**I have custom header view** ![Screenshot 2024-10-30 at 5 21 15 PM](https://github.com/user-attachments/assets/f6bd7a24-4c16-4e97-b3ea-0589230cc34e) I want to dismiss (not hide) the bottom sheet when click in this custom close button. I have read the documentation, but unfortunately, I couldn’t find anything that provides this customization. The .hide modifier doesn’t work well, as it doesn’t destroy the view; instead, it keeps it in its previous state. Additionally, the onDismiss { } closure doesn’t get triggered when switching to .hide. I have gone a little bit deeper into the library and found out this: ![Screenshot 2024-10-30 at 5 23 33 PM](https://github.com/user-attachments/assets/0b3a4bfa-e91c-4f3a-be13-2f7faed41012) It makes the configuration dismiss, which I think is what causes other things that totally destroy the view to get called! Unfortunately, it's an inaccessible property. **Do you have any API or configuration that could help me out?**

Comments

lucaszischka

`closeSheet()` gets called, when the BottomSheet decides to close itself. This may be the case when you use the provided close button or tap to dismiss behavior. Behavior of `closeSheet()`: 1. sets the position to hidden (what you can do yourself) 2. closes all keyboards (what you can do yourself; endEditing is not exposed, but you can copy its implementation, see below) 3. it calls the user provided additional code to execute on dismiss So if you have your own button for closing the sheet, your code looks like this: ```swift func closeSheet() { self.bottomSheetPosition = .hidden self.endEditing() // Additional code you would like to perform (previously onDismiss) } func endEditing() { #if !os(macOS) UIApplication.shared.endEditing() #endif } #if !os(macOS) import UIKit extension UIApplication { func endEditing() { sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } } #endif ``` You are suggesting that the BottomSheet library has some kind of private "destroy view" function, which is not the case.