objc clean
This commit is contained in:
parent
3564d993e1
commit
3040629fcb
@ -8,10 +8,10 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers public class MFLoadImageView: ViewConstrainingView {
|
||||
@objc public let loadingSpinner = MFLoadingSpinner(frame: .zero)
|
||||
@objc public let imageView = MFTransparentGIFView(frame: .zero)
|
||||
@objc public var addSizeConstraintsForAspectRatio = false
|
||||
@objcMembers open class MFLoadImageView: ViewConstrainingView {
|
||||
public let loadingSpinner = MFLoadingSpinner(frame: .zero)
|
||||
public let imageView = MFTransparentGIFView(frame: .zero)
|
||||
public var addSizeConstraintsForAspectRatio = false
|
||||
var centerX: NSLayoutConstraint?
|
||||
var centerY: NSLayoutConstraint?
|
||||
var widthConstraint: NSLayoutConstraint?
|
||||
@ -19,11 +19,11 @@ import UIKit
|
||||
var loadingSpinnerHeightConstraint: NSLayoutConstraint?
|
||||
|
||||
// For keeping track of current state.
|
||||
private var edges: UIRectEdge?
|
||||
private var spinnerHeight: CGFloat?
|
||||
private var width: CGFloat?
|
||||
private var loadingImageName: String?
|
||||
private var isFallbackImage: Bool = false
|
||||
var edges: UIRectEdge?
|
||||
var spinnerHeight: CGFloat?
|
||||
var width: CGFloat?
|
||||
var loadingImageName: String?
|
||||
var isFallbackImage: Bool = false
|
||||
|
||||
public init(pinnedEdges edge: UIRectEdge) {
|
||||
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.
|
||||
@objc public init() {
|
||||
public init() {
|
||||
edges = UIRectEdge(rawValue: 0)
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
@objc public func pinEdges(_ edge: UIRectEdge) {
|
||||
public func pinEdges(_ edge: UIRectEdge) {
|
||||
edges = edge
|
||||
if edge == UIRectEdge.all {
|
||||
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
|
||||
@ -109,7 +109,7 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
override public func setupView() {
|
||||
override open func setupView() {
|
||||
super.setupView()
|
||||
guard subviews.count == 0 else {
|
||||
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
|
||||
if let 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.
|
||||
guard let currentWidth = self.width else {
|
||||
return true
|
||||
@ -191,7 +191,7 @@ import UIKit
|
||||
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.vertical)
|
||||
}
|
||||
|
||||
public override func updateView(_ size: CGFloat) {
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
let width = size.rounded()
|
||||
if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width) {
|
||||
@ -203,18 +203,20 @@ import UIKit
|
||||
}
|
||||
|
||||
// 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)
|
||||
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
||||
}
|
||||
if let accessibilityString = json?.optionalStringForKey("accessibilityText") {
|
||||
imageView.accessibilityLabel = accessibilityString
|
||||
imageView.accessibilityTraits = .staticText
|
||||
imageView.isAccessibilityElement = true
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
self.loadingImageName = imageName
|
||||
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?) {
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
|
||||
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())
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user