separator
keys clean up
This commit is contained in:
parent
302a2f887f
commit
2d73f89fd4
@ -21,7 +21,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
private var topViewBottomConstraint: NSLayoutConstraint?
|
||||
private var bottomViewTopConstraint: NSLayoutConstraint?
|
||||
|
||||
//MARK:-MVMCoreViewProtocol
|
||||
//MARK: - MVMCoreViewProtocol
|
||||
open override func updateViews() {
|
||||
super.updateViews()
|
||||
let width = view.bounds.width
|
||||
@ -37,7 +37,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
self.tableView?.reloadData()
|
||||
}
|
||||
|
||||
//MARK:-MFViewController
|
||||
//MARK: - MFViewController
|
||||
open override func newDataBuildScreen() {
|
||||
super.newDataBuildScreen()
|
||||
createViewForTableHeader()
|
||||
@ -51,7 +51,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
//MARK:-Spacing
|
||||
//MARK: - Spacing
|
||||
// If both are subclassed to return a value, then the buttons will not be pinned towards the bottom because neither spacing would try to fill the screen.
|
||||
/// Space between the top view and the table sections, nil to fill. 0 default
|
||||
open func spaceBelowTopView() -> CGFloat? {
|
||||
@ -127,7 +127,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK:-Header Footer
|
||||
//MARK: - Header Footer
|
||||
/// Gets the top view and adds it to a spacing view, headerView, and then calls showHeader.
|
||||
open func createViewForTableHeader() {
|
||||
let topView = viewForTop()
|
||||
@ -215,7 +215,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK:-Functions to subclass
|
||||
//MARK: - Functions to subclass
|
||||
/// Subclass for a top view.
|
||||
open func viewForTop() -> UIView {
|
||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
||||
@ -230,7 +230,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
return view
|
||||
}
|
||||
|
||||
//MARK:-Scrollview
|
||||
//MARK: - Scrollview
|
||||
open override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
// To stop handscroll animation if animating after scroll
|
||||
stopHandScrollAnimation(true)
|
||||
@ -240,7 +240,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
|
||||
tableView?.delegate = nil
|
||||
}
|
||||
|
||||
//MARK:-Animation
|
||||
//MARK: - Animation
|
||||
open override func setupIntroAnimations() {
|
||||
if let topView = topView, topView.subviews.count > 0 {
|
||||
introAnimationManager?.addAnimation(animation: MVMAnimations.fadeUpAnimation(view: topView))
|
||||
|
||||
@ -13,6 +13,7 @@ public class MoleculeStackView: MFView {
|
||||
var moleculesArray: [UIView]?
|
||||
var useMargins: Bool = false
|
||||
|
||||
// MARK: - Inits
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
@ -31,6 +32,7 @@ public class MoleculeStackView: MFView {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: - MFViewProtocol
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
@ -48,9 +50,10 @@ public class MoleculeStackView: MFView {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
guard let molecules = json?.arrayForKey("molecules") as? [[String: Any]] else {
|
||||
guard let molecules = json?.arrayForKey(KeyMolecules) as? [[String: Any]] else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,24 @@
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class MoleculeTableViewCell: UITableViewCell, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
|
||||
open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
|
||||
|
||||
// For the accessory view convenience.
|
||||
public var caretView: CaretView?
|
||||
private var caretViewWidthSizeObject: MFSizeObject?
|
||||
private var caretViewHeightSizeObject: MFSizeObject?
|
||||
|
||||
// For separation between cells.
|
||||
public var topSeparatorView: SeparatorView?
|
||||
public var bottomSeparatorView: SeparatorView?
|
||||
public enum SeparatorFrequency: String {
|
||||
case All = "all"
|
||||
case AllExceptTop = "allExceptTop"
|
||||
case AllExceptBottom = "allExceptBottom"
|
||||
case Between = "between"
|
||||
}
|
||||
|
||||
// MARK: - Inits
|
||||
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
setupView()
|
||||
@ -21,17 +37,17 @@ import UIKit
|
||||
setupView()
|
||||
}
|
||||
|
||||
// For the accessory view convenience.
|
||||
var caretView: CaretView?
|
||||
private var caretViewWidthSizeObject: MFSizeObject?
|
||||
private var caretViewHeightSizeObject: MFSizeObject?
|
||||
|
||||
// MARK: - MFViewProtocol
|
||||
public func updateView(_ size: CGFloat) {
|
||||
MFStyler.setDefaultMarginsFor(self, size: size)
|
||||
if #available(iOS 11.0, *) {
|
||||
contentView.directionalLayoutMargins = directionalLayoutMargins
|
||||
topSeparatorView?.setLeftAndRightPinConstant(directionalLayoutMargins.leading)
|
||||
bottomSeparatorView?.setLeftAndRightPinConstant(directionalLayoutMargins.leading)
|
||||
} else {
|
||||
contentView.layoutMargins = layoutMargins
|
||||
topSeparatorView?.setLeftAndRightPinConstant(layoutMargins.left)
|
||||
bottomSeparatorView?.setLeftAndRightPinConstant(layoutMargins.left)
|
||||
}
|
||||
|
||||
if let molecule = molecule as? MVMCoreViewProtocol {
|
||||
@ -40,6 +56,8 @@ import UIKit
|
||||
if let _ = accessoryView, let caretView = caretView, let widthObject = caretViewWidthSizeObject, let heightObject = caretViewHeightSizeObject {
|
||||
caretView.frame = CGRect(x: 0, y: 0, width: widthObject.getValueBased(onSize: size), height: heightObject.getValueBased(onSize: size))
|
||||
}
|
||||
topSeparatorView?.updateView(size)
|
||||
bottomSeparatorView?.updateView(size)
|
||||
}
|
||||
|
||||
public func setupView() {
|
||||
@ -48,6 +66,7 @@ import UIKit
|
||||
selectionStyle = .none
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
guard let json = json else {
|
||||
return
|
||||
@ -64,7 +83,8 @@ import UIKit
|
||||
backgroundColor = molecule?.backgroundColor
|
||||
}
|
||||
|
||||
// MARK- Convenience
|
||||
// MARK: - Convenience
|
||||
/// Adds the standard mvm style caret to the accessory view
|
||||
public func addCaretViewAccessory() {
|
||||
guard accessoryView == nil else {
|
||||
return
|
||||
@ -77,4 +97,56 @@ import UIKit
|
||||
caretViewHeightSizeObject = MFSizeObject(scalingStandardSize: height)
|
||||
accessoryView = caretView
|
||||
}
|
||||
|
||||
func addSeparatorsIfNeeded() {
|
||||
if topSeparatorView == nil {
|
||||
topSeparatorView = SeparatorView.separatorAdd(to: self, position: SeparatorPositionTop)
|
||||
topSeparatorView?.hide()
|
||||
}
|
||||
if bottomSeparatorView == nil {
|
||||
bottomSeparatorView = SeparatorView.separatorAdd(to: self, position: SeparatorPositionBot)
|
||||
bottomSeparatorView?.hide()
|
||||
}
|
||||
}
|
||||
|
||||
/// For when the separator between cells shows using json and frequency.
|
||||
public func setSeparatorWithJSON(_ json: [AnyHashable : Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?, indexPath: IndexPath) {
|
||||
guard let json = json else {
|
||||
return
|
||||
}
|
||||
addSeparatorsIfNeeded()
|
||||
topSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
bottomSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
if let separatorFrequencyString = json.optionalStringForKey("frequency"), let separatorFrequency = SeparatorFrequency(rawValue: separatorFrequencyString) {
|
||||
setSeparatorFrequency(separatorFrequency, indexPath: indexPath)
|
||||
}
|
||||
}
|
||||
|
||||
/// For when the separator between cells shows.
|
||||
public func setSeparatorFrequency(_ separatorFrequency: SeparatorFrequency, indexPath: IndexPath) {
|
||||
switch separatorFrequency {
|
||||
case .All:
|
||||
if indexPath.row == 0 {
|
||||
topSeparatorView?.show()
|
||||
} else {
|
||||
topSeparatorView?.hide()
|
||||
}
|
||||
bottomSeparatorView?.show()
|
||||
case .AllExceptBottom:
|
||||
topSeparatorView?.show()
|
||||
bottomSeparatorView?.hide()
|
||||
case .Between:
|
||||
if indexPath.row == 0 {
|
||||
topSeparatorView?.hide()
|
||||
} else {
|
||||
topSeparatorView?.show()
|
||||
}
|
||||
bottomSeparatorView?.hide()
|
||||
case .AllExceptTop:
|
||||
fallthrough
|
||||
default:
|
||||
topSeparatorView?.hide()
|
||||
bottomSeparatorView?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
}
|
||||
|
||||
- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)getMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
NSString *moleculeName = [json string:@"moleculeName"];
|
||||
NSString *moleculeName = [json string:KeyMoleculeName];
|
||||
if (!moleculeName) {
|
||||
return nil;
|
||||
}
|
||||
@ -67,7 +67,7 @@
|
||||
|
||||
|
||||
- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)getMoleculeForStackWithJSON:(nonnull NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
NSString *moleculeName = [json string:@"moleculeName"];
|
||||
NSString *moleculeName = [json string:KeyMoleculeName];
|
||||
if (!moleculeName) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@ -8,58 +8,60 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
public class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
open class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
|
||||
public override func registerWithTable() {
|
||||
open override func registerWithTable() {
|
||||
super.registerWithTable()
|
||||
guard let molecules = loadObject?.pageJSON?.arrayForKey("molecules") else {
|
||||
guard let molecules = loadObject?.pageJSON?.arrayForKey(KeyMolecules) else {
|
||||
return
|
||||
}
|
||||
for case let molecule as Dictionary<AnyHashable, Any> in molecules {
|
||||
if let moleculeName = molecule.optionalStringForKey("moleculeName") {
|
||||
if let moleculeName = molecule.optionalStringForKey(KeyMoleculeName) {
|
||||
tableView?.register(MoleculeTableViewCell.self, forCellReuseIdentifier: moleculeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override func viewForTop() -> UIView {
|
||||
open override func viewForTop() -> UIView {
|
||||
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else {
|
||||
return super.viewForTop()
|
||||
}
|
||||
return molecule
|
||||
}
|
||||
|
||||
override public func viewForBottom() -> UIView {
|
||||
override open func viewForBottom() -> UIView {
|
||||
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForStack(withJSON: moleculeJSON, delegateObject: delegateObject()) else {
|
||||
return viewForBottom()
|
||||
}
|
||||
return molecule
|
||||
}
|
||||
|
||||
public override func newDataBuildScreen() {
|
||||
open override func newDataBuildScreen() {
|
||||
super.newDataBuildScreen()
|
||||
registerWithTable()
|
||||
}
|
||||
|
||||
public override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
if let moleculeName = loadObject?.pageJSON?.stringOptionalWithChainOfKeysOrIndexes(["molecules",indexPath.row,"moleculeName"]), let theClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping?[moleculeName] as? MVMCoreUIMoleculeViewProtocol.Type,
|
||||
open override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
if let moleculeName = loadObject?.pageJSON?.stringOptionalWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row,KeyMoleculeName]), let theClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping?[moleculeName] as? MVMCoreUIMoleculeViewProtocol.Type,
|
||||
let estimatedHeightForRow = theClass.estimatedHeightForRow {
|
||||
return estimatedHeightForRow()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return loadObject?.pageJSON?.arrayForKey("molecules").count ?? 0
|
||||
open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return loadObject?.pageJSON?.arrayForKey(KeyMolecules).count ?? 0
|
||||
}
|
||||
|
||||
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
guard let molecule = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes(["molecules",indexPath.row]),
|
||||
let moleculeName = molecule.optionalStringForKey("moleculeName"),
|
||||
open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
guard let molecule = loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyMolecules,indexPath.row]),
|
||||
let moleculeName = molecule.optionalStringForKey(KeyMoleculeName),
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: moleculeName) as? MoleculeTableViewCell else {
|
||||
return UITableViewCell()
|
||||
}
|
||||
cell.setWithJSON(molecule, delegateObject: delegateObject(), additionalData: nil)
|
||||
let delegate = delegateObject()
|
||||
cell.setWithJSON(molecule, delegateObject: delegate, additionalData: nil)
|
||||
cell.setSeparatorWithJSON(loadObject?.pageJSON?.optionalDictionaryForKey("separator"), delegateObject: delegate, additionalData: nil, indexPath: indexPath)
|
||||
cell.updateView(tableView.bounds.width)
|
||||
return cell
|
||||
}
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
|
||||
extern NSString * const KeyScreenHeading;
|
||||
|
||||
extern NSString * const KeyMolecules;
|
||||
extern NSString * const KeyMoleculeName;
|
||||
|
||||
extern NSString * const KeyDisableButton;
|
||||
|
||||
extern NSString * const KeyValue;
|
||||
|
||||
@ -12,6 +12,9 @@
|
||||
|
||||
NSString * const KeyScreenHeading = @"screenHeading";
|
||||
|
||||
NSString * const KeyMolecules = @"molecules";
|
||||
NSString * const KeyMoleculeName = @"moleculeName";
|
||||
|
||||
NSString * const KeyDisableButton = @"disableAction";
|
||||
|
||||
NSString * const KeyValue = @"value";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user