Commit f5ff3bb7 by Daniel Dahan

development: preparation for latest release

parent 4ee81dce
......@@ -4,6 +4,10 @@
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
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 {
/// Reloads the layout.
open func reload() {
// Clear constraints so new ones do not conflict.
container.removeConstraints(container.constraints)
var h: CGFloat = 0
var format = "V:|"
var views = [String: Any]()
var metrics = [String: Any]()
h = prepare(view: toolbar, with: toolbarEdgeInsets, from: h)
h = prepare(view: contentView, with: contentViewEdgeInsets, from: h)
h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h)
if let v = toolbar {
metrics["toolbarTop"] = toolbarEdgeInsets.top
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))
container.height = h
bounds.size.height = h
}
/**
......@@ -274,6 +225,7 @@ open class Card: PulseView {
- Parameter from top: A CGFloat.
- Returns: A CGFloat.
*/
@discardableResult
open func prepare(view: UIView?, with insets: EdgeInsets, from top: CGFloat) -> CGFloat {
guard let v = view else {
return top
......
......@@ -76,12 +76,15 @@ open class ImageCard: Card {
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: bottomBar, with: bottomBarEdgeInsets, from: h)
container.height = h
height = h
bounds.size.height = h
}
}
......@@ -103,6 +103,13 @@ open class PageTabBarController: RootController {
/// Reference to the 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.
open internal(set) var isTabSelectedAnimation = false
......@@ -120,15 +127,32 @@ open class PageTabBarController: RootController {
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.
open var viewControllers = [UIViewController]()
public required init?(coder aDecoder: NSCoder) {
isBounceEnabled = true
super.init(coder: aDecoder)
prepare()
}
public override init(rootViewController: UIViewController) {
isBounceEnabled = true
super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil))
viewControllers.append(rootViewController)
setViewControllers(viewControllers, direction: .forward, animated: true)
......@@ -136,6 +160,7 @@ open class PageTabBarController: RootController {
}
public init(viewControllers: [UIViewController], selectedIndex: Int) {
isBounceEnabled = true
super.init(rootViewController: UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil))
self.selectedIndex = selectedIndex
self.viewControllers.append(contentsOf: viewControllers)
......@@ -189,7 +214,7 @@ open class PageTabBarController: RootController {
preparePageTabBarItems()
}
override func prepareRootViewController() {
open override func prepareRootViewController() {
super.prepareRootViewController()
guard let v = pageViewController else {
......@@ -200,11 +225,7 @@ open class PageTabBarController: RootController {
v.dataSource = self
v.isDoubleSided = false
for view in v.view.subviews {
if let v = view as? UIScrollView {
v.delegate = self
}
}
scrollView?.delegate = self
}
/// Prepares the pageTabBarItems.
......@@ -260,7 +281,7 @@ open class PageTabBarController: RootController {
}
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 {
return
}
......@@ -279,7 +300,7 @@ extension PageTabBarController: UIPageViewControllerDelegate {
}
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 {
return nil
}
......@@ -293,7 +314,7 @@ extension PageTabBarController: UIPageViewControllerDataSource {
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 {
return nil
}
......@@ -309,7 +330,7 @@ extension PageTabBarController: UIPageViewControllerDataSource {
}
extension PageTabBarController: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard !pageTabBar.isAnimating else {
return
}
......
......@@ -68,6 +68,6 @@ open class PresenterCard: Card {
h = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: h)
container.height = h
height = h
bounds.size.height = h
}
}
......@@ -148,6 +148,7 @@ open class Toolbar: Bar {
*/
open override func prepare() {
super.prepare()
zPosition = 1000
contentViewAlignment = .center
prepareTitleLabel()
prepareDetailLabel()
......
......@@ -203,7 +203,6 @@ open class ToolbarController: StatusBarController {
/// Prepares the toolbar.
private func prepareToolbar() {
toolbar.depthPreset = .depth1
toolbar.zPosition = 1000
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