Commit 452bc8f0 by Daniel Dahan

development: PageController now animates TabBar line while panning

parent 6554f20e
......@@ -357,6 +357,23 @@
name = Data;
sourceTree = "<group>";
};
962DDD071D6FBBB7001C307C /* Page */ = {
isa = PBXGroup;
children = (
963FBF071D669D14008F8512 /* PageController.swift */,
);
name = Page;
sourceTree = "<group>";
};
962DDD081D6FBBD0001C307C /* BottomTabBar */ = {
isa = PBXGroup;
children = (
96BCB7591CB40DC500C806FE /* BottomTabBar.swift */,
96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */,
);
name = BottomTabBar;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
isa = PBXGroup;
children = (
......@@ -407,9 +424,6 @@
isa = PBXGroup;
children = (
96BCB79A1CB40DC500C806FE /* TabBar.swift */,
963FBF071D669D14008F8512 /* PageController.swift */,
96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */,
96BCB7591CB40DC500C806FE /* BottomTabBar.swift */,
);
name = TabBar;
sourceTree = "<group>";
......@@ -494,6 +508,7 @@
isa = PBXGroup;
children = (
96BCB8091CB4107700C806FE /* Animate */,
962DDD081D6FBBD0001C307C /* BottomTabBar */,
96BCB8031CB40F4B00C806FE /* Button */,
96BCB8021CB40F3B00C806FE /* Card */,
96BCB7FF1CB40EF000C806FE /* Capture */,
......@@ -512,6 +527,7 @@
96BCB80D1CB410FD00C806FE /* Layer */,
96BCB8041CB40F6C00C806FE /* Layout */,
96BCB8011CB40F1700C806FE /* Navigation */,
962DDD071D6FBBB7001C307C /* Page */,
96EA9A411D4E68E60052C74D /* PhotoLibrary */,
963FBF031D6696EF008F8512 /* SearchBar */,
963FBEFB1D6694E8008F8512 /* Snackbar */,
......
......@@ -93,6 +93,9 @@ open class ControlView: View {
/// Left side UIControls.
open var leftControls = [UIView]() {
didSet {
for v in oldValue {
v.removeFromSuperview()
}
layoutSubviews()
}
}
......@@ -100,6 +103,9 @@ open class ControlView: View {
/// Right side UIControls.
open var rightControls = [UIView]() {
didSet {
for v in oldValue {
v.removeFromSuperview()
}
layoutSubviews()
}
}
......
......@@ -187,7 +187,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 1
view.frame.origin.y = base!.frame.origin.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace
view.y = base!.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace
animations?(view)
}
}) { [weak self] _ in
......@@ -226,7 +226,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 0
view.frame.origin.y = s.origin.y
view.y = s.origin.y
animations?(view)
}
}) { [weak self] _ in
......@@ -273,7 +273,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 1
view.frame.origin.y = base!.frame.origin.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace
view.y = base!.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace
animations?(view)
}
}) { [weak self] _ in
......@@ -313,7 +313,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 0
view.frame.origin.y = s.origin.y + h
view.y = s.origin.y + h
animations?(view)
}
}) { [weak self] _ in
......@@ -359,7 +359,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 1
view.frame.origin.x = base!.frame.origin.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace
view.x = base!.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace
animations?(view)
}
}) { [weak self] _ in
......@@ -397,7 +397,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 0
view.frame.origin.x = s.origin.x
view.x = s.origin.x
animations?(view)
}
}) { [weak self] _ in
......@@ -443,7 +443,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 1
view.frame.origin.x = base!.frame.origin.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace
view.x = base!.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace
animations?(view)
}
}) { [weak self] _ in
......@@ -483,7 +483,7 @@ public class Menu {
animations: { [weak self] in
if let s: Menu = self {
view.alpha = 0
view.frame.origin.x = s.origin.x + w
view.x = s.origin.x + w
animations?(view)
}
}) { [weak self] _ in
......@@ -514,8 +514,8 @@ public class Menu {
view.alpha = 0
view.isHidden = true
view.frame.size = itemSize
view.frame.origin.x = origin.x + (size.width - itemSize.width) / 2
view.frame.origin.y = origin.y + (size.height - itemSize.height) / 2
view.x = origin.x + (size.width - itemSize.width) / 2
view.y = origin.y + (size.height - itemSize.height) / 2
view.layer.zPosition = CGFloat(10000 - v.count - i)
}
}
......
......@@ -411,8 +411,8 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
v.height = view.bounds.height
leftViewThreshold = leftViewWidth / 2
if let vc: UIViewController = leftViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
vc.view.width = v.width
vc.view.height = v.height
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
}
}
......@@ -422,8 +422,8 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
v.height = view.bounds.height
rightViewThreshold = view.bounds.width - rightViewWidth / 2
if let vc: UIViewController = rightViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
vc.view.width = v.width
vc.view.height = v.height
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
}
}
......@@ -903,7 +903,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
leftViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
leftView = View()
leftView!.frame = CGRect(x: 0, y: 0, width: leftViewWidth, height: view.frame.height)
leftView!.frame = CGRect(x: 0, y: 0, width: leftViewWidth, height: view.height)
leftView!.backgroundColor = Color.clear
view.addSubview(leftView!)
......@@ -923,7 +923,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
rightViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
rightView = View()
rightView!.frame = CGRect(x: 0, y: 0, width: rightViewWidth, height: view.frame.height)
rightView!.frame = CGRect(x: 0, y: 0, width: rightViewWidth, height: view.height)
rightView!.backgroundColor = Color.clear
view.addSubview(rightView!)
......
......@@ -55,9 +55,6 @@ public protocol PageControllerDelegate {
@objc(PageController)
open class PageController: RootController {
/// A boolean that indicates when a button animation is active.
internal var animating = false
/// The currently selected UIViewController.
open internal(set) var selectedIndex: Int = 0
......@@ -112,8 +109,8 @@ open class PageController: RootController {
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p
rootViewController.view.frame.origin.y = 0
rootViewController.view.frame.size.height = y
rootViewController.view.y = 0
rootViewController.view.height = y
v.divider.reload()
}
......@@ -160,15 +157,14 @@ open class PageController: RootController {
}
extension PageController {
open func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: (@escaping (Bool) -> Swift.Void)? = nil) {
open func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: (@escaping (Bool) -> Void)? = nil) {
pageViewController?.setViewControllers(viewControllers, direction: direction, animated: animated, completion: completion)
}
}
extension PageController: UIPageViewControllerDelegate {
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
guard let vc = previousViewControllers.first else {
public func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
guard let vc = pendingViewControllers.first else {
return
}
......@@ -176,15 +172,25 @@ extension PageController: UIPageViewControllerDelegate {
return
}
selectedIndex = index
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
guard completed else {
tabBar.select(at: index) { [weak self] _ in
guard let s = self else {
return
}
s.animating = false
}
return
}
guard let vc = previousViewControllers.first else {
return
}
guard let index = viewControllers.index(of: vc) else {
return
}
tabBar.select(at: selectedIndex)
}
}
......@@ -221,25 +227,16 @@ extension PageController: UIPageViewControllerDataSource {
extension PageController: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard !animating else {
guard 0 < view.width else {
return
}
let x = scrollView.contentOffset.x / scrollView.contentSize.width * scrollView.width
guard 0 < x else {
guard let selected = tabBar.selected else {
return
}
tabBar.line.x = x
print("scrolling", x)
}
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// animating = true
}
public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
animating = true
let x = (scrollView.contentOffset.x - view.width) / scrollView.contentSize.width * view.width
tabBar.line.x = selected.x + x
}
}
......@@ -72,8 +72,8 @@ open class SearchBarController: RootController {
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
rootViewController.view.y = p
rootViewController.view.height = h - p
v.divider.reload()
}
......
......@@ -175,8 +175,8 @@ open class ToolbarController: RootController {
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
rootViewController.view.y = p
rootViewController.view.height = h - p
v.divider.reload()
}
......
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