container testing
This commit is contained in:
parent
6cc31113f7
commit
e5acf63e6f
@ -47,6 +47,7 @@
|
|||||||
D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */; };
|
D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */; };
|
||||||
D22D1F562204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F542204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
D22D1F562204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F542204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F552204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m */; };
|
D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F552204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m */; };
|
||||||
|
D243859923A16B1800332775 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = D243859823A16B1800332775 /* Container.swift */; };
|
||||||
D260D7B122D65BDD007E7233 /* MVMCoreUIPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
D260D7B122D65BDD007E7233 /* MVMCoreUIPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */; };
|
D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */; };
|
||||||
D260D7B622D68514007E7233 /* MVMCoreUIPagingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
D260D7B622D68514007E7233 /* MVMCoreUIPagingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
@ -245,6 +246,7 @@
|
|||||||
D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUISwitch.m; sourceTree = "<group>"; };
|
D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUISwitch.m; sourceTree = "<group>"; };
|
||||||
D22D1F542204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIStackableViewController.h; sourceTree = "<group>"; };
|
D22D1F542204CE5D0077CEC0 /* MVMCoreUIStackableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIStackableViewController.h; sourceTree = "<group>"; };
|
||||||
D22D1F552204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIStackableViewController.m; sourceTree = "<group>"; };
|
D22D1F552204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIStackableViewController.m; sourceTree = "<group>"; };
|
||||||
|
D243859823A16B1800332775 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = "<group>"; };
|
||||||
D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPageControl.h; sourceTree = "<group>"; };
|
D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPageControl.h; sourceTree = "<group>"; };
|
||||||
D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIPageControl.m; sourceTree = "<group>"; };
|
D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIPageControl.m; sourceTree = "<group>"; };
|
||||||
D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPagingProtocol.h; sourceTree = "<group>"; };
|
D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPagingProtocol.h; sourceTree = "<group>"; };
|
||||||
@ -669,6 +671,7 @@
|
|||||||
D29DF2B721E7BE79003B2FB9 /* TabBarController */,
|
D29DF2B721E7BE79003B2FB9 /* TabBarController */,
|
||||||
D29DF2B621E7BE66003B2FB9 /* SplitViewController */,
|
D29DF2B621E7BE66003B2FB9 /* SplitViewController */,
|
||||||
D2B18B93236214AD00A9AEDC /* NavigationController.swift */,
|
D2B18B93236214AD00A9AEDC /* NavigationController.swift */,
|
||||||
|
D243859823A16B1800332775 /* Container.swift */,
|
||||||
);
|
);
|
||||||
path = Containers;
|
path = Containers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1146,6 +1149,7 @@
|
|||||||
D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */,
|
D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */,
|
||||||
D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */,
|
D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */,
|
||||||
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */,
|
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */,
|
||||||
|
D243859923A16B1800332775 /* Container.swift in Sources */,
|
||||||
D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */,
|
D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */,
|
||||||
D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */,
|
D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */,
|
||||||
D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */,
|
D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */,
|
||||||
|
|||||||
197
MVMCoreUI/Containers/Container.swift
Normal file
197
MVMCoreUI/Containers/Container.swift
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
//
|
||||||
|
// Container.swift
|
||||||
|
// MVMCoreUI
|
||||||
|
//
|
||||||
|
// Created by Scott Pfeil on 12/11/19.
|
||||||
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
protocol ContainerModelProtocol {
|
||||||
|
var horizontalAlignment: UIStackView.Alignment { get set }
|
||||||
|
var verticalAlignment: UIStackView.Alignment { get set }
|
||||||
|
}
|
||||||
|
|
||||||
|
class ContainerHelper: NSObject {
|
||||||
|
var leftConstraint: NSLayoutConstraint?
|
||||||
|
var topConstraint: NSLayoutConstraint?
|
||||||
|
var bottomConstraint: NSLayoutConstraint?
|
||||||
|
var rightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
var alignCenterHorizontalConstraint: NSLayoutConstraint?
|
||||||
|
var alignCenterLeftConstraint: NSLayoutConstraint?
|
||||||
|
var alignCenterRightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
var alignCenterVerticalConstraint: NSLayoutConstraint?
|
||||||
|
var alignCenterTopConstraint: NSLayoutConstraint?
|
||||||
|
var alignCenterBottomConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
var leftLowConstraint: NSLayoutConstraint?
|
||||||
|
var topLowConstraint: NSLayoutConstraint?
|
||||||
|
var bottomLowConstraint: NSLayoutConstraint?
|
||||||
|
var rightLowConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
func constrainView(_ view: UIView) {
|
||||||
|
guard let margins = view.superview?.layoutMarginsGuide else { return }
|
||||||
|
leftConstraint = view.leftAnchor.constraint(equalTo: margins.leftAnchor)
|
||||||
|
leftConstraint?.isActive = true
|
||||||
|
|
||||||
|
topConstraint = view.topAnchor.constraint(equalTo: margins.topAnchor)
|
||||||
|
topConstraint?.isActive = true
|
||||||
|
|
||||||
|
rightConstraint = margins.rightAnchor.constraint(equalTo: view.rightAnchor)
|
||||||
|
rightConstraint?.isActive = true
|
||||||
|
|
||||||
|
bottomConstraint = margins.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||||
|
bottomConstraint?.isActive = true
|
||||||
|
|
||||||
|
alignCenterHorizontalConstraint = view.centerXAnchor.constraint(equalTo: margins.centerXAnchor)
|
||||||
|
alignCenterLeftConstraint = view.leftAnchor.constraint(greaterThanOrEqualTo: margins.leftAnchor)
|
||||||
|
alignCenterRightConstraint = margins.rightAnchor.constraint(greaterThanOrEqualTo: view.rightAnchor)
|
||||||
|
|
||||||
|
alignCenterVerticalConstraint = view.centerYAnchor.constraint(equalTo: margins.centerYAnchor)
|
||||||
|
alignCenterTopConstraint = view.topAnchor.constraint(greaterThanOrEqualTo: margins.topAnchor)
|
||||||
|
alignCenterBottomConstraint = margins.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor)
|
||||||
|
|
||||||
|
leftLowConstraint = view.leftAnchor.constraint(equalTo: margins.leftAnchor)
|
||||||
|
leftLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||||
|
leftLowConstraint?.isActive = true
|
||||||
|
|
||||||
|
topLowConstraint = view.topAnchor.constraint(equalTo: margins.topAnchor)
|
||||||
|
topLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||||
|
topLowConstraint?.isActive = true
|
||||||
|
|
||||||
|
rightLowConstraint = margins.rightAnchor.constraint(equalTo: view.rightAnchor)
|
||||||
|
rightLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||||
|
rightLowConstraint?.isActive = true
|
||||||
|
|
||||||
|
bottomLowConstraint = margins.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||||
|
bottomLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||||
|
bottomLowConstraint?.isActive = true
|
||||||
|
|
||||||
|
setAccessibility(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAccessibility(_ view: UIView) {
|
||||||
|
guard let superView = view.superview else { return }
|
||||||
|
superView.isAccessibilityElement = false
|
||||||
|
if let elements = view.accessibilityElements {
|
||||||
|
superView.accessibilityElements = elements
|
||||||
|
} else {
|
||||||
|
superView.accessibilityElements = [view]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func alignHorizontal(_ alignment: UIStackView.Alignment) {
|
||||||
|
switch alignment {
|
||||||
|
case .center:
|
||||||
|
alignCenterHorizontalConstraint?.isActive = true
|
||||||
|
alignCenterLeftConstraint?.isActive = true
|
||||||
|
alignCenterRightConstraint?.isActive = true
|
||||||
|
leftConstraint?.isActive = false
|
||||||
|
rightConstraint?.isActive = false
|
||||||
|
case .leading:
|
||||||
|
alignCenterHorizontalConstraint?.isActive = false
|
||||||
|
alignCenterLeftConstraint?.isActive = false
|
||||||
|
alignCenterRightConstraint?.isActive = true
|
||||||
|
leftConstraint?.isActive = true
|
||||||
|
rightConstraint?.isActive = false
|
||||||
|
case .trailing:
|
||||||
|
alignCenterHorizontalConstraint?.isActive = false
|
||||||
|
alignCenterLeftConstraint?.isActive = true
|
||||||
|
alignCenterRightConstraint?.isActive = false
|
||||||
|
leftConstraint?.isActive = false
|
||||||
|
rightConstraint?.isActive = true
|
||||||
|
case .fill:
|
||||||
|
alignCenterHorizontalConstraint?.isActive = false
|
||||||
|
alignCenterLeftConstraint?.isActive = false
|
||||||
|
alignCenterRightConstraint?.isActive = false
|
||||||
|
leftConstraint?.isActive = true
|
||||||
|
rightConstraint?.isActive = true
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func alignVertical(_ alignment: UIStackView.Alignment) {
|
||||||
|
switch alignment {
|
||||||
|
case .center:
|
||||||
|
alignCenterVerticalConstraint?.isActive = true
|
||||||
|
alignCenterTopConstraint?.isActive = true
|
||||||
|
alignCenterBottomConstraint?.isActive = true
|
||||||
|
topConstraint?.isActive = false
|
||||||
|
bottomConstraint?.isActive = false
|
||||||
|
case .leading:
|
||||||
|
alignCenterVerticalConstraint?.isActive = false
|
||||||
|
alignCenterTopConstraint?.isActive = false
|
||||||
|
alignCenterBottomConstraint?.isActive = true
|
||||||
|
topConstraint?.isActive = true
|
||||||
|
bottomConstraint?.isActive = false
|
||||||
|
case .trailing:
|
||||||
|
alignCenterVerticalConstraint?.isActive = false
|
||||||
|
alignCenterTopConstraint?.isActive = true
|
||||||
|
alignCenterBottomConstraint?.isActive = false
|
||||||
|
topConstraint?.isActive = false
|
||||||
|
bottomConstraint?.isActive = true
|
||||||
|
case .fill:
|
||||||
|
alignCenterVerticalConstraint?.isActive = false
|
||||||
|
alignCenterTopConstraint?.isActive = false
|
||||||
|
alignCenterBottomConstraint?.isActive = false
|
||||||
|
topConstraint?.isActive = true
|
||||||
|
bottomConstraint?.isActive = true
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func set(with model: ContainerModelProtocol) {
|
||||||
|
alignHorizontal(model.horizontalAlignment)
|
||||||
|
alignVertical(model.verticalAlignment)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func getAlignment(for string: String) -> UIStackView.Alignment? {
|
||||||
|
switch string {
|
||||||
|
case "leading":
|
||||||
|
return .leading
|
||||||
|
case "trailing":
|
||||||
|
return .trailing
|
||||||
|
case "center":
|
||||||
|
return .center
|
||||||
|
case "fill":
|
||||||
|
return .fill
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Container: View {
|
||||||
|
var model: ContainerModelProtocol?
|
||||||
|
var view: UIView?
|
||||||
|
let containerHelper = ContainerHelper()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - MVMCoreViewProtocol
|
||||||
|
extension Container {
|
||||||
|
open override func updateView(_ size: CGFloat) {
|
||||||
|
super.updateView(size)
|
||||||
|
(view as? MVMCoreViewProtocol)?.updateView(size)
|
||||||
|
MFStyler.setMarginsFor(self, size: size, defaultHorizontal: true, top: 0, bottom: 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will be called only once.
|
||||||
|
open override func setupView() {
|
||||||
|
super.setupView()
|
||||||
|
backgroundColor = .clear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
|
extension Container {
|
||||||
|
override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||||
|
if let horizontalAlignmentString = json?.optionalStringForKey("horizontalAlignment"), let alignment = ContainerHelper.getAlignment(for: horizontalAlignmentString) {
|
||||||
|
containerHelper.alignHorizontal(alignment)
|
||||||
|
} else if let alignment = (view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment {
|
||||||
|
containerHelper.alignHorizontal(alignment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,13 @@
|
|||||||
- (BOOL)needsToBeConstrained;
|
- (BOOL)needsToBeConstrained;
|
||||||
|
|
||||||
/// The alignment if constrained.
|
/// The alignment if constrained.
|
||||||
- (UIStackViewAlignment)alignment;
|
- (UIStackViewAlignment)alignment __deprecated;
|
||||||
|
|
||||||
|
/// The alignment if constrained.
|
||||||
|
- (UIStackViewAlignment)horizontalAlignment;
|
||||||
|
|
||||||
|
/// The alignment if constrained.
|
||||||
|
- (UIStackViewAlignment)verticalAlignment;
|
||||||
|
|
||||||
/// Can be used to override any standard constraints that may be added.
|
/// Can be used to override any standard constraints that may be added.
|
||||||
- (BOOL)useStandardConstraints;
|
- (BOOL)useStandardConstraints;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user