Module Molecule update to Container
This commit is contained in:
parent
dc8910c61d
commit
03f64b0875
@ -232,4 +232,8 @@ public extension Container {
|
|||||||
super.reset()
|
super.reset()
|
||||||
(view as? MVMCoreUIMoleculeViewProtocol)?.reset?()
|
(view as? MVMCoreUIMoleculeViewProtocol)?.reset?()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setAsMolecule() {
|
||||||
|
(view as? MVMCoreUIMoleculeViewProtocol)?.setAsMolecule?()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,13 +8,20 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
open class ModuleMolecule: ViewConstrainingView {
|
struct ModuleMoleculeModel: ContainerModelProtocol {
|
||||||
|
var horizontalAlignment: UIStackView.Alignment? = .fill
|
||||||
|
var verticalAlignment: UIStackView.Alignment? = .fill
|
||||||
|
var useHorizontalMargins: Bool? = false
|
||||||
|
var useVerticalMargins: Bool? = false
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ModuleMolecule: Container {
|
||||||
|
|
||||||
open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
|
open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
public override func setupView() {
|
||||||
super.updateView(size)
|
super.setupView()
|
||||||
moduleMolecule?.updateView(size)
|
model = ModuleMoleculeModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
@ -27,34 +34,15 @@ open class ModuleMolecule: ViewConstrainingView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if moduleMolecule == nil {
|
if moduleMolecule == nil {
|
||||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) {
|
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: false) {
|
||||||
addSubview(moleculeView)
|
addAndContain(moleculeView)
|
||||||
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
|
|
||||||
moduleMolecule = moleculeView
|
|
||||||
|
|
||||||
isAccessibilityElement = false
|
|
||||||
if moleculeView.accessibilityElements != nil {
|
|
||||||
accessibilityElements = moleculeView.accessibilityElements
|
|
||||||
} else {
|
|
||||||
accessibilityElements = [moleculeView]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
|
moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setAsMolecule() {
|
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||||
super.setAsMolecule()
|
|
||||||
moduleMolecule?.setAsMolecule?()
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func reset() {
|
|
||||||
super.reset()
|
|
||||||
moduleMolecule?.reset?()
|
|
||||||
}
|
|
||||||
|
|
||||||
public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
||||||
guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||||
// Critical error
|
// Critical error
|
||||||
return 0
|
return 0
|
||||||
@ -62,7 +50,7 @@ open class ModuleMolecule: ViewConstrainingView {
|
|||||||
return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0
|
return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public override class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||||
guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||||
// Critical error
|
// Critical error
|
||||||
return "moduleMolecule<>"
|
return "moduleMolecule<>"
|
||||||
@ -70,7 +58,7 @@ open class ModuleMolecule: ViewConstrainingView {
|
|||||||
return "moduleMolecule<" + (MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.name?(forReuse: module, delegateObject: delegateObject) ?? module.stringForkey(KeyMoleculeName)) + ">"
|
return "moduleMolecule<" + (MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.name?(forReuse: module, delegateObject: delegateObject) ?? module.stringForkey(KeyMoleculeName)) + ">"
|
||||||
}
|
}
|
||||||
|
|
||||||
public override class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||||
let moduleName = json?.optionalStringForKey("moduleName")
|
let moduleName = json?.optionalStringForKey("moduleName")
|
||||||
if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil {
|
if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil {
|
||||||
if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
||||||
@ -83,25 +71,4 @@ open class ModuleMolecule: ViewConstrainingView {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIViewConstrainingProtocol
|
|
||||||
open override func useStandardConstraints() -> Bool {
|
|
||||||
return (moduleMolecule as? MVMCoreUIViewConstrainingProtocol)?.useStandardConstraints?() ?? true
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func alignHorizontal(_ alignment: UIStackView.Alignment) {
|
|
||||||
(moduleMolecule as? MVMCoreUIViewConstrainingProtocol)?.alignHorizontal?(alignment)
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func alignVertical(_ alignment: UIStackView.Alignment) {
|
|
||||||
(moduleMolecule as? MVMCoreUIViewConstrainingProtocol)?.alignVertical?(alignment)
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func shouldSetHorizontalMargins(_ shouldSet: Bool) {
|
|
||||||
(moduleMolecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(shouldSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func shouldSetVerticalMargins(_ shouldSet: Bool) {
|
|
||||||
(moduleMolecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(shouldSet)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user