Sheeeeeeeeet icon indicating copy to clipboard operation
Sheeeeeeeeet copied to clipboard

Implement this into SwiftUI

Open reinaldoriant opened this issue 3 years ago • 10 comments

Do you have sample to use this in SwiftUI?

reinaldoriant avatar Aug 24 '21 02:08 reinaldoriant

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.

danielsaidi avatar Aug 24 '21 05:08 danielsaidi

Any help on this?

bukira avatar Dec 03 '21 10:12 bukira

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.

danielsaidi avatar Dec 07 '21 08:12 danielsaidi

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 avatar Dec 08 '21 11:12 bukira

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 avatar Dec 10 '21 10:12 bukira

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

danielsaidi avatar Jan 05 '22 11:01 danielsaidi

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

bukira avatar Jan 05 '22 11:01 bukira

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.

danielsaidi avatar Jan 05 '22 12:01 danielsaidi

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

bukira avatar Jan 05 '22 12:01 bukira

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

danielsaidi avatar Jan 07 '22 07:01 danielsaidi