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

Add buttons #98

Closed
heisen273 opened this issue Feb 17, 2017 · 8 comments
Closed

Add buttons #98

heisen273 opened this issue Feb 17, 2017 · 8 comments

Comments

@heisen273
Copy link

Is there any way to add custom button? Or, for example, re-program existing "delete" button?

@oneeypi
Copy link

oneeypi commented Apr 20, 2017

put a completion-handler on the delete button would be so great!

I found a solution:

let lightbox = LightboxController(images: lightboxImages, startIndex: idx)
lightbox.headerView.deleteButton.addTarget(self, action: #selector(yourSelectorHere), for: .touchUpInside)
context?.present(lightbox, animated: true, completion: nil)`

@vitalii-tym
Copy link
Contributor

vitalii-tym commented Jun 16, 2017

My intention was to make the image preview a part of JSQMessagesViewController (which is used from several places).

So, I went this way as one more possible option to set custom actions for buttons:

  1. Extended UIControl to make it possible to assign a closure as described here: https://stackoverflow.com/a/41438789/2650588
  2. Did this
extension JSQMessagesViewController {
        ...
        // Usual Lighbox setup and configuration here
        // Change the Lightbox Delete button to look like a Share button by setting your image or text  
        ...
        lightbox.headerView.deleteButton.removeTarget(nil, action: nil, for: .allEvents) // I don't want the preview to disappear when button is tapped
        lightbox.headerView.deleteButton.addAction(for: .touchUpInside) {
            self.presentedViewController?.present(UIActivityViewController(activityItems: [chatImage], applicationActivities: nil), animated: true, completion: nil)
            // chatImage - is the image, which will be shown by Lighbox. I have only one image to show.
            // presentedViewController is used here because I prevent Lighbox from disappearing
        }
}

@vitalii-tym
Copy link
Contributor

vitalii-tym commented Jun 19, 2017

... and in case there are several images in the Lightbox, it is still possible to reach to the currently shown image and share it:

lightbox.headerView.deleteButton.removeTarget(nil, action: nil, for: .allEvents) // preventing this button from closing the lightbox controller
        lightbox.headerView.deleteButton.addAction(for: .touchUpInside) { [weak lightbox, weak self] in
            if let thePlaceViewController = self,
                let theLightbox = lightbox,
               let currentlyShownImage = theLightbox.images[theLightbox.currentPage].image {
                thePlaceViewController.presentedViewController?.present(UIActivityViewController(activityItems: [currentlyShownImage], applicationActivities: nil), animated: true, completion: nil)
            }
        } 

NOTE: at the moment the theLightbox.images[theLightbox.currentPage].image will be nil if the respective LightboxImage was inited via imageURL (i.e. the image was downloaded by Lightbox itself). But there's a PR, which is supposed to fix this: #122

@sverin
Copy link

sverin commented Sep 23, 2017

I want to add new buttons and keep both the close and delete button. How can these be achieved?

@onmyway133
Copy link
Contributor

@heisen273 @sverin Hi, sorry for late response. The design of Lightbox is to have delete and close button at the header. But you can totally do your own customisation by subclassing HeaderView https://github.com/hyperoslo/Lightbox/blob/master/Source/Views/HeaderView.swift. Hope you understand 🥂

@sverin
Copy link

sverin commented Sep 26, 2017

I know how to subclass the HeaderView, but I can't figure out how to use it since the headerView is set as fileprivate(set) in the LightboxController.

@onmyway133
Copy link
Contributor

onmyway133 commented Sep 26, 2017

@sverin Hi, the proposed changes during swift 4 migration is to exposed them as open so that they are easier to customise. You can track the progress here https://github.com/hyperoslo/Lightbox/tree/swift4, feel free to comment or review 😉

@tamoyal
Copy link

tamoyal commented Dec 6, 2017

Agree that this at least seems problematic because it looks like LightboxController does some housekeeping on close, for example:

func headerView(_ headerView: HeaderView, didPressCloseButton closeButton: UIButton) {
    closeButton.isEnabled = false
    presented = false
    dismissalDelegate?.lightboxControllerWillDismiss(self)
    dismiss(animated: true, completion: nil)
  }

so we should probably be able to hook into that, right?

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

6 participants