sync properties
also ensured same properties were in Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e25a0cadc1
commit
ce8b5b85cb
@ -51,19 +51,12 @@ open class TileContainer: VDS.TileContainer, VDSMoleculeViewProtocol{
|
||||
}
|
||||
}
|
||||
|
||||
// set backgroundImage
|
||||
if let imageName = viewModel.backgroundImage {
|
||||
loadImage(imageName)
|
||||
}
|
||||
|
||||
padding = viewModel.padding
|
||||
color = viewModel.color
|
||||
backgroundEffect = viewModel.backgroundEffect
|
||||
aspectRatio = viewModel.aspectRatio
|
||||
width = viewModel.width
|
||||
height = viewModel.height
|
||||
showBorder = viewModel.showBorder
|
||||
showDropShadows = viewModel.showDropShadwows
|
||||
//setup action
|
||||
//set action
|
||||
if let action = viewModel.action {
|
||||
//add the subscriber
|
||||
onClick = { [weak self] control in
|
||||
@ -74,6 +67,18 @@ open class TileContainer: VDS.TileContainer, VDSMoleculeViewProtocol{
|
||||
delegateObject: self.delegateObject)
|
||||
}
|
||||
}
|
||||
|
||||
//set the rest of the properties
|
||||
surface = viewModel.surface
|
||||
imageFallbackColor = viewModel.imageFallbackColor
|
||||
width = viewModel.width
|
||||
height = viewModel.height
|
||||
showBorder = viewModel.showBorder
|
||||
showDropShadow = viewModel.showDropShadow
|
||||
padding = viewModel.padding
|
||||
color = viewModel.color
|
||||
aspectRatio = viewModel.aspectRatio
|
||||
backgroundEffect = viewModel.backgroundEffect
|
||||
}
|
||||
|
||||
private func loadImage(_ imageName: String? = nil) {
|
||||
|
||||
@ -55,37 +55,44 @@ open class TileContainerBaseModel<PaddingType: DefaultValuing & Codable, TileCon
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
public var inverted: Bool = false
|
||||
public var backgroundImage: String?
|
||||
public var action: ActionModelProtocol?
|
||||
public var imageFallbackColor: Surface = .light
|
||||
public var width: CGFloat?
|
||||
public var height: CGFloat?
|
||||
public var showBorder: Bool = false
|
||||
public var showDropShadwows: Bool = false
|
||||
public var showDropShadow: Bool = false
|
||||
public var padding = PaddingType.defaultValue
|
||||
public var color: TileContainerType.BackgroundColor = .black
|
||||
public var aspectRatio: TileContainerType.AspectRatio = .ratio1x1
|
||||
public var backgroundEffect: TileContainerType.BackgroundEffect = .none
|
||||
|
||||
public var surface: Surface { inverted ? .dark : .light }
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case inverted
|
||||
case backgroundImage
|
||||
case action
|
||||
case padding
|
||||
case color
|
||||
case aspectRatio
|
||||
case imageFallbackColor
|
||||
case width
|
||||
case height
|
||||
case showBorder
|
||||
case showDropShadows
|
||||
case showDropShadow
|
||||
case padding
|
||||
case color
|
||||
case aspectRatio
|
||||
case backgroundEffect
|
||||
}
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
inverted = try container.decodeIfPresent(Bool.self, forKey: .inverted) ?? false
|
||||
backgroundImage = try container.decodeIfPresent(String.self, forKey: .backgroundImage)
|
||||
action = try container.decodeModelIfPresent(codingKey: .action)
|
||||
imageFallbackColor = try container.decodeIfPresent(VDS.Surface.self, forKey: .imageFallbackColor) ?? .light
|
||||
width = try container.decodeIfPresent(CGFloat.self, forKey: .width)
|
||||
height = try container.decodeIfPresent(CGFloat.self, forKey: .height)
|
||||
action = try container.decodeModelIfPresent(codingKey: .action)
|
||||
showBorder = try container.decodeIfPresent(Bool.self, forKey: .showBorder) ?? false
|
||||
showDropShadow = try container.decodeIfPresent(Bool.self, forKey: .showDropShadow) ?? false
|
||||
padding = try container.decodeIfPresent(PaddingType.self, forKey: .padding) ?? PaddingType.defaultValue
|
||||
color = try container.decodeIfPresent(TileContainerType.BackgroundColor.self, forKey: .color) ?? .black
|
||||
aspectRatio = try container.decodeIfPresent(TileContainerType.AspectRatio.self, forKey: .aspectRatio) ?? .ratio1x1
|
||||
@ -96,12 +103,15 @@ open class TileContainerBaseModel<PaddingType: DefaultValuing & Codable, TileCon
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(backgroundImage, forKey: .backgroundImage)
|
||||
try container.encodeModelIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(imageFallbackColor, forKey: .imageFallbackColor)
|
||||
try container.encodeIfPresent(width, forKey: .width)
|
||||
try container.encodeIfPresent(height, forKey: .height)
|
||||
try container.encodeIfPresent(backgroundEffect, forKey: .backgroundEffect)
|
||||
try container.encodeIfPresent(showBorder, forKey: .showBorder)
|
||||
try container.encodeIfPresent(showDropShadow, forKey: .showDropShadow)
|
||||
try container.encodeIfPresent(padding, forKey: .padding)
|
||||
try container.encodeIfPresent(color, forKey: .color)
|
||||
try container.encodeIfPresent(aspectRatio, forKey: .aspectRatio)
|
||||
try container.encodeModelIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(backgroundEffect, forKey: .backgroundEffect)
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,16 +39,7 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
|
||||
// MARK: - Public
|
||||
//--------------------------------------------------
|
||||
public func viewModelDidUpdate() {
|
||||
|
||||
padding = viewModel.padding
|
||||
color = viewModel.color
|
||||
backgroundEffect = viewModel.backgroundEffect
|
||||
aspectRatio = viewModel.aspectRatio
|
||||
width = viewModel.width
|
||||
height = viewModel.height
|
||||
showBorder = viewModel.showBorder
|
||||
showDropShadows = viewModel.showDropShadwows
|
||||
|
||||
//tilelet specific properties
|
||||
if let value = viewModel.textWidth {
|
||||
textWidth = .value(value)
|
||||
} else if let percentage = viewModel.textPercentage {
|
||||
@ -70,6 +61,51 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
|
||||
delegateObject: self.delegateObject)
|
||||
}
|
||||
}
|
||||
|
||||
// TileContainer properties
|
||||
// set backgroundImage
|
||||
if let imageName = viewModel.backgroundImage {
|
||||
loadImage(imageName)
|
||||
}
|
||||
|
||||
//set action
|
||||
if let action = viewModel.action {
|
||||
//add the subscriber
|
||||
onClick = { [weak self] control in
|
||||
guard let self, let viewModel = self.viewModel else { return }
|
||||
MVMCoreUIActionHandler.performActionUnstructured(with: action,
|
||||
sourceModel: viewModel,
|
||||
additionalData: self.additionalData,
|
||||
delegateObject: self.delegateObject)
|
||||
}
|
||||
}
|
||||
|
||||
//set the rest of the properties
|
||||
surface = viewModel.surface
|
||||
imageFallbackColor = viewModel.imageFallbackColor
|
||||
width = viewModel.width
|
||||
height = viewModel.height
|
||||
showBorder = viewModel.showBorder
|
||||
showDropShadow = viewModel.showDropShadow
|
||||
padding = viewModel.padding
|
||||
color = viewModel.color
|
||||
aspectRatio = viewModel.aspectRatio
|
||||
backgroundEffect = viewModel.backgroundEffect
|
||||
}
|
||||
|
||||
private func loadImage(_ imageName: String? = nil) {
|
||||
guard let imageName else {
|
||||
if backgroundImage != nil {
|
||||
backgroundImage = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let finishedLoadingBlock: MVMCoreGetImageBlock = {[weak self] (image, data, isFallbackImage) in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.backgroundImage = image
|
||||
})}
|
||||
MVMCoreCache.shared()?.getImage(imageName, useWidth: false, widthForS7: 0, useHeight: false, heightForS7: 0, format: nil, localFallbackImageName: nil, allowServerQueryParameters: false, localBundle: nil, completionHandler: finishedLoadingBlock)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user