image molecule protocol

This commit is contained in:
Pfeil, Scott Robert 2019-03-19 17:08:26 -04:00
parent 680f8fc4aa
commit 3564d993e1
3 changed files with 25 additions and 0 deletions

View File

@ -191,6 +191,28 @@ import UIKit
imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.vertical)
}
public override func updateView(_ size: CGFloat) {
super.updateView(size)
let width = size.rounded()
if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width) {
imageView.image = nil
imageView.animatedImage = nil
loadImage(withName: imageName, format: json?.optionalStringForKey("imageFormat"), width: NSNumber(value: Double(width)), height: nil)
loadImage(withName: imageName, format: json?.optionalStringForKey("imageFormat"), width: NSNumber(value: Double(width)), height: nil, customFallbackImage: json?.optionalStringForKey("fallbackImage"))
}
}
// MARK: - MVMCoreUIMoleculeViewProtocol functions
public 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
}
}
// MARK: - load functions
@objc public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?, completionHandler: @escaping MVMCoreGetImageBlock) {
MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in

View File

@ -12,6 +12,8 @@
@interface MFView : UIView <MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol>
@property (nullable, nonatomic, strong) NSDictionary *json;
// Called in the initialization functions. Can setup ui here.
- (void)setupView;

View File

@ -44,6 +44,7 @@
#pragma mark - MVMCoreUIMoleculeViewProtocol
- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData {
self.json = json;
}
@end