Commit 51a7d750 by Daniel Dahan

development: updated ControlView and NavigationBar grid layouts

parent 9efac5ec
......@@ -48,7 +48,7 @@ open class ControlView: View {
/// A wrapper around grid.contentInset.
@IBInspectable
open var contentInset: EdgeInsets {
open var contentEdgeInsets: EdgeInsets {
get {
return grid.contentEdgeInsets
}
......@@ -151,49 +151,48 @@ open class ControlView: View {
if willRenderView {
layoutIfNeeded()
let g = Int(width / gridFactor)
let columns = g + 1
let l = (CGFloat(leftControls.count) * interimSpace)
let r = (CGFloat(rightControls.count) * interimSpace)
let p = width - l - r - contentEdgeInsets.left - contentEdgeInsets.right
let columns = Int(p / gridFactor)
grid.views = []
grid.views.removeAll()
grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
for c in leftControls {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
for v in leftControls {
var w: CGFloat = 0
if let b = v as? UIButton {
b.contentEdgeInsets = .zero
b.sizeToFit()
w = b.width
}
v.height = frame.size.height - contentEdgeInsets.top - contentEdgeInsets.bottom
v.grid.columns = Int(ceil(w / gridFactor)) + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= v.grid.columns
addSubview(c)
grid.views.append(c)
grid.views.append(v)
}
addSubview(contentView)
grid.views.append(contentView)
// rightControls
for c in rightControls {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
for v in rightControls {
var w: CGFloat = 0
if let b = v as? UIButton {
b.contentEdgeInsets = .zero
b.sizeToFit()
w = b.width
}
v.height = frame.size.height - contentEdgeInsets.top - contentEdgeInsets.bottom
v.grid.columns = Int(ceil(w / gridFactor)) + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= v.grid.columns
addSubview(c)
grid.views.append(c)
grid.views.append(v)
}
grid.contentEdgeInsets = contentInset
grid.interimSpace = interimSpace
contentView.grid.reload()
}
}
......
......@@ -61,19 +61,19 @@ open class NavigationBar: UINavigationBar {
/// Will render the view.
open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview
return 0 < width && 0 < height
}
/// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet {
contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open var contentInset = EdgeInsets.zero {
open var contentEdgeInsets = EdgeInsets.zero {
didSet {
layoutSubviews()
}
......@@ -175,7 +175,9 @@ open class NavigationBar: UINavigationBar {
layoutNavigationItem(item: v)
}
divider?.reload()
if let v = divider {
v.reload()
}
}
open override func pushItem(_ item: UINavigationItem, animated: Bool) {
......@@ -194,52 +196,51 @@ open class NavigationBar: UINavigationBar {
let titleView = prepareTitleView(item: item)
let contentView = prepareContentView(item: item)
let g = Int(width / gridFactor)
let columns = g + 1
let l = (CGFloat(item.leftControls.count) * interimSpace)
let r = (CGFloat(item.rightControls.count) * interimSpace)
let p = width - l - r - contentEdgeInsets.left - contentEdgeInsets.right
let columns = Int(p / gridFactor)
titleView.frame.origin = .zero
titleView.frame.size = intrinsicContentSize
titleView.grid.views = []
titleView.grid.views.removeAll()
titleView.grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v = item.leftControls {
for c in v {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = titleView.height - contentInset.top - contentInset.bottom
c.grid.columns = Int(w / gridFactor) + 1
for v in item.leftControls {
var w: CGFloat = 0
if let b = v as? UIButton {
b.contentEdgeInsets = .zero
b.sizeToFit()
w = b.width
}
v.height = frame.size.height - contentEdgeInsets.top - contentEdgeInsets.bottom
v.grid.columns = Int(ceil(w / gridFactor)) + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= v.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
titleView.grid.views.append(v)
}
titleView.addSubview(contentView)
titleView.grid.views.append(contentView)
// rightControls
if let v = item.rightControls {
for c in v {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = titleView.height - contentInset.top - contentInset.bottom
c.grid.columns = Int(w / gridFactor) + 1
for v in item.rightControls {
var w: CGFloat = 0
if let b = v as? UIButton {
b.contentEdgeInsets = .zero
b.sizeToFit()
w = b.width
}
v.height = frame.size.height - contentEdgeInsets.top - contentEdgeInsets.bottom
v.grid.columns = Int(ceil(w / gridFactor)) + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= v.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
titleView.grid.views.append(v)
}
titleView.grid.contentEdgeInsets = contentInset
titleView.grid.contentEdgeInsets = contentEdgeInsets
titleView.grid.interimSpace = interimSpace
titleView.grid.reload()
......
......@@ -43,7 +43,7 @@ extension UINavigationController {
}
@IBDesignable
open class NavigationController: UINavigationController, UIGestureRecognizerDelegate {
open class NavigationController: UINavigationController {
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
......@@ -72,17 +72,22 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let v = interactivePopGestureRecognizer {
if let x = navigationDrawerController {
guard let v = interactivePopGestureRecognizer else {
return
}
guard let x = navigationDrawerController else {
return
}
if let l = x.leftPanGesture {
l.require(toFail: v)
}
if let r = x.rightPanGesture {
r.require(toFail: v)
}
}
}
}
open override func viewDidLoad() {
super.viewDidLoad()
......@@ -100,16 +105,25 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
}
/**
Detects the gesture recognizer being used. This is necessary when using
NavigationDrawerController. It eliminates the conflict in panning.
- Parameter gestureRecognizer: A UIGestureRecognizer to detect.
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no.
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return interactivePopGestureRecognizer == gestureRecognizer && nil != navigationBar.backItem
open func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = Device.scale
// This ensures the panning gesture is available when going back between views.
if let v = interactivePopGestureRecognizer {
v.isEnabled = true
v.delegate = self
}
}
}
extension NavigationController: UINavigationBarDelegate {
/**
Delegation method that is called when a new UINavigationItem is about to be pushed.
This is used to prepare the transitions between UIViewControllers on the stack.
......@@ -118,19 +132,13 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
- Returns: A Boolean value that indicates whether to push the item on to the stack or not.
True is yes, false is no.
*/
open func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
public func navigationBar(_ navigationBar: UINavigationBar, shouldPush item: UINavigationItem) -> Bool {
if let v = navigationBar as? NavigationBar {
let backButton = IconButton(image: v.backButtonImage)
let backButton = IconButton(image: v.backButtonImage, tintColor: Color.blue.base)
backButton.pulseColor = Color.white
backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
if var c = item.leftControls {
c.append(backButton)
item.leftControls = c
} else {
item.leftControls = [backButton]
}
item.leftControls.append(backButton)
item.backButton = backButton
v.layoutNavigationItem(item: item)
}
......@@ -141,22 +149,17 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
internal func handleBackButton() {
popViewController(animated: true)
}
}
extension NavigationController: UIGestureRecognizerDelegate {
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
Detects the gesture recognizer being used. This is necessary when using
NavigationDrawerController. It eliminates the conflict in panning.
- Parameter gestureRecognizer: A UIGestureRecognizer to detect.
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no.
*/
open func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = Device.scale
// This ensures the panning gesture is available when going back between views.
if let v = interactivePopGestureRecognizer {
v.isEnabled = true
v.delegate = self
}
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return interactivePopGestureRecognizer == gestureRecognizer && nil != navigationBar.backItem
}
}
......@@ -53,10 +53,10 @@ public class NavigationItem {
public private(set) var detailLabel: UILabel!
/// Left controls.
public var leftControls: [UIView]?
public var leftControls = [UIView]()
/// Right controls.
public var rightControls: [UIView]?
public var rightControls = [UIView]()
/// Initializer.
public init() {
......@@ -153,7 +153,7 @@ extension UINavigationItem {
}
/// Left side UIViews.
public var leftControls: [UIView]? {
public var leftControls: [UIView] {
get {
return navigationItem.leftControls
}
......@@ -163,7 +163,7 @@ extension UINavigationItem {
}
/// Right side UIViews.
public var rightControls: [UIView]? {
public var rightControls: [UIView] {
get {
return navigationItem.rightControls
}
......
......@@ -49,7 +49,7 @@ open class Snackbar: BarView {
}
/// Text label.
public private(set) var textLabel: UILabel!
public internal(set) var textLabel: UILabel!
open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 49)
......@@ -58,22 +58,6 @@ open class Snackbar: BarView {
/// The status of the snackbar.
open internal(set) var status = SnackbarStatus.notVisible
open override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
if nil != text && "" != text {
if nil == textLabel.superview {
contentView.addSubview(textLabel)
}
textLabel.frame = contentView.bounds
} else {
textLabel.removeFromSuperview()
}
contentView.grid.reload()
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
......@@ -83,9 +67,10 @@ open class Snackbar: BarView {
*/
open override func prepareView() {
super.prepareView()
interimSpace = 24
contentEdgeInsets.left = interimSpace
contentEdgeInsets.right = interimSpace
backgroundColor = Color.grey.darken3
grid.contentEdgeInsets = EdgeInsets(top: 0, left: 24, bottom: 0, right: 24)
grid.interimSpace = 24
prepareTextLabel()
}
......@@ -96,5 +81,6 @@ open class Snackbar: BarView {
textLabel.font = RobotoFont.medium(with: 14)
textLabel.textAlignment = .left
textLabel.textColor = Color.white
contentView.grid.views.append(textLabel)
}
}
......@@ -92,6 +92,7 @@ open class SnackbarController: RootController {
*/
open func animate(snackbar status: SnackbarStatus, animations: (@escaping (Snackbar) -> Void)? = nil, completion: (@escaping (Snackbar) -> Void)? = nil) {
isAnimating = true
isUserInteractionEnabled = false
UIView.animate(withDuration: 0.25, animations: { [weak self, status = status, animations = animations] in
guard let s = self else {
return
......@@ -105,6 +106,7 @@ open class SnackbarController: RootController {
}
s.isAnimating = false
s.isUserInteractionEnabled = true
s.snackbar.status = status
completion?(s.snackbar)
}
......
......@@ -43,7 +43,7 @@ open class Toolbar: BarView {
}
/// Title label.
open private(set) var titleLabel: UILabel!
open internal(set) var titleLabel: UILabel!
/// A convenience property to set the detailLabel text.
open var detail: String? {
......@@ -57,7 +57,7 @@ open class Toolbar: BarView {
}
/// Detail label.
open private(set) var detailLabel: UILabel!
open internal(set) var detailLabel: UILabel!
open override func layoutSubviews() {
super.layoutSubviews()
......
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