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

Remove dependencies on specific image request library #287

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lightbox.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Pod::Spec.new do |s|
s.ios.resource = 'Resources/Lightbox.bundle'

s.frameworks = 'UIKit', 'AVFoundation', 'AVKit'
s.dependency 'SDWebImage'
s.swift_version = '5.0'

end
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ let package = Package(
name: "Lightbox",
targets: ["Lightbox"]),
],
dependencies: [
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
],
dependencies: [],
targets: [
.target(
name: "Lightbox",
dependencies: ["SDWebImage"],
dependencies: [],
path: "Source"
)
],
Expand Down
9 changes: 1 addition & 8 deletions Source/LightboxConfig.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UIKit
import AVKit
import AVFoundation
import SDWebImage

public class LightboxConfig {
/// Whether to show status bar while Lightbox is presented
Expand All @@ -18,13 +17,7 @@ public class LightboxConfig {
}

/// How to load image onto SDAnimatedImageView
public static var loadImage: (SDAnimatedImageView, URL, ((UIImage?) -> Void)?) -> Void = { (imageView, imageURL, completion) in

// Use SDWebImage by default
imageView.sd_setImage(with: imageURL) { image, error, _ , _ in
completion?(image)
}
}
public static var loadImage: ((UIImageView, URL, ((UIImage?) -> Void)?) -> Void)?

/// Indicator is used to show while image is being fetched
public static var makeLoadingIndicator: () -> UIView = {
Expand Down
7 changes: 3 additions & 4 deletions Source/LightboxController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UIKit
import SDWebImage

public protocol LightboxControllerPageDelegate: AnyObject {

Expand Down Expand Up @@ -45,8 +44,8 @@ open class LightboxController: UIViewController {
return view
}()

lazy var backgroundView: SDAnimatedImageView = {
let view = SDAnimatedImageView()
lazy var backgroundView: UIImageView = {
let view = UIImageView()
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

return view
Expand Down Expand Up @@ -384,7 +383,7 @@ extension LightboxController: UIScrollViewDelegate {

extension LightboxController: PageViewDelegate {

func remoteImageDidLoad(_ image: UIImage?, imageView: SDAnimatedImageView) {
func remoteImageDidLoad(_ image: UIImage?, imageView: UIImageView) {
guard let image = image, dynamicBackground else {
return
}
Expand Down
12 changes: 9 additions & 3 deletions Source/LightboxImage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UIKit
import SDWebImage

open class LightboxImage {

Expand Down Expand Up @@ -33,12 +32,19 @@ open class LightboxImage {
self.videoURL = videoURL
}

open func addImageTo(_ imageView: SDAnimatedImageView, completion: ((UIImage?) -> Void)? = nil) {
open func addImageTo(_ imageView: UIImageView, completion: ((UIImage?) -> Void)? = nil) {
if let image = image {
imageView.image = image
completion?(image)
} else if let imageURL = imageURL {
LightboxConfig.loadImage(imageView, imageURL, completion)
guard let loadImage = LightboxConfig.loadImage else {
print("Lightbox: To use `imageURL`, you must use `LightboxConfig.loadImage`.")
imageView.image = nil
completion?(nil)
return
}

loadImage(imageView, imageURL, completion)
} else if let imageClosure = imageClosure {
let img = imageClosure()
imageView.image = img
Expand Down
7 changes: 3 additions & 4 deletions Source/Views/PageView.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import UIKit
import SDWebImage

protocol PageViewDelegate: AnyObject {

func pageViewDidZoom(_ pageView: PageView)
func remoteImageDidLoad(_ image: UIImage?, imageView: SDAnimatedImageView)
func remoteImageDidLoad(_ image: UIImage?, imageView: UIImageView)
func pageView(_ pageView: PageView, didTouchPlayButton videoURL: URL)
func pageViewDidTouch(_ pageView: PageView)
}

class PageView: UIScrollView {

lazy var imageView: SDAnimatedImageView = {
let imageView = SDAnimatedImageView()
lazy var imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.isUserInteractionEnabled = true
Expand Down
6 changes: 6 additions & 0 deletions iOSDemo/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import Lightbox
import SDWebImage

class ViewController: UIViewController {

Expand All @@ -23,6 +24,11 @@ class ViewController: UIViewController {
view.addSubview(showButton)
title = "Lightbox"
LightboxConfig.preload = 2
LightboxConfig.loadImage = { imageView, url, completion in
imageView.sd_setImage(with: url) { image, _, _ , _ in
completion?(image)
}
}
}

// MARK: - Action methods
Expand Down