danielsaidi / Sheeeeeeeeet

Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement this into SwiftUI

reinaldoriant opened this issue · comments

Do you have sample to use this in SwiftUI?

Hi! No, I haven’t tried this yet, but I think it would be pretty easy to achieve.

The thing that will be the hardest to achieve as I’ve had problems with other libraries, is to get the global view to behave correctly. You’d want to put a modifier on the outermost view (NavigationView or TabView) and then setup new sheets for any new modals.

Any help on this?

I had a look at this today, and I'm not really sure how to extend this to SwiftUI. I mean, the custom action sheet would be great to have, but the context menu and alert parts are already easily available in SwiftUI.

I guess creating a SwiftUI bridge for the custom action sheet would be good, but I'm not sure when I'll have time to do it.

yeah tis the custom action sheet that I use, this for looking I have found a few other kind of similar things so will try hacking them to suit my uses

for the custom action sheet, not sure if this is what you were thinking off but I did the following

struct CustomActionSheet: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> CustomActionSheetController {
let customActionSheet = CustomActionSheetController()
customActionSheet.delegate = context.coordinator
customActionSheet.sheet = self.sheet
return customActionSheet
}

func updateUIViewController(_ uiViewController: CustomActionSheetController, context: Context) {}

typealias UIViewControllerType = CustomActionSheetController
@Binding var isShowing: Bool
var sheet: Sheeeeeeeeet.ActionSheet?

class Coordinator: NSObject, CustomActionSheetControllerDelegate {
    func actionSheetDidFinish(_ customActionSheet: CustomActionSheetController) {
        parent.isShowing = false
    }
    var parent: CustomActionSheet
    init(_ parent: CustomActionSheet) {
        self.parent = parent
    }
}

func makeCoordinator() -> Coordinator {
    Coordinator(self)
}

}

protocol CustomActionSheetControllerDelegate: AnyObject {
func actionSheetDidFinish(_ customActionSheet: CustomActionSheetController)
}

class CustomActionSheetController: UIViewController {
weak var delegate: CustomActionSheetControllerDelegate?
var sheet: Sheeeeeeeeet.ActionSheet?

override func viewDidLoad() {
    super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool) {
    sheet?.present(in: self, from: self.view) {
        self.sheet?.presenter?.events.didDismissWithBackgroundTap = { self.delegate?.actionSheetDidFinish(self) }
    }
}

}

@bukira Sorry for the slow reply. Did that work in your case?

yes this did the job for me, feel free to add to the repo if this is what you had in mind also

Wow, perfect! I will try to get around to it, but I have so many other things going on right now, that it may take a while.

np, the above works for me fine and anyone else who wants to use it, works seamlessly and perfectly, a win win

That's great, thank you. I'll keep this issue opened until the code is in the master branch.