Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
d89f0976
Commit
d89f0976
authored
Jul 25, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved animation logic completely to TabBar
parent
41f41bcc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
64 deletions
+31
-64
Sources/iOS/TabsController.swift
+31
-64
No files found.
Sources/iOS/TabsController.swift
View file @
d89f0976
...
@@ -76,7 +76,7 @@ extension UIViewController {
...
@@ -76,7 +76,7 @@ extension UIViewController {
open
class
TabsController
:
UIViewController
{
open
class
TabsController
:
UIViewController
{
/// The TabBar used to switch between view controllers.
/// The TabBar used to switch between view controllers.
@IBInspectable
@IBInspectable
open
fileprivate
(
set
)
var
tabBar
:
TabBar
?
open
let
tabBar
=
TabBar
()
@IBInspectable
@IBInspectable
public
let
container
=
UIView
()
public
let
container
=
UIView
()
...
@@ -157,6 +157,7 @@ open class TabsController: UIViewController {
...
@@ -157,6 +157,7 @@ open class TabsController: UIViewController {
when subclassing.
when subclassing.
*/
*/
open
func
prepare
()
{
open
func
prepare
()
{
view
.
backgroundColor
=
.
white
view
.
contentScaleFactor
=
Screen
.
scale
view
.
contentScaleFactor
=
Screen
.
scale
prepareContainer
()
prepareContainer
()
prepareTabBar
()
prepareTabBar
()
...
@@ -164,26 +165,22 @@ open class TabsController: UIViewController {
...
@@ -164,26 +165,22 @@ open class TabsController: UIViewController {
}
}
}
}
extension
TabsController
{
fileprivate
extension
TabsController
{
/**
/**
Prepares the tabBar buttons.
Prepares the tabBar buttons.
- Parameter _ buttons: An Array of UIButtons.
- Parameter _ buttons: An Array of UIButtons.
*/
*/
fileprivate
func
prepareTabBarButtons
(
_
buttons
:
[
UIButton
])
{
func
prepareTabBarButtons
(
_
buttons
:
[
UIButton
])
{
guard
let
v
=
tabBar
else
{
tabBar
.
buttons
=
buttons
return
}
v
.
buttons
=
buttons
for
b
in
v
.
buttons
{
for
b
in
tabBar
.
buttons
{
b
.
removeTarget
(
self
,
action
:
#selector(
handleTabBarButton(button:)
)
,
for
:
.
touchUpInside
)
b
.
removeTarget
(
self
,
action
:
#selector(
handleTabBarButton(button:)
)
,
for
:
.
touchUpInside
)
b
.
addTarget
(
self
,
action
:
#selector(
handleTabBarButton(button:)
)
,
for
:
.
touchUpInside
)
b
.
addTarget
(
self
,
action
:
#selector(
handleTabBarButton(button:)
)
,
for
:
.
touchUpInside
)
}
}
}
}
/// Prepares the TabBar.
/// Prepares the TabBar.
f
ileprivate
f
unc
prepareTabBar
()
{
func
prepareTabBar
()
{
var
buttons
=
[
UIButton
]()
var
buttons
=
[
UIButton
]()
for
v
in
viewControllers
{
for
v
in
viewControllers
{
...
@@ -192,35 +189,20 @@ extension TabsController {
...
@@ -192,35 +189,20 @@ extension TabsController {
buttons
.
append
(
button
)
buttons
.
append
(
button
)
}
}
guard
0
<
buttons
.
count
else
{
tabBar
.
lineAlignment
=
.
bottom
==
tabBarAlignment
?
.
top
:
.
bottom
tabBar
?
.
removeFromSuperview
()
view
.
addSubview
(
tabBar
)
tabBar
=
nil
return
}
guard
nil
==
tabBar
else
{
prepareTabBarButtons
(
buttons
)
return
}
tabBar
=
TabBar
()
tabBar
?
.
isLineAnimated
=
false
tabBar
?
.
lineAlignment
=
.
top
view
.
addSubview
(
tabBar
!
)
prepareTabBarButtons
(
buttons
)
prepareTabBarButtons
(
buttons
)
}
}
/// Prepares the container view.
/// Prepares the container view.
f
ileprivate
f
unc
prepareContainer
()
{
func
prepareContainer
()
{
view
.
addSubview
(
container
)
view
.
addSubview
(
container
)
}
}
/// Prepares all the view controllers.
/// Prepares all the view controllers.
fileprivate
func
prepareViewControllers
()
{
func
prepareViewControllers
()
{
let
n
=
viewControllers
.
count
for
i
in
0
..<
viewControllers
.
count
{
for
i
in
0
..<
n
{
guard
i
!=
selectedIndex
else
{
guard
i
!=
selectedIndex
else
{
continue
continue
}
}
...
@@ -236,7 +218,7 @@ extension TabsController {
...
@@ -236,7 +218,7 @@ extension TabsController {
and adds it as a child view controller.
and adds it as a child view controller.
- Parameter at index: An Int for the viewControllers index.
- Parameter at index: An Int for the viewControllers index.
*/
*/
f
ileprivate
f
unc
prepareViewController
(
at
index
:
Int
)
{
func
prepareViewController
(
at
index
:
Int
)
{
let
vc
=
viewControllers
[
index
]
let
vc
=
viewControllers
[
index
]
guard
!
childViewControllers
.
contains
(
vc
)
else
{
guard
!
childViewControllers
.
contains
(
vc
)
else
{
...
@@ -251,15 +233,10 @@ extension TabsController {
...
@@ -251,15 +233,10 @@ extension TabsController {
}
}
}
}
extension
TabsController
{
fileprivate
extension
TabsController
{
/// Layout the container view.
/// Layout the container view.
fileprivate
func
layoutContainer
()
{
func
layoutContainer
()
{
guard
let
v
=
tabBar
else
{
let
p
=
tabBar
.
height
container
.
frame
=
view
.
bounds
return
}
let
p
=
v
.
height
let
y
=
view
.
height
-
p
let
y
=
view
.
height
-
p
switch
tabBarAlignment
{
switch
tabBarAlignment
{
...
@@ -278,40 +255,36 @@ extension TabsController {
...
@@ -278,40 +255,36 @@ extension TabsController {
}
}
/// Layout the TabBar.
/// Layout the TabBar.
fileprivate
func
layoutTabBar
()
{
func
layoutTabBar
()
{
guard
let
v
=
tabBar
else
{
let
y
=
view
.
height
-
tabBar
.
height
return
}
let
y
=
view
.
height
-
v
.
height
tabBar
.
width
=
view
.
width
v
.
width
=
view
.
width
switch
tabBarAlignment
{
switch
tabBarAlignment
{
case
.
top
:
case
.
top
:
v
.
isHidden
=
false
tabBar
.
isHidden
=
false
v
.
y
=
0
tabBar
.
y
=
0
case
.
bottom
:
case
.
bottom
:
v
.
isHidden
=
false
tabBar
.
isHidden
=
false
v
.
y
=
y
tabBar
.
y
=
y
case
.
hidden
:
case
.
hidden
:
v
.
isHidden
=
true
tabBar
.
isHidden
=
true
}
}
}
}
/// Layout the view controller at the given index.
/// Layout the view controller at the given index.
f
ileprivate
f
unc
layoutViewController
(
at
index
:
Int
)
{
func
layoutViewController
(
at
index
:
Int
)
{
viewControllers
[
index
]
.
view
.
frame
.
size
=
container
.
bounds
.
size
viewControllers
[
index
]
.
view
.
frame
.
size
=
container
.
bounds
.
size
}
}
}
}
extension
TabsController
{
fileprivate
extension
TabsController
{
/**
/**
Removes the view controller as a child view controller with
Removes the view controller as a child view controller with
the given index.
the given index.
- Parameter at index: An Int for the view controller position.
- Parameter at index: An Int for the view controller position.
*/
*/
f
ileprivate
f
unc
removeViewController
(
at
index
:
Int
)
{
func
removeViewController
(
at
index
:
Int
)
{
let
v
=
viewControllers
[
index
]
let
v
=
viewControllers
[
index
]
guard
childViewControllers
.
contains
(
v
)
else
{
guard
childViewControllers
.
contains
(
v
)
else
{
...
@@ -325,25 +298,21 @@ extension TabsController {
...
@@ -325,25 +298,21 @@ extension TabsController {
Removes a given view controller from the childViewControllers array.
Removes a given view controller from the childViewControllers array.
- Parameter at index: An Int for the view controller position.
- Parameter at index: An Int for the view controller position.
*/
*/
f
ileprivate
f
unc
removeViewController
(
viewController
:
UIViewController
)
{
func
removeViewController
(
viewController
:
UIViewController
)
{
viewController
.
willMove
(
toParentViewController
:
nil
)
viewController
.
willMove
(
toParentViewController
:
nil
)
viewController
.
view
.
removeFromSuperview
()
viewController
.
view
.
removeFromSuperview
()
viewController
.
removeFromParentViewController
()
viewController
.
removeFromParentViewController
()
}
}
}
}
extension
TabsController
{
fileprivate
extension
TabsController
{
/**
/**
Handles the pageTabBarButton.
Handles the pageTabBarButton.
- Parameter button: A UIButton.
- Parameter button: A UIButton.
*/
*/
@objc
@objc
fileprivate
func
handleTabBarButton
(
button
:
UIButton
)
{
func
handleTabBarButton
(
button
:
UIButton
)
{
guard
let
v
=
tabBar
else
{
guard
let
i
=
tabBar
.
buttons
.
index
(
of
:
button
)
else
{
return
}
guard
let
i
=
v
.
buttons
.
index
(
of
:
button
)
else
{
return
return
}
}
...
@@ -360,7 +329,5 @@ extension TabsController {
...
@@ -360,7 +329,5 @@ extension TabsController {
Motion
.
shared
.
transition
(
from
:
fvc
,
to
:
tvc
,
in
:
container
)
Motion
.
shared
.
transition
(
from
:
fvc
,
to
:
tvc
,
in
:
container
)
selectedIndex
=
i
selectedIndex
=
i
tabBar
?
.
select
(
at
:
selectedIndex
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment