Commit 838fadf0 by Daniel Dahan

development: reducing code complexity with BarViews round 2

parent 3ff98d5a
...@@ -224,7 +224,6 @@ open class ControlView: View { ...@@ -224,7 +224,6 @@ open class ControlView: View {
super.prepareView() super.prepareView()
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
autoresizingMask = .flexibleWidth
prepareContentView() prepareContentView()
} }
......
...@@ -227,27 +227,29 @@ public class Grid { ...@@ -227,27 +227,29 @@ public class Grid {
canvas.addSubview(child) canvas.addSubview(child)
} }
canvas.layoutIfNeeded()
switch axis.direction { switch axis.direction {
case .horizontal: case .horizontal:
let c = child.grid.columns let c = child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = contentEdgeInsets.top + layoutEdgeInsets.top child.y = contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace child.width = w * CGFloat(c) - interimSpace
child.height = canvas.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom child.height = canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom
n += c + co - 1 n += c + co - 1
case .vertical: case .vertical:
let r = child.grid.rows let r = child.grid.rows
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let h = (canvas.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = contentEdgeInsets.left + layoutEdgeInsets.left child.x = contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = canvas.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right child.width = canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right
child.height = h * CGFloat(r) - interimSpace child.height = h * CGFloat(r) - interimSpace
n += r + ro - 1 n += r + ro - 1
...@@ -257,8 +259,8 @@ public class Grid { ...@@ -257,8 +259,8 @@ public class Grid {
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let c = child.grid.columns let c = child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (canvas.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
......
...@@ -117,7 +117,7 @@ open class RootController: UIViewController { ...@@ -117,7 +117,7 @@ open class RootController: UIViewController {
open func transitionFromRootViewController(toViewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { open func transitionFromRootViewController(toViewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMove(toParentViewController: nil) rootViewController.willMove(toParentViewController: nil)
addChildViewController(toViewController) addChildViewController(toViewController)
toViewController.view.frame = rootViewController.view.frame toViewController.view.frame = rootViewController.view.bounds
transition(from: rootViewController, transition(from: rootViewController,
to: toViewController, to: toViewController,
duration: duration, duration: duration,
...@@ -138,7 +138,7 @@ open class RootController: UIViewController { ...@@ -138,7 +138,7 @@ open class RootController: UIViewController {
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you method. `layoutSubviews` should be called immediately, unless you
have a certain need. have a certain need.
*/ */
open func layoutSubviews() {} open func layoutSubviews() {}
...@@ -176,7 +176,8 @@ open class RootController: UIViewController { ...@@ -176,7 +176,8 @@ open class RootController: UIViewController {
addChildViewController(v) addChildViewController(v)
container.addSubview(v.view) container.addSubview(v.view)
v.didMove(toParentViewController: self) v.didMove(toParentViewController: self)
v.view.clipsToBounds = true v.view.frame = container.bounds
v.view.clipsToBounds = true
v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
v.view.contentScaleFactor = Device.scale v.view.contentScaleFactor = Device.scale
} }
......
...@@ -77,14 +77,6 @@ open class Snackbar: BarView { ...@@ -77,14 +77,6 @@ open class Snackbar: BarView {
return super.hitTest(point, with: event) return super.hitTest(point, with: event)
} }
open override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
print("RENDING", contentView)
textLabel.frame = contentView.bounds
}
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
...@@ -112,6 +104,6 @@ open class Snackbar: BarView { ...@@ -112,6 +104,6 @@ open class Snackbar: BarView {
textLabel.numberOfLines = 0 textLabel.numberOfLines = 0
contentView.backgroundColor = Color.green.base contentView.backgroundColor = Color.green.base
contentView.addSubview(textLabel) contentView.grid.views.append(textLabel)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment