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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
14 deletions
+48
-14
Sources/iOS/NavigationController.swift
+48
-14
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,12 +174,37 @@ extension NavigationController: UINavigationBarDelegate {
...
@@ -158,12 +174,37 @@ 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
)
return
true
}
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
didPop
item
:
UINavigationItem
)
{
removeBackButton
(
from
:
item
)
}
}
internal
extension
NavigationController
{
/// Handler for the backbutton.
@objc
func
handle
(
backButton
:
UIButton
)
{
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
{
if
nil
==
item
.
backButton
.
image
&&
nil
==
item
.
backButton
.
title
{
item
.
backButton
.
image
=
v
.
backButtonImage
item
.
backButton
.
image
=
v
.
backButtonImage
}
}
if
!
item
.
backButton
.
isHidden
{
if
!
item
.
backButton
.
isHidden
&&
!
item
.
leftViews
.
contains
(
item
.
backButton
)
{
item
.
leftViews
.
insert
(
item
.
backButton
,
at
:
0
)
item
.
leftViews
.
insert
(
item
.
backButton
,
at
:
0
)
}
}
...
@@ -175,10 +216,11 @@ extension NavigationController: UINavigationBarDelegate {
...
@@ -175,10 +216,11 @@ extension NavigationController: UINavigationBarDelegate {
v
.
layoutNavigationItem
(
item
:
item
)
v
.
layoutNavigationItem
(
item
:
item
)
}
}
return
true
/**
}
Removes back button of the navigation item.
- Parameter from item: A UINavigationItem.
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
didPop
item
:
UINavigationItem
)
{
*/
func
removeBackButton
(
from
item
:
UINavigationItem
)
{
if
let
index
=
item
.
leftViews
.
index
(
of
:
item
.
backButton
)
{
if
let
index
=
item
.
leftViews
.
index
(
of
:
item
.
backButton
)
{
item
.
leftViews
.
remove
(
at
:
index
)
item
.
leftViews
.
remove
(
at
:
index
)
}
}
...
@@ -187,14 +229,6 @@ extension NavigationController: UINavigationBarDelegate {
...
@@ -187,14 +229,6 @@ extension NavigationController: UINavigationBarDelegate {
}
}
}
}
internal
extension
NavigationController
{
/// Handler for the backbutton.
@objc
func
handle
(
backButton
:
UIButton
)
{
popViewController
(
animated
:
true
)
}
}
extension
NavigationController
:
UIGestureRecognizerDelegate
{
extension
NavigationController
:
UIGestureRecognizerDelegate
{
/**
/**
Detects the gesture recognizer being used. This is necessary when using
Detects the gesture recognizer being used. This is necessary when using
...
...
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