Commit f5ff3bb7 by Daniel Dahan

development: preparation for latest release

parent 4ee81dce
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
Material is an animation and graphics framework that is used to create beautiful applications. Material is an animation and graphics framework that is used to create beautiful applications.
![Material Sample](http://cosmicmind.io/samples/github/page-tab-bar-controller.png)
* [Download the latest sample](https://github.com/CosmicMind/Samples/tree/master/Graph/CardTableView).
## About Material 2 ## About Material 2
The first version of Material was to bring Material Design to iOS. We considered that a great starting point, but not the entire story. Material 2 is the next chapter, which goes deeper into iOS with refined APIs that simplify Architecture, Photo Library, Reminders, Text Editing, Photo & Video, and much more. In addition to Material Design, we love Apple’s flat UI. Having this in mind, we made it possible to accomplish both UI styles with ease. The first version of Material was to bring Material Design to iOS. We considered that a great starting point, but not the entire story. Material 2 is the next chapter, which goes deeper into iOS with refined APIs that simplify Architecture, Photo Library, Reminders, Text Editing, Photo & Video, and much more. In addition to Material Design, we love Apple’s flat UI. Having this in mind, we made it possible to accomplish both UI styles with ease.
......
...@@ -193,63 +193,14 @@ open class Card: PulseView { ...@@ -193,63 +193,14 @@ open class Card: PulseView {
/// Reloads the layout. /// Reloads the layout.
open func reload() { open func reload() {
// Clear constraints so new ones do not conflict. var h: CGFloat = 0
container.removeConstraints(container.constraints)
var format = "V:|" h = prepare(view: toolbar, with: toolbarEdgeInsets, from: h)
var views = [String: Any]() h = prepare(view: contentView, with: contentViewEdgeInsets, from: h)
var metrics = [String: Any]() h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h)
if let v = toolbar { container.height = h
metrics["toolbarTop"] = toolbarEdgeInsets.top bounds.size.height = h
metrics["toolbarBottom"] = toolbarEdgeInsets.bottom
format += "-(toolbarTop)-[toolbar]-(toolbarBottom)"
views["toolbar"] = v
container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right)
}
if let v = contentView {
metrics["contentViewBottom"] = contentViewEdgeInsets.bottom
if nil != toolbar {
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + contentViewEdgeInsets.top
format += "-[contentView]-(contentViewBottom)"
} else {
metrics["contentViewTop"] = contentViewEdgeInsets.top
format += "-(contentViewTop)-[contentView]-(contentViewBottom)"
}
views["contentView"] = v
container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right)
v.grid.reload()
v.divider.reload()
}
if let v = bottomBar {
metrics["bottomBarBottom"] = bottomBarEdgeInsets.bottom
if nil != contentView {
metrics["contentViewBottom"] = (metrics["contentViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)"
} else if nil != toolbar {
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)"
} else {
metrics["bottomBarTop"] = bottomBarEdgeInsets.top
format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)"
}
views["bottomBar"] = v
container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right)
}
guard 0 < views.count else {
return
}
container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
} }
/** /**
...@@ -274,6 +225,7 @@ open class Card: PulseView { ...@@ -274,6 +225,7 @@ open class Card: PulseView {
- Parameter from top: A CGFloat. - Parameter from top: A CGFloat.
- Returns: A CGFloat. - Returns: A CGFloat.
*/ */
@discardableResult
open func prepare(view: UIView?, with insets: EdgeInsets, from top: CGFloat) -> CGFloat { open func prepare(view: UIView?, with insets: EdgeInsets, from top: CGFloat) -> CGFloat {
guard let v = view else { guard let v = view else {
return top return top
......
...@@ -76,12 +76,15 @@ open class ImageCard: Card { ...@@ -76,12 +76,15 @@ open class ImageCard: Card {
h = prepare(view: imageView, with: imageViewEdgeInsets, from: h) h = prepare(view: imageView, with: imageViewEdgeInsets, from: h)
h = prepare(view: toolbar, with: toolbarEdgeInsets, from: h) if let v = toolbar {
prepare(view: v, with: toolbarEdgeInsets, from: h)
v.y = .top == toolbarAlignment ? 0 : h - v.height
}
h = prepare(view: contentView, with: contentViewEdgeInsets, from: h) h = prepare(view: contentView, with: contentViewEdgeInsets, from: h)
h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h) h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h)
container.height = h container.height = h
height = h bounds.size.height = h
} }
} }
...@@ -103,6 +103,13 @@ open class PageTabBarController: RootController { ...@@ -103,6 +103,13 @@ open class PageTabBarController: RootController {
/// Reference to the PageTabBar. /// Reference to the PageTabBar.
open private(set) lazy var pageTabBar: PageTabBar = PageTabBar() open private(set) lazy var pageTabBar: PageTabBar = PageTabBar()
/// A boolean that indicates whether bounds is enabled.
open var isBounceEnabled: Bool {
didSet {
scrollView?.bounces = isBounceEnabled
}
}
/// Indicates that the tab has been pressed and animating. /// Indicates that the tab has been pressed and animating.
open internal(set) var isTabSelectedAnimation = false open internal(set) var isTabSelectedAnimation = false
...@@ -120,15 +127,32 @@ open class PageTabBarController: RootController { ...@@ -120,15 +127,32 @@ open class PageTabBarController: RootController {
return rootViewController as? UIPageViewController return rootViewController as? UIPageViewController
} }
/// A reference to the scrollView.
open var scrollView: UIScrollView? {
guard let v = pageViewController else {
return nil
}
for view in v.view.subviews {
if let v = view as? UIScrollView {
return v
}
}
return nil
}
/// A reference to the UIViewControllers. /// A reference to the UIViewControllers.
open var viewControllers = [UIViewController]() open var viewControllers = [UIViewController]()
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
isBounceEnabled = true
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepare() prepare()
} }
public override init(rootViewController: UIViewController) { public override init(rootViewController: UIViewController) {
isBounceEnabled = true
super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)) super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil))
viewControllers.append(rootViewController) viewControllers.append(rootViewController)
setViewControllers(viewControllers, direction: .forward, animated: true) setViewControllers(viewControllers, direction: .forward, animated: true)
...@@ -136,6 +160,7 @@ open class PageTabBarController: RootController { ...@@ -136,6 +160,7 @@ open class PageTabBarController: RootController {
} }
public init(viewControllers: [UIViewController], selectedIndex: Int) { public init(viewControllers: [UIViewController], selectedIndex: Int) {
isBounceEnabled = true
super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)) super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil))
self.selectedIndex = selectedIndex self.selectedIndex = selectedIndex
self.viewControllers.append(contentsOf: viewControllers) self.viewControllers.append(contentsOf: viewControllers)
...@@ -189,7 +214,7 @@ open class PageTabBarController: RootController { ...@@ -189,7 +214,7 @@ open class PageTabBarController: RootController {
preparePageTabBarItems() preparePageTabBarItems()
} }
override func prepareRootViewController() { open override func prepareRootViewController() {
super.prepareRootViewController() super.prepareRootViewController()
guard let v = pageViewController else { guard let v = pageViewController else {
...@@ -200,11 +225,7 @@ open class PageTabBarController: RootController { ...@@ -200,11 +225,7 @@ open class PageTabBarController: RootController {
v.dataSource = self v.dataSource = self
v.isDoubleSided = false v.isDoubleSided = false
for view in v.view.subviews { scrollView?.delegate = self
if let v = view as? UIScrollView {
v.delegate = self
}
}
} }
/// Prepares the pageTabBarItems. /// Prepares the pageTabBarItems.
...@@ -260,7 +281,7 @@ open class PageTabBarController: RootController { ...@@ -260,7 +281,7 @@ open class PageTabBarController: RootController {
} }
extension PageTabBarController: UIPageViewControllerDelegate { extension PageTabBarController: UIPageViewControllerDelegate {
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { open func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
guard let v = pageViewController.viewControllers?.first else { guard let v = pageViewController.viewControllers?.first else {
return return
} }
...@@ -279,7 +300,7 @@ extension PageTabBarController: UIPageViewControllerDelegate { ...@@ -279,7 +300,7 @@ extension PageTabBarController: UIPageViewControllerDelegate {
} }
extension PageTabBarController: UIPageViewControllerDataSource { extension PageTabBarController: UIPageViewControllerDataSource {
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { open func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let current = viewControllers.index(of: viewController) else { guard let current = viewControllers.index(of: viewController) else {
return nil return nil
} }
...@@ -293,7 +314,7 @@ extension PageTabBarController: UIPageViewControllerDataSource { ...@@ -293,7 +314,7 @@ extension PageTabBarController: UIPageViewControllerDataSource {
return viewControllers[previous] return viewControllers[previous]
} }
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { open func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let current = viewControllers.index(of: viewController) else { guard let current = viewControllers.index(of: viewController) else {
return nil return nil
} }
...@@ -309,7 +330,7 @@ extension PageTabBarController: UIPageViewControllerDataSource { ...@@ -309,7 +330,7 @@ extension PageTabBarController: UIPageViewControllerDataSource {
} }
extension PageTabBarController: UIScrollViewDelegate { extension PageTabBarController: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) { open func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard !pageTabBar.isAnimating else { guard !pageTabBar.isAnimating else {
return return
} }
......
...@@ -68,6 +68,6 @@ open class PresenterCard: Card { ...@@ -68,6 +68,6 @@ open class PresenterCard: Card {
h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h) h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h)
container.height = h container.height = h
height = h bounds.size.height = h
} }
} }
...@@ -148,6 +148,7 @@ open class Toolbar: Bar { ...@@ -148,6 +148,7 @@ open class Toolbar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
zPosition = 1000
contentViewAlignment = .center contentViewAlignment = .center
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
......
...@@ -203,7 +203,6 @@ open class ToolbarController: StatusBarController { ...@@ -203,7 +203,6 @@ open class ToolbarController: StatusBarController {
/// Prepares the toolbar. /// Prepares the toolbar.
private func prepareToolbar() { private func prepareToolbar() {
toolbar.depthPreset = .depth1 toolbar.depthPreset = .depth1
toolbar.zPosition = 1000
view.addSubview(toolbar) view.addSubview(toolbar)
} }
} }
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