danielsaidi / Sheeeeeeeeet

Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.
MIT License
1.72k stars 109 forks source link

Implement this into SwiftUI #151

Open reinaldoriant opened 3 years ago

reinaldoriant commented 3 years ago

Do you have sample to use this in SwiftUI?

danielsaidi commented 3 years ago

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.

bukira commented 2 years ago

Any help on this?

danielsaidi commented 2 years ago

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.

bukira commented 2 years ago

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

bukira commented 2 years ago

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) }
    }
}

}

danielsaidi commented 2 years ago

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

bukira commented 2 years ago

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

danielsaidi commented 2 years ago

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.

bukira commented 2 years ago

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

danielsaidi commented 2 years ago

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