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
0cd62140
Commit
0cd62140
authored
Oct 25, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed backButton issues with navigation bar show/hide
parent
cf36b57f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
22 deletions
+56
-22
Sources/iOS/NavigationController.swift
+56
-22
No files found.
Sources/iOS/NavigationController.swift
View file @
0cd62140
...
@@ -146,6 +146,22 @@ open class NavigationController: UINavigationController {
...
@@ -146,6 +146,22 @@ open class NavigationController: UINavigationController {
navigationBar
.
setNeedsLayout
()
navigationBar
.
setNeedsLayout
()
navigationBar
.
layoutIfNeeded
()
navigationBar
.
layoutIfNeeded
()
}
}
/**
Sets whether the navigation bar is hidden.
- Parameter _ hidden: Specify true to hide the navigation bar or false to show it.
- Parameter animated: Specify true if you want to animate the change in visibility or false if you want the navigation bar to appear immediately.
*/
open
override
func
setNavigationBarHidden
(
_
hidden
:
Bool
,
animated
:
Bool
)
{
super
.
setNavigationBarHidden
(
hidden
,
animated
:
animated
)
guard
let
items
=
navigationBar
.
items
,
items
.
count
>
1
else
{
return
}
items
.
forEach
{
prepareBackButton
(
for
:
$0
,
in
:
navigationBar
)
}
}
}
}
extension
NavigationController
:
UINavigationBarDelegate
{
extension
NavigationController
:
UINavigationBarDelegate
{
...
@@ -158,32 +174,12 @@ extension NavigationController: UINavigationBarDelegate {
...
@@ -158,32 +174,12 @@ extension NavigationController: UINavigationBarDelegate {
True is yes, false is no.
True is yes, false is no.
*/
*/
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
shouldPush
item
:
UINavigationItem
)
->
Bool
{
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
shouldPush
item
:
UINavigationItem
)
->
Bool
{
if
let
v
=
navigationBar
as?
NavigationBar
{
prepareBackButton
(
for
:
item
,
in
:
navigationBar
)
if
nil
==
item
.
backButton
.
image
&&
nil
==
item
.
backButton
.
title
{
item
.
backButton
.
image
=
v
.
backButtonImage
}
if
!
item
.
backButton
.
isHidden
{
item
.
leftViews
.
insert
(
item
.
backButton
,
at
:
0
)
}
item
.
backButton
.
addTarget
(
self
,
action
:
#selector(
handle(backButton:)
)
,
for
:
.
touchUpInside
)
item
.
hidesBackButton
=
false
item
.
setHidesBackButton
(
true
,
animated
:
false
)
v
.
layoutNavigationItem
(
item
:
item
)
}
return
true
return
true
}
}
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
didPop
item
:
UINavigationItem
)
{
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
didPop
item
:
UINavigationItem
)
{
if
let
index
=
item
.
leftViews
.
index
(
of
:
item
.
backButton
)
{
removeBackButton
(
from
:
item
)
item
.
leftViews
.
remove
(
at
:
index
)
}
item
.
backButton
.
removeTarget
(
self
,
action
:
#selector(
handle(backButton:)
)
,
for
:
.
touchUpInside
)
}
}
}
}
...
@@ -193,6 +189,44 @@ internal extension NavigationController {
...
@@ -193,6 +189,44 @@ internal extension NavigationController {
func
handle
(
backButton
:
UIButton
)
{
func
handle
(
backButton
:
UIButton
)
{
popViewController
(
animated
:
true
)
popViewController
(
animated
:
true
)
}
}
/**
Prepares back button of the navigation item in navigation bar.
- Parameter for item: A UINavigationItem.
- Parameter in navigationBar: A UINavigationBar.
*/
func
prepareBackButton
(
for
item
:
UINavigationItem
,
in
navigationBar
:
UINavigationBar
)
{
guard
let
v
=
navigationBar
as?
NavigationBar
else
{
return
}
if
nil
==
item
.
backButton
.
image
&&
nil
==
item
.
backButton
.
title
{
item
.
backButton
.
image
=
v
.
backButtonImage
}
if
!
item
.
backButton
.
isHidden
&&
!
item
.
leftViews
.
contains
(
item
.
backButton
)
{
item
.
leftViews
.
insert
(
item
.
backButton
,
at
:
0
)
}
item
.
backButton
.
addTarget
(
self
,
action
:
#selector(
handle(backButton:)
)
,
for
:
.
touchUpInside
)
item
.
hidesBackButton
=
false
item
.
setHidesBackButton
(
true
,
animated
:
false
)
v
.
layoutNavigationItem
(
item
:
item
)
}
/**
Removes back button of the navigation item.
- Parameter from item: A UINavigationItem.
*/
func
removeBackButton
(
from
item
:
UINavigationItem
)
{
if
let
index
=
item
.
leftViews
.
index
(
of
:
item
.
backButton
)
{
item
.
leftViews
.
remove
(
at
:
index
)
}
item
.
backButton
.
removeTarget
(
self
,
action
:
#selector(
handle(backButton:)
)
,
for
:
.
touchUpInside
)
}
}
}
extension
NavigationController
:
UIGestureRecognizerDelegate
{
extension
NavigationController
:
UIGestureRecognizerDelegate
{
...
...
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