Commit 4ca95ebc by Daniel Dahan

adjusting line animation on TabBar changes

parent 31330fc6
......@@ -78,14 +78,21 @@ open class TabBar: Bar {
}
/// An enum that determines the tab bar style.
open var tabBarStyle = TabBarStyle.normal {
open var tabBarStyle = TabBarStyle.scrollable {
didSet {
layoutSubviews()
}
}
/// A reference to the scroll view when the tab bar style is scrollable.
open fileprivate(set) var scrollView: UIScrollView!
open let scrollView = UIScrollView()
/// Does the scroll view bounce.
open var isScrollBounceEnabled = true {
didSet {
scrollView.bounces = true
}
}
/// A delegation reference.
open weak var delegate: TabBarDelegate?
......@@ -270,11 +277,7 @@ open class TabBar: Bar {
layoutDivider()
let buttonsWidth = buttons.reduce(0) {
$0 + $1.sizeThatFits(CGSize(width: .greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
}
if .scrollable == tabBarStyle && buttonsWidth > p {
if .scrollable == tabBarStyle {
scrollView.frame = CGRect(x: l, y: 0, width: p, height: height)
var w: CGFloat = 0
......@@ -288,14 +291,14 @@ open class TabBar: Bar {
w += width
}
scrollView.contentSize = CGSize(width: buttonsWidth, height: height)
scrollView.addSubview(line)
scrollView.contentSize = CGSize(width: w, height: height)
} else {
contentView.grid.axis.columns = buttons.count
centerViews = buttons
addSubview(line)
}
addSubview(line)
updateSelectionLine()
}
......@@ -354,8 +357,6 @@ extension TabBar {
/// Prepares the scroll view.
fileprivate func prepareScrollView() {
scrollView = UIScrollView()
scrollView.bounces = false
scrollView.isPagingEnabled = false
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
......
......@@ -32,12 +32,7 @@ import UIKit
fileprivate var TabItemKey: UInt8 = 0
open class TabItem: FlatButton {
open override func prepare() {
super.prepare()
pulseAnimation = .none
}
}
open class TabItem: FlatButton {}
@objc(TabBarAlignment)
public enum TabBarAlignment: Int {
......@@ -95,6 +90,7 @@ open class TabsController: UIViewController {
prepareTabBar()
prepareContainer()
prepareViewControllers()
layoutSubviews()
}
}
......@@ -111,7 +107,7 @@ open class TabsController: UIViewController {
}
/// The transition type used during a transition.
open var transitionType = MotionTransitionType.autoReverse(presenting: .fade)
open var motionTransitionType = MotionTransitionType.fade
/**
An initializer that initializes the object with a NSCoder object.
......@@ -150,8 +146,7 @@ open class TabsController: UIViewController {
open func layoutSubviews() {
layoutTabBar()
layoutContainer()
viewControllers[selectedIndex].view.frame.size = container.bounds.size
layoutViewController(at: selectedIndex)
}
/**
......@@ -165,10 +160,7 @@ open class TabsController: UIViewController {
view.contentScaleFactor = Screen.scale
prepareContainer()
prepareTabBar()
for i in 0..<viewControllers.count {
prepareViewController(at: i)
}
prepareViewControllers()
}
}
......@@ -224,6 +216,21 @@ extension TabsController {
view.addSubview(container)
}
/// Prepares all the view controllers.
fileprivate func prepareViewControllers() {
let n = viewControllers.count
for i in 0..<n {
guard i != selectedIndex else {
continue
}
prepareViewController(at: i)
}
prepareViewController(at: selectedIndex)
}
/**
Loads a view controller based on its index in the viewControllers Array
and adds it as a child view controller.
......@@ -267,7 +274,7 @@ extension TabsController {
container.height = view.height
}
container.width = view.bounds.width
container.width = view.width
}
/// Layout the TabBar.
......@@ -291,6 +298,11 @@ extension TabsController {
v.isHidden = true
}
}
/// Layout the view controller at the given index.
fileprivate func layoutViewController(at index: Int) {
viewControllers[index].view.frame.size = container.bounds.size
}
}
extension TabsController {
......@@ -343,10 +355,12 @@ extension TabsController {
let tvc = viewControllers[i]
tvc.view.frame.size = container.bounds.size
tvc.motionModalTransitionType = transitionType
tvc.motionModalTransitionType = motionTransitionType
Motion.shared.transition(from: fvc, to: tvc, in: container)
selectedIndex = i
tabBar?.select(at: selectedIndex)
}
}
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