height changes minor

This commit is contained in:
Pfeil, Scott Robert 2019-08-19 13:30:50 -04:00
parent 10755d888f
commit 84ecaa9a81

View File

@ -25,8 +25,8 @@ import UIKit
var delegateObject: MVMCoreUIDelegateObject? var delegateObject: MVMCoreUIDelegateObject?
// For keeping track of current state. // For keeping track of current state.
private var edges: UIRectEdge? private var edges = UIRectEdge(rawValue: 0)
private var spinnerHeight: CGFloat? private var spinnerHeight: CGFloat = 0
private var currentImageWidth: CGFloat? private var currentImageWidth: CGFloat?
private var currentImageHeight: CGFloat? private var currentImageHeight: CGFloat?
private var currentImageName: String? private var currentImageName: String?
@ -39,7 +39,6 @@ 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.
public init() { public init() {
edges = UIRectEdge(rawValue: 0)
super.init(frame: .zero) super.init(frame: .zero)
} }
@ -93,10 +92,7 @@ import UIKit
pinView(toSuperView: imageView) pinView(toSuperView: imageView)
// Setup edges constraints // Setup edges constraints
if edges == nil { pinEdges(edges)
edges = UIRectEdge(rawValue: 0)
}
pinEdges(edges!)
// Setup spinner. // Setup spinner.
loadingSpinner.clipsToBounds = true loadingSpinner.clipsToBounds = true
@ -185,7 +181,8 @@ import UIKit
let widthWillChange = !MVMCoreGetterUtility.cgfequal(widthConstraint?.constant ?? 0, width ?? 0) let widthWillChange = !MVMCoreGetterUtility.cgfequal(widthConstraint?.constant ?? 0, width ?? 0)
let heightWillChange = !MVMCoreGetterUtility.cgfequal(heightConstraint?.constant ?? 0, height ?? 0) let heightWillChange = !MVMCoreGetterUtility.cgfequal(heightConstraint?.constant ?? 0, height ?? 0)
let sizeWillChange = (width == nil || height == nil) && !(size?.equalTo(imageView.image?.size ?? CGSize.zero) ?? false) let sizeWillChange = (width == nil || height == nil) && !(size?.equalTo(imageView.image?.size ?? CGSize.zero) ?? false)
return widthWillChange || heightWillChange || sizeWillChange let heightChangeFromSpinner = ((height ?? size?.height) ?? 0) < loadingSpinnerHeightConstraint?.constant ?? CGFloat.leastNormalMagnitude
return widthWillChange || heightWillChange || sizeWillChange || heightChangeFromSpinner
} }
// Constrains the image view to be the size provided. Used to size it to the image to fix aspect fit defect. // Constrains the image view to be the size provided. Used to size it to the image to fix aspect fit defect.
@ -252,9 +249,9 @@ import UIKit
self.currentImageName = imageName self.currentImageName = imageName
self.currentImageWidth = width?.cgfloat() self.currentImageWidth = width?.cgfloat()
self.currentImageHeight = height?.cgfloat() self.currentImageHeight = height?.cgfloat()
self.loadingSpinner.resumeSpinnerAfterDelay() if MVMCoreCache.isHostedImage(imageName) {
if let height = self.spinnerHeight { self.loadingSpinner.resumeSpinnerAfterDelay()
self.loadingSpinnerHeightConstraint?.constant = height self.loadingSpinnerHeightConstraint?.constant = self.spinnerHeight
} }
let finishedLoadingBlock: MVMCoreGetImageBlock = {[weak self] (image, data, isFallbackImage) in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in let finishedLoadingBlock: MVMCoreGetImageBlock = {[weak self] (image, data, isFallbackImage) in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
@ -262,10 +259,10 @@ import UIKit
return return
} }
self?.isFallbackImage = isFallbackImage self?.isFallbackImage = isFallbackImage
self?.loadingSpinnerHeightConstraint?.constant = 0
self?.loadingSpinner.pause() self?.loadingSpinner.pause()
let layoutWillChange = self?.layoutWillChange(width: self?.currentImageWidth, height: self?.currentImageHeight, size: image?.size) ?? false let layoutWillChange = self?.layoutWillChange(width: self?.currentImageWidth, height: self?.currentImageHeight, size: image?.size) ?? false
self?.addConstraints(width: width, height: height, size: image?.size) self?.addConstraints(width: width, height: height, size: image?.size)
self?.loadingSpinnerHeightConstraint?.constant = 0
if layoutWillChange { if layoutWillChange {
self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!) self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!)
} }
@ -287,9 +284,8 @@ import UIKit
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in
self.currentImageName = imageName self.currentImageName = imageName
self.loadingSpinner.resumeSpinnerAfterDelay() self.loadingSpinner.resumeSpinnerAfterDelay()
if let height = self.spinnerHeight { self.loadingSpinnerHeightConstraint?.constant = self.spinnerHeight
self.loadingSpinnerHeightConstraint?.constant = height
}
MVMCoreCache.shared()?.getCroppedImage(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, finalRect: cropRect, flipImage: flipImage, localFallbackImageName: customFallbackImage ?? MVMCoreUIUtility.localizedImageName("fallback"), completionHandler: { [weak self] (image, data, isFallBackImage) in MVMCoreCache.shared()?.getCroppedImage(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, finalRect: cropRect, flipImage: flipImage, localFallbackImageName: customFallbackImage ?? MVMCoreUIUtility.localizedImageName("fallback"), completionHandler: { [weak self] (image, data, isFallBackImage) in
MVMCoreDispatchUtility.performBlock(onMainThread: { MVMCoreDispatchUtility.performBlock(onMainThread: {
guard let image = image, let loadingImageName = self?.currentImageName, loadingImageName == imageName else { guard let image = image, let loadingImageName = self?.currentImageName, loadingImageName == imageName else {