Code Monkey home page Code Monkey logo

jfherobrowser's Introduction

JFHeroBrowser

Version License Platform Language

Usage

JFHeroBrowser is not include any network image cache framework(like Kingfisher or SDWebImage). So first step, you should implement NetworkImageProvider Protocol func downloadImage().

example use Kingfisher


extension HeroNetworkImageProvider: NetworkImageProvider {
    func downloadImage(with imgUrl: String, complete: Complete<UIImage>?) {
        KingfisherManager.shared.retrieveImage(with: URL(string: imgUrl)!, options: nil) { receiveSize, totalSize in
            guard totalSize > 0 else { return }
            let progress:CGFloat = CGFloat(CGFloat(receiveSize) / CGFloat(totalSize))
            complete?(.progress(progress))
        } downloadTaskUpdated: { task in

        } completionHandler: { result in
            switch result {
            case .success(let loadingImageResult):
                complete?(.success(loadingImageResult.image))
                break
            case .failure(let error):
                complete?(.failed(error))
                break
            }
        }
    }
}

class HeroNetworkImageProvider: NSObject {
    @objc static let shared = HeroNetworkImageProvider()
}

And then setup Global Config in App DidFinish.


JFHeroBrowserGlobalConfig.default.networkImageProvider = HeroNetworkImageProvider.shared

Finally, enjoy JFHeroBrowser.

example code browser a photo list.


var list: [HeroBrowserViewModule] = []
        for i in 0..<origins.count {
            list.append(HeroBrowserNetworkImageViewModule(thumbailImgUrl: thumbs[i], originImgUrl: origins[i]))
        }
        self.hero.browserPhoto(viewModules: list, initIndex: button.tag - 1) {
            [
                .heroView(button.imageView),
                .imageDidChangeHandle({ [weak self] imageIndex in
                    guard let self = self else { return nil }
                    guard let btn = self.view.viewWithTag(imageIndex + 1) as? UIButton else { return nil }
                    return btn.imageView
                }),
            ]
        }

Installation

CocoasPods

JFHeroBrowser is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'JFHeroBrowser', '1.2.0'

Change Log

  • v1.0.0 support image (data、UIImage、netowrk image) source & video(local file & network url video) source

  • v1.1.0 supoort 'Hero' namespace, add twd quick browser func (browserPhoto & browserVideo)

  • v1.2.0 support Horizontal Screen & auto rotate && adapt UI in Horizontal Screen

  • v1.3.3 fix iOS16 screen rotate update view frame invalid

  • v1.4.0 Support iPad OS

  • v1.4.1 fix image scale issue

Author

JerryFans, [email protected]

License

JFHeroBrowser is available under the MIT license. See the LICENSE file for more info.

jfherobrowser's People

Contributors

hstdt avatar jerryfans avatar whtoo avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.