Skip to content

Commit

Permalink
Merge pull request #287 from kitwtnb/remove-dependency-on-specific-im…
Browse files Browse the repository at this point in the history
…age-request-library

Remove dependencies on specific image request library
  • Loading branch information
3lvis authored Dec 4, 2022
2 parents 2ac28e0 + 3ac333b commit 0119309
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
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 @@ -20,13 +19,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 @@ -57,8 +56,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 @@ -398,7 +397,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,19 +1,18 @@
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)
func pageViewDidTap(_ pageView: PageView)
func pageViewDidDoubleTap(_ 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

0 comments on commit 0119309

Please sign in to comment.