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
d603e0fa
Unverified
Commit
d603e0fa
authored
Jun 06, 2018
by
Daniel Dahan
Committed by
GitHub
Jun 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1086 from OrkhanAlikhanov/issue-1056
Fix delegations never fired on tab swipe
parents
dd741ff0
2a740022
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
31 deletions
+34
-31
Sources/iOS/TabBar.swift
+7
-5
Sources/iOS/TabsController.swift
+27
-26
No files found.
Sources/iOS/TabBar.swift
View file @
d603e0fa
...
...
@@ -183,13 +183,13 @@ public protocol TabBarDelegate {
@objc(_TabBarDelegate)
internal
protocol
_TabBarDelegate
{
/**
A delegation method that is executed
when the tabItem will trigger the
anima
tion to the next tab.
A delegation method that is executed
to determine if the TabBar should
transi
tion to the next tab.
- Parameter tabBar: A TabBar.
- Parameter tabItem: A TabItem.
- Returns: A Boolean.
*/
@objc
optional
func
_tabBar
(
tabBar
:
TabBar
,
willSelect
tabItem
:
TabItem
)
func
_tabBar
(
tabBar
:
TabBar
,
shouldSelect
tabItem
:
TabItem
)
->
Bool
}
@objc(TabBarStyle)
...
...
@@ -546,6 +546,9 @@ fileprivate extension TabBar {
return
}
guard
!
(
false
==
_delegate
?
.
_tabBar
(
tabBar
:
self
,
shouldSelect
:
tabItem
))
else
{
return
}
animate
(
to
:
tabItem
,
isTriggeredByUserInteraction
:
true
)
}
}
...
...
@@ -592,7 +595,6 @@ fileprivate extension TabBar {
*/
func
animate
(
to
tabItem
:
TabItem
,
isTriggeredByUserInteraction
:
Bool
,
completion
:
((
TabItem
)
->
Void
)?
=
nil
)
{
if
isTriggeredByUserInteraction
{
_delegate
?
.
_tabBar
?(
tabBar
:
self
,
willSelect
:
tabItem
)
delegate
?
.
tabBar
?(
tabBar
:
self
,
willSelect
:
tabItem
)
}
...
...
Sources/iOS/TabsController.swift
View file @
d603e0fa
...
...
@@ -257,7 +257,6 @@ fileprivate extension TabsController {
func
prepareTabBar
()
{
tabBar
.
lineAlignment
=
.
bottom
==
tabBarAlignment
?
.
top
:
.
bottom
tabBar
.
_delegate
=
self
tabBar
.
delegate
=
self
view
.
addSubview
(
tabBar
)
}
...
...
@@ -374,10 +373,10 @@ fileprivate extension TabsController {
switch
swipeGesture
.
direction
{
case
.
right
:
guard
(
selectedIndex
-
1
)
>=
0
else
{
return
}
select
(
at
:
selectedIndex
-
1
)
internalSelect
(
at
:
selectedIndex
-
1
,
isTriggeredByUserInteraction
:
true
)
case
.
left
:
guard
(
selectedIndex
+
1
)
<
viewControllers
.
count
else
{
return
}
select
(
at
:
selectedIndex
+
1
)
internalSelect
(
at
:
selectedIndex
+
1
,
isTriggeredByUserInteraction
:
true
)
default
:
break
}
...
...
@@ -391,8 +390,26 @@ extension TabsController {
- Parameter at index: An Int.
*/
open
func
select
(
at
index
:
Int
)
{
internalSelect
(
at
:
index
,
isTriggeredByUserInteraction
:
false
)
}
/**
Transitions to the view controller that is at the given index.
- Parameter at index: An Int.
- Parameter isTriggeredByUserInteraction: A boolean indicating whether the
state was changed by a user interaction, true if yes, false otherwise.
- Returns: A boolean indicating whether the transition will take place.
*/
@discardableResult
private
func
internalSelect
(
at
index
:
Int
,
isTriggeredByUserInteraction
:
Bool
)
->
Bool
{
guard
index
!=
selectedIndex
else
{
return
return
false
}
if
isTriggeredByUserInteraction
{
guard
!
(
false
==
delegate
?
.
tabsController
?(
tabsController
:
self
,
shouldSelect
:
viewControllers
[
index
]))
else
{
return
false
}
}
Motion
.
async
{
[
weak
self
]
in
...
...
@@ -402,7 +419,7 @@ extension TabsController {
s
.
tabBar
.
select
(
at
:
index
)
s
.
transition
(
to
:
s
.
viewControllers
[
index
],
isTriggeredByUserInteraction
:
false
)
{
[
weak
self
]
(
isFinishing
)
in
s
.
transition
(
to
:
s
.
viewControllers
[
index
],
isTriggeredByUserInteraction
:
isTriggeredByUserInteraction
)
{
[
weak
self
]
(
isFinishing
)
in
guard
isFinishing
else
{
return
}
...
...
@@ -410,34 +427,18 @@ extension TabsController {
self
?
.
selectedIndex
=
index
}
}
return
true
}
}
extension
TabsController
:
TabBarDelegate
,
_TabBarDelegate
{
extension
TabsController
:
_TabBarDelegate
{
@objc
func
_tabBar
(
tabBar
:
TabBar
,
willSelect
tabItem
:
TabItem
)
{
guard
!
(
false
==
tabBar
.
delegate
?
.
tabBar
?(
tabBar
:
tabBar
,
shouldSelect
:
tabItem
))
else
{
return
}
func
_tabBar
(
tabBar
:
TabBar
,
shouldSelect
tabItem
:
TabItem
)
->
Bool
{
guard
let
i
=
tabBar
.
tabItems
.
index
(
of
:
tabItem
)
else
{
return
}
guard
i
!=
selectedIndex
else
{
return
}
guard
!
(
false
==
delegate
?
.
tabsController
?(
tabsController
:
self
,
shouldSelect
:
viewControllers
[
i
]))
else
{
return
return
false
}
transition
(
to
:
viewControllers
[
i
],
isTriggeredByUserInteraction
:
true
)
{
[
weak
self
]
(
isFinishing
)
in
guard
isFinishing
else
{
return
}
self
?
.
selectedIndex
=
i
}
return
internalSelect
(
at
:
i
,
isTriggeredByUserInteraction
:
true
)
}
}
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