From 273b1317145fc83d7dcdf6c1890bc5e861b906a8 Mon Sep 17 00:00:00 2001 From: Subhankar Acharya Date: Mon, 17 Feb 2020 22:50:43 +0530 Subject: [PATCH] Code commit - changes has to be done to model. --- MVMCoreUI/Atoms/Views/ImageViewModel.swift | 4 ++++ .../List/RightVariable/ListRightVariablePayments.swift | 5 +++-- .../RightVariable/ListRightVariablePaymentsModel.swift | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ImageViewModel.swift b/MVMCoreUI/Atoms/Views/ImageViewModel.swift index ce46a930..c6eb9668 100644 --- a/MVMCoreUI/Atoms/Views/ImageViewModel.swift +++ b/MVMCoreUI/Atoms/Views/ImageViewModel.swift @@ -18,4 +18,8 @@ import Foundation public var imageFormat: String? public var width: CGFloat? public var height: CGFloat? + + public init(image: String) { + self.image = image + } } diff --git a/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift index e46cc469..91703fd7 100644 --- a/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift @@ -36,6 +36,7 @@ import Foundation stack.stackItems = [StackItem(andContain: leftLabel),StackItem(andContain: rightImage)] contentView.addSubview(stack) containerHelper.constrainView(stack) + } //---------------------------------------------------- // MARK: - Molecule @@ -52,9 +53,9 @@ import Foundation rightImage.setWithModel(model.image, delegateObject, additionalData) // Create a stack model to use for the internal stack and set the alignment of label and image - let leftLabel = StackItemModel(percent: 70) + let leftLabel = StackItemModel() leftLabel.horizontalAlignment = .leading - let rightImage = StackItemModel(percent: 30) + let rightImage = StackItemModel() rightImage.horizontalAlignment = .trailing let stackModel = StackModel(molecules: [leftLabel,rightImage]) stackModel.axis = .horizontal diff --git a/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift index 23545142..422cd193 100644 --- a/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift @@ -15,11 +15,17 @@ public class ListRightVariablePaymentsModel: ListItemModel, MoleculeModelProtoco public var leftLabel: LabelModel public init(image: ImageViewModel, leftLabel: LabelModel) { - self.image = image self.leftLabel = leftLabel + self.image = image super.init() } + func createPayPalImage() -> ImageViewModel { + let image = ImageViewModel(image: "imagename_paypal") + image.width = 30.0 + return image + } + private enum CodingKeys: String, CodingKey { case moleculeName case leftLabel @@ -29,7 +35,7 @@ public class ListRightVariablePaymentsModel: ListItemModel, MoleculeModelProtoco required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) leftLabel = try typeContainer.decode(LabelModel.self, forKey: .leftLabel) - image = try typeContainer.decode(ImageViewModel.self, forKey: .image) + image = try typeContainer.decodeIfPresent(ImageViewModel.self, forKey: .image) ?? createPayPalImage() try super.init(from: decoder) }