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
c9fb3f6f
Commit
c9fb3f6f
authored
Aug 15, 2018
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated organization of BottomNavigationController
parent
a41f9f9d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
38 deletions
+41
-38
Sources/iOS/BottomNavigationController.swift
+41
-38
No files found.
Sources/iOS/BottomNavigationController.swift
View file @
c9fb3f6f
...
...
@@ -42,6 +42,18 @@ extension UIViewController {
}
open
class
BottomNavigationController
:
UITabBarController
{
/// A Boolean that indicates if the swipe feature is enabled..
open
var
isSwipeEnabled
=
false
{
didSet
{
guard
isSwipeEnabled
else
{
removeSwipeGestureRecognizers
()
return
}
prepareSwipeGestureRecognizers
()
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
...
...
@@ -129,17 +141,33 @@ open class BottomNavigationController: UITabBarController {
prepareTabBar
()
}
}
/// A Boolean that indicates if the swipe feature is enabled..
open
var
isSwipeEnabled
=
false
{
didSet
{
guard
isSwipeEnabled
else
{
removeSwipeGestureRecognizers
()
private
extension
BottomNavigationController
{
/**
Selects a view controller at a given index.
- Parameter at index: An Int.
*/
func
select
(
at
index
:
Int
)
{
guard
index
!=
selectedIndex
else
{
return
}
prepareSwipeGestureRecognizers
()
let
lastTabIndex
=
(
tabBar
.
items
?
.
count
??
1
)
-
1
guard
(
0
...
lastTabIndex
)
.
contains
(
index
)
else
{
return
}
guard
!
(
index
==
lastTabIndex
&&
tabBar
.
items
?
.
last
==
moreNavigationController
.
tabBarItem
)
else
{
return
}
let
vc
=
viewControllers
!
[
index
]
guard
delegate
?
.
tabBarController
?(
self
,
shouldSelect
:
vc
)
!=
false
else
{
return
}
selectedIndex
=
index
delegate
?
.
tabBarController
?(
self
,
didSelect
:
vc
)
}
}
...
...
@@ -156,9 +184,7 @@ private extension BottomNavigationController {
tabBar
.
backgroundImage
=
image
tabBar
.
backgroundColor
=
.
white
}
}
private
extension
BottomNavigationController
{
/// Prepare the UISwipeGestureRecognizers.
func
prepareSwipeGestureRecognizers
()
{
removeSwipeGestureRecognizers
()
...
...
@@ -182,42 +208,19 @@ private extension BottomNavigationController {
view
.
removeGestureRecognizer
(
$0
)
}
}
}
private
extension
BottomNavigationController
{
/**
A UISwipeGestureRecognizer that handles swipes.
- Parameter _ gesture: A UISwipeGestureRecognizer.
*/
@objc
func
handleSwipeGesture
(
_
gesture
:
UISwipeGestureRecognizer
)
{
guard
selectedIndex
!=
NSNotFound
else
{
return
}
switch
gesture
.
direction
{
case
.
right
:
select
(
at
:
selectedIndex
-
1
)
case
.
left
:
select
(
at
:
selectedIndex
+
1
)
default
:
break
}
}
private
func
select
(
at
index
:
Int
)
{
guard
index
!=
selectedIndex
else
{
return
}
let
lastTabIndex
=
(
tabBar
.
items
?
.
count
??
1
)
-
1
guard
(
0
...
lastTabIndex
)
.
contains
(
index
)
else
{
return
}
guard
!
(
index
==
lastTabIndex
&&
tabBar
.
items
?
.
last
==
moreNavigationController
.
tabBarItem
)
else
{
return
}
let
vc
=
viewControllers
!
[
index
]
guard
delegate
?
.
tabBarController
?(
self
,
shouldSelect
:
vc
)
!=
false
else
{
return
}
selectedIndex
=
index
delegate
?
.
tabBarController
?(
self
,
didSelect
:
vc
)
select
(
at
:
.
right
==
gesture
.
direction
?
selectedIndex
-
1
:
selectedIndex
+
1
)
}
}
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