objc clean
This commit is contained in:
parent
3564d993e1
commit
3040629fcb
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@objcMembers public class MFLoadImageView: ViewConstrainingView {
|
@objcMembers open class MFLoadImageView: ViewConstrainingView {
|
||||||
@objc public let loadingSpinner = MFLoadingSpinner(frame: .zero)
|
public let loadingSpinner = MFLoadingSpinner(frame: .zero)
|
||||||
@objc public let imageView = MFTransparentGIFView(frame: .zero)
|
public let imageView = MFTransparentGIFView(frame: .zero)
|
||||||
@objc public var addSizeConstraintsForAspectRatio = false
|
public var addSizeConstraintsForAspectRatio = false
|
||||||
var centerX: NSLayoutConstraint?
|
var centerX: NSLayoutConstraint?
|
||||||
var centerY: NSLayoutConstraint?
|
var centerY: NSLayoutConstraint?
|
||||||
var widthConstraint: NSLayoutConstraint?
|
var widthConstraint: NSLayoutConstraint?
|
||||||
@ -19,11 +19,11 @@ import UIKit
|
|||||||
var loadingSpinnerHeightConstraint: NSLayoutConstraint?
|
var loadingSpinnerHeightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
// For keeping track of current state.
|
// For keeping track of current state.
|
||||||
private var edges: UIRectEdge?
|
var edges: UIRectEdge?
|
||||||
private var spinnerHeight: CGFloat?
|
var spinnerHeight: CGFloat?
|
||||||
private var width: CGFloat?
|
var width: CGFloat?
|
||||||
private var loadingImageName: String?
|
var loadingImageName: String?
|
||||||
private var isFallbackImage: Bool = false
|
var isFallbackImage: Bool = false
|
||||||
|
|
||||||
public init(pinnedEdges edge: UIRectEdge) {
|
public init(pinnedEdges edge: UIRectEdge) {
|
||||||
edges = edge
|
edges = edge
|
||||||
@ -31,16 +31,16 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The default is an image that is centered with no edges pinned. So it will take the size of the content and fill as needed.
|
// The default is an image that is centered with no edges pinned. So it will take the size of the content and fill as needed.
|
||||||
@objc public init() {
|
public init() {
|
||||||
edges = UIRectEdge(rawValue: 0)
|
edges = UIRectEdge(rawValue: 0)
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required public init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func pinEdges(_ edge: UIRectEdge) {
|
public func pinEdges(_ edge: UIRectEdge) {
|
||||||
edges = edge
|
edges = edge
|
||||||
if edge == UIRectEdge.all {
|
if edge == UIRectEdge.all {
|
||||||
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
|
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
|
||||||
@ -109,7 +109,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public func setupView() {
|
override open func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
guard subviews.count == 0 else {
|
guard subviews.count == 0 else {
|
||||||
return
|
return
|
||||||
@ -145,7 +145,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func defaultCompletionBlock() -> MVMCoreGetImageBlock {
|
open func defaultCompletionBlock() -> MVMCoreGetImageBlock {
|
||||||
return {image,gifData,_ in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
return {image,gifData,_ in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||||
if let image = image {
|
if let image = image {
|
||||||
self?.imageView.image = image
|
self?.imageView.image = image
|
||||||
@ -157,7 +157,7 @@ import UIKit
|
|||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func shouldLoadImage(withName imageName: String?, width: CGFloat) -> Bool {
|
open func shouldLoadImage(withName imageName: String?, width: CGFloat) -> Bool {
|
||||||
// We should load a new image if there is no current image, the image names are different, the width is different, or we are using a fallback image.
|
// We should load a new image if there is no current image, the image names are different, the width is different, or we are using a fallback image.
|
||||||
guard let currentWidth = self.width else {
|
guard let currentWidth = self.width else {
|
||||||
return true
|
return true
|
||||||
@ -191,7 +191,7 @@ import UIKit
|
|||||||
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.vertical)
|
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
let width = size.rounded()
|
let width = size.rounded()
|
||||||
if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width) {
|
if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width) {
|
||||||
@ -203,18 +203,20 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol functions
|
// MARK: - MVMCoreUIMoleculeViewProtocol functions
|
||||||
public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
|
open override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
|
||||||
super.setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
super.setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
||||||
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
||||||
}
|
}
|
||||||
if let accessibilityString = json?.optionalStringForKey("accessibilityText") {
|
if let accessibilityString = json?.optionalStringForKey("accessibilityText") {
|
||||||
imageView.accessibilityLabel = accessibilityString
|
imageView.accessibilityLabel = accessibilityString
|
||||||
|
imageView.accessibilityTraits = .staticText
|
||||||
|
imageView.isAccessibilityElement = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - load functions
|
// MARK: - load functions
|
||||||
@objc public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?, completionHandler: @escaping MVMCoreGetImageBlock) {
|
public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?, completionHandler: @escaping MVMCoreGetImageBlock) {
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
|
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
|
||||||
self.loadingImageName = imageName
|
self.loadingImageName = imageName
|
||||||
if let width = width {
|
if let width = width {
|
||||||
@ -246,7 +248,7 @@ import UIKit
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadCroppedImage(withName imageName:
|
public func loadCroppedImage(withName imageName:
|
||||||
String?, width: NSNumber?, height: NSNumber?, cropRect: CGRect, flipImage: Bool, customFallbackImage: String?) {
|
String?, width: NSNumber?, height: NSNumber?, cropRect: CGRect, flipImage: Bool, customFallbackImage: String?) {
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
|
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
|
||||||
self.loadingImageName = imageName
|
self.loadingImageName = imageName
|
||||||
@ -272,35 +274,35 @@ import UIKit
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?) {
|
public func loadImage(withName imageName: String?) {
|
||||||
loadImage(withName: imageName, format: nil, width: nil, height: nil, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: nil, width: nil, height: nil, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, width: NSNumber?) {
|
public func loadImage(withName imageName: String?, width: NSNumber?) {
|
||||||
loadImage(withName: imageName, format: nil, width: width, height: nil, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: nil, width: width, height: nil, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, height: NSNumber?) {
|
public func loadImage(withName imageName: String?, height: NSNumber?) {
|
||||||
loadImage(withName: imageName, format: nil, width: nil, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: nil, width: nil, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?) {
|
public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?) {
|
||||||
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?) {
|
public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?) {
|
||||||
loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: nil, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?) {
|
public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?) {
|
||||||
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: customFallbackImage, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: customFallbackImage, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?, completionHandler: @escaping MVMCoreGetImageBlock) {
|
public func loadImage(withName imageName: String?, width: NSNumber?, height: NSNumber?, completionHandler: @escaping MVMCoreGetImageBlock) {
|
||||||
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: nil, completionHandler: completionHandler)
|
loadImage(withName: imageName, format: nil, width: width, height: height, customFallbackImage: nil, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?) {
|
public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?) {
|
||||||
loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: customFallbackImage, completionHandler: defaultCompletionBlock())
|
loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: customFallbackImage, completionHandler: defaultCompletionBlock())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user