Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement this into SwiftUI #151

Open
reinaldoriant opened this issue Aug 24, 2021 · 10 comments
Open

Implement this into SwiftUI #151

reinaldoriant opened this issue Aug 24, 2021 · 10 comments

Comments

@reinaldoriant
Copy link

Do you have sample to use this in SwiftUI?

@danielsaidi
Copy link
Owner

danielsaidi commented Aug 24, 2021

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
Copy link

bukira commented Dec 3, 2021

Any help on this?

@danielsaidi
Copy link
Owner

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
Copy link

bukira commented Dec 8, 2021

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
Copy link

bukira commented Dec 10, 2021

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
Copy link
Owner

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

@bukira
Copy link

bukira commented Jan 5, 2022

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

@danielsaidi
Copy link
Owner

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
Copy link

bukira commented Jan 5, 2022

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

@danielsaidi
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants