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

Click to enlarge the Image Content? #13

Closed
2 tasks done
yo1995 opened this issue Apr 24, 2019 · 3 comments
Closed
2 tasks done

Click to enlarge the Image Content? #13

yo1995 opened this issue Apr 24, 2019 · 3 comments

Comments

@yo1995
Copy link

yo1995 commented Apr 24, 2019

Checklist

Expected Behavior

Would you like to add a tap gesture or so, so that when tapping on imageview content, the image view will zoom in or pop up in a larger view to preview?

@yo1995
Copy link
Author

yo1995 commented Apr 25, 2019

currently I embedded the Lightbox framework to it, but wonder if Carbon can provide a native method for it. 🤔

@ra1028
Copy link
Owner

ra1028 commented May 12, 2019

Hi @yo1995 ,

Carbon, like frameworks such as IGListKit, doesn't support complex features other than rendering list elements.
As you say, you can implement it by vanilla implementation or using a framework such as LightBox.
Below is the sample code for receiving events of component on view controller.

final class CustomImageView: UIImageView {
    var onPreview: ((UIImage) -> Void)?

    override func awakeFromNib() {
        super.awakeFromNib()

        let gesture = UITapGestureRecognizer(target: self, action: #selector(handlePreview))
        addGestureRecognizer(gesture)
        isUserInteractionEnabled = true
    }

    @objc func handlePreview() {
        guard let image = image else { return }
        onPreview?(image)
    }
}

struct ImageComponent: Component {
    var image: UIImage
    var onPreview: (UIImage) -> Void

    func renderContent() -> CustomImageView {
        return UIImageView()
    }

    func render(in content: CustomImageView) {
        content.image = image
        content.onPreview = onPreview
    }
}

let component = ImageComponent(image: yourImage, onPreview: { image in
    // Implement UIImage previewing
})

@yo1995
Copy link
Author

yo1995 commented May 12, 2019

Hi @yo1995 ,

Carbon, like frameworks such as IGListKit, doesn't support complex features other than rendering list elements.
As you say, you can implement it by vanilla implementation or using a framework such as LightBox.
Below is the sample code for receiving events of component on view controller.

final class CustomImageView: UIImageView {
    var onPreview: ((UIImage) -> Void)?

    override func awakeFromNib() {
        super.awakeFromNib()

        let gesture = UITapGestureRecognizer(target: self, action: #selector(handlePreview))
        addGestureRecognizer(gesture)
        isUserInteractionEnabled = true
    }

    @objc func handlePreview() {
        guard let image = image else { return }
        onPreview?(image)
    }
}

struct ImageComponent: Component {
    var image: UIImage
    var onPreview: (UIImage) -> Void

    func renderContent() -> CustomImageView {
        return UIImageView()
    }

    func render(in content: CustomImageView) {
        content.image = image
        content.onPreview = onPreview
    }
}

let component = ImageComponent(image: yourImage, onPreview: { image in
    // Implement UIImage previewing
})

Thanks for your clarification! Got it.

@yo1995 yo1995 closed this as completed May 12, 2019
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

2 participants