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
18a4375b
Commit
18a4375b
authored
Jan 29, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
right panel for SideNav now supports pan gesture
parent
7a577efb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
77 deletions
+87
-77
Sources/SideNavigationViewController.swift
+87
-77
No files found.
Sources/SideNavigationViewController.swift
View file @
18a4375b
...
...
@@ -108,10 +108,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private
var
originalPosition
:
CGPoint
=
CGPointZero
/**
A
UI
View property that is used internally to track
the currentView,
either leftView or rightView.
A
Material
View property that is used internally to track
either leftView or rightView.
*/
private
var
currentView
:
UI
View
?
private
var
currentView
:
Material
View
?
/**
A UIPanGestureRecognizer property internally used for the
...
...
@@ -550,17 +550,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
public
func
openLeftView
(
velocity
:
CGFloat
=
0
)
{
if
enabledLeftView
{
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
if
let
v
:
MaterialView
=
leftView
{
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
currentView
=
v
delegate
?
.
sideNavigationViewWillOpen
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
v
.
x
/
velocity
)))),
animations
:
{
v
.
position
=
CGPointMake
(
v
.
width
/
2
,
v
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
false
self
.
show
LeftView
Depth
()
self
.
showDepth
()
self
.
delegate
?
.
sideNavigationViewDidOpen
?(
self
)
}
}
...
...
@@ -575,17 +576,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
public
func
openRightView
(
velocity
:
CGFloat
=
0
)
{
if
enabledRightView
{
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
if
let
v
:
MaterialView
=
rightView
{
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
currentView
=
v
delegate
?
.
sideNavigationViewWillOpen
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
v
.
x
/
velocity
)))),
animations
:
{
v
.
position
=
CGPointMake
(
self
.
view
.
bounds
.
width
-
v
.
width
/
2
,
v
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
false
self
.
show
RightView
Depth
()
self
.
showDepth
()
self
.
delegate
?
.
sideNavigationViewDidOpen
?(
self
)
}
}
...
...
@@ -610,8 +612,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
v
.
position
=
CGPointMake
(
-
v
.
width
/
2
,
v
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
true
self
.
hide
LeftView
Depth
()
self
.
hideDepth
()
self
.
delegate
?
.
sideNavigationViewDidClose
?(
self
)
self
.
currentView
=
nil
}
}
}
...
...
@@ -635,8 +638,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
v
.
position
=
CGPointMake
(
self
.
view
.
bounds
.
width
+
v
.
width
/
2
,
v
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
true
self
.
hide
RightView
Depth
()
self
.
hideDepth
()
self
.
delegate
?
.
sideNavigationViewDidClose
?(
self
)
self
.
currentView
=
nil
}
}
}
...
...
@@ -661,39 +665,73 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
passed to the handler when recognized.
*/
internal
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
enabled
{
switch
recognizer
.
state
{
case
.
Began
:
if
!
opened
{
if
isPointContainedWithinLeftViewThreshold
(
recognizer
.
locationInView
(
view
))
{
// Deterine which view to pan.
if
enabledRightView
&&
(
openedRightView
||
!
openedLeftView
&&
isPointContainedWithinRightViewThreshold
(
recognizer
.
locationInView
(
view
)))
{
currentView
=
rightView
if
let
v
:
MaterialView
=
currentView
{
// Animate the panel.
switch
recognizer
.
state
{
case
.
Began
:
backdropLayer
.
hidden
=
false
originalPosition
=
v
.
position
toggleStatusBar
(
true
)
showDepth
()
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
v
)
let
w
:
CGFloat
=
v
.
width
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
print
(
"OX
\(
self
.
originalPosition
.
x
)
TX
\(
translation
.
x
)
"
)
v
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
<
self
.
view
.
bounds
.
width
-
(
w
/
2
)
?
self
.
view
.
bounds
.
width
-
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
recognizer
.
locationInView
(
self
.
view
))
}
case
.
Ended
,
.
Cancelled
,
.
Failed
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
if
v
.
x
<=
CGFloat
(
floor
(
-
rightViewWidth
))
+
rightViewThreshold
||
point
.
x
<=
-
1000
{
closeRightView
(
x
)
}
else
{
openRightView
(
x
)
}
case
.
Possible
:
break
}
backdropLayer
.
hidden
=
false
originalPosition
=
leftView
!.
position
toggleStatusBar
(
true
)
showLeftViewDepth
()
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
leftView
)
let
w
:
CGFloat
=
leftView
!.
width
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
leftView
!.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
recognizer
.
locationInView
(
self
.
view
))
}
case
.
Ended
,
.
Cancelled
,
.
Failed
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
if
leftView
!.
x
<=
CGFloat
(
floor
(
-
leftViewWidth
))
+
leftViewThreshold
||
point
.
x
<=
-
1000
{
closeLeftView
(
x
)
}
else
{
openLeftView
(
x
)
}
}
else
if
enabledLeftView
{
currentView
=
leftView
if
let
v
:
MaterialView
=
currentView
{
// Animate the panel.
switch
recognizer
.
state
{
case
.
Began
:
backdropLayer
.
hidden
=
false
originalPosition
=
v
.
position
toggleStatusBar
(
true
)
showDepth
()
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
v
)
let
w
:
CGFloat
=
v
.
width
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
v
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
recognizer
.
locationInView
(
self
.
view
))
}
case
.
Ended
,
.
Cancelled
,
.
Failed
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
recognizer
.
locationInView
(
view
))
if
v
.
x
<=
CGFloat
(
floor
(
-
leftViewWidth
))
+
leftViewThreshold
||
point
.
x
<=
-
1000
{
closeLeftView
(
x
)
}
else
{
openLeftView
(
x
)
}
case
.
Possible
:
break
}
case
.
Possible
:
break
}
}
}
...
...
@@ -898,46 +936,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
return
CGRectContainsPoint
(
container
.
frame
,
point
)
}
/**
A method that adds the depth to the leftView depth property.
*/
private
func
showLeftViewDepth
()
{
if
let
v
:
MaterialView
=
leftView
{
/// A method that adds the depth to the currentView.
private
func
showDepth
()
{
if
let
v
:
MaterialView
=
currentView
{
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
v
.
depth
=
self
.
depth
}
}
}
/**
A method that adds the depth to the rightView depth property.
*/
private
func
showRightViewDepth
()
{
if
let
v
:
MaterialView
=
rightView
{
MaterialAnimation
.
animationDisabled
{
v
.
depth
=
self
.
depth
}
}
}
/**
A method that removes the depth from the leftView depth
property.
*/
private
func
hideLeftViewDepth
()
{
if
let
v
:
MaterialView
=
leftView
{
MaterialAnimation
.
animationDisabled
{
v
.
depth
=
.
None
}
}
}
/**
A method that removes the depth from the rightView depth
property.
*/
private
func
hideRightViewDepth
()
{
if
let
v
:
MaterialView
=
rightView
{
/// A method that removes the depth from the currentView.
private
func
hideDepth
()
{
if
let
v
:
MaterialView
=
currentView
{
MaterialAnimation
.
animationDisabled
{
v
.
depth
=
.
None
}
...
...
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