Module Molecule update to Container
This commit is contained in:
parent
dc8910c61d
commit
03f64b0875
@ -232,4 +232,8 @@ public extension Container {
|
||||
super.reset()
|
||||
(view as? MVMCoreUIMoleculeViewProtocol)?.reset?()
|
||||
}
|
||||
|
||||
func setAsMolecule() {
|
||||
(view as? MVMCoreUIMoleculeViewProtocol)?.setAsMolecule?()
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,13 +8,20 @@
|
||||
|
||||
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 override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
moduleMolecule?.updateView(size)
|
||||
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
model = ModuleMoleculeModel()
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
@ -27,34 +34,15 @@ open class ModuleMolecule: ViewConstrainingView {
|
||||
}
|
||||
|
||||
if moduleMolecule == nil {
|
||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) {
|
||||
addSubview(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]
|
||||
}
|
||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: false) {
|
||||
addAndContain(moleculeView)
|
||||
}
|
||||
} else {
|
||||
moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
open override func setAsMolecule() {
|
||||
super.setAsMolecule()
|
||||
moduleMolecule?.setAsMolecule?()
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
moduleMolecule?.reset?()
|
||||
}
|
||||
|
||||
public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||
// Critical error
|
||||
return 0
|
||||
@ -62,7 +50,7 @@ open class ModuleMolecule: ViewConstrainingView {
|
||||
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 {
|
||||
// Critical error
|
||||
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)) + ">"
|
||||
}
|
||||
|
||||
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")
|
||||
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)) {
|
||||
@ -83,25 +71,4 @@ open class ModuleMolecule: ViewConstrainingView {
|
||||
}
|
||||
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