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
56da8682
Unverified
Commit
56da8682
authored
Jan 08, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated BottomSheetController tap detection to account for FABButton
parent
82564ad0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
78 deletions
+114
-78
Sources/iOS/BottomSheetController.swift
+113
-78
Sources/iOS/HeightPreset.swift
+1
-0
No files found.
Sources/iOS/BottomSheetController.swift
View file @
56da8682
...
@@ -37,6 +37,12 @@ public enum BottomSheetFABButtonPosition: Int {
...
@@ -37,6 +37,12 @@ public enum BottomSheetFABButtonPosition: Int {
case
center
case
center
}
}
@objc(BottomSheetLayoutStyle)
public
enum
BottomSheetLayoutStyle
:
Int
{
case
persistent
case
modal
}
open
class
BottomSheet
:
View
{
open
class
BottomSheet
:
View
{
/// A reference to a FABButton.
/// A reference to a FABButton.
open
var
fabButton
:
FABButton
?
{
open
var
fabButton
:
FABButton
?
{
...
@@ -137,76 +143,70 @@ public protocol BottomSheetControllerDelegate {
...
@@ -137,76 +143,70 @@ public protocol BottomSheetControllerDelegate {
/**
/**
An optional delegation method that is fired before the
An optional delegation method that is fired before the
BottomSheetController opens.
BottomSheetController opens.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
*/
*/
@objc
@objc
optional
func
bottom
SheetControllerWillOpen
(
bottomSheet
Controller
:
BottomSheetController
)
optional
func
bottom
ViewControllerWillOpen
(
bottomView
Controller
:
BottomSheetController
)
/**
/**
An optional delegation method that is fired after the
An optional delegation method that is fired after the
BottomSheetController opened.
BottomSheetController opened.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
*/
*/
@objc
@objc
optional
func
bottom
SheetControllerDidOpen
(
bottomSheet
Controller
:
BottomSheetController
)
optional
func
bottom
ViewControllerDidOpen
(
bottomView
Controller
:
BottomSheetController
)
/**
/**
An optional delegation method that is fired before the
An optional delegation method that is fired before the
BottomSheetController closes.
BottomSheetController closes.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
*/
*/
@objc
@objc
optional
func
bottom
SheetControllerWillClose
(
bottomSheet
Controller
:
BottomSheetController
)
optional
func
bottom
ViewControllerWillClose
(
bottomView
Controller
:
BottomSheetController
)
/**
/**
An optional delegation method that is fired after the
An optional delegation method that is fired after the
BottomSheetController closed.
BottomSheetController closed.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
*/
*/
@objc
@objc
optional
func
bottom
SheetControllerDidClose
(
bottomSheet
Controller
:
BottomSheetController
)
optional
func
bottom
ViewControllerDidClose
(
bottomView
Controller
:
BottomSheetController
)
/**
/**
An optional delegation method that is fired when the
An optional delegation method that is fired when the
BottomSheetController pan gesture begins.
BottomSheetController pan gesture begins.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
- Parameter didBeginPanAt point: A CGPoint.
- Parameter didBeginPanAt point: A CGPoint.
*/
*/
@objc
@objc
optional
func
bottom
SheetController
(
bottomSheet
Controller
:
BottomSheetController
,
didBeginPanAt
point
:
CGPoint
)
optional
func
bottom
ViewController
(
bottomView
Controller
:
BottomSheetController
,
didBeginPanAt
point
:
CGPoint
)
/**
/**
An optional delegation method that is fired when the
An optional delegation method that is fired when the
BottomSheetController pan gesture changes position.
BottomSheetController pan gesture changes position.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
- Parameter didChangePanAt point: A CGPoint.
- Parameter didChangePanAt point: A CGPoint.
*/
*/
@objc
@objc
optional
func
bottom
SheetController
(
bottomSheet
Controller
:
BottomSheetController
,
didChangePanAt
point
:
CGPoint
)
optional
func
bottom
ViewController
(
bottomView
Controller
:
BottomSheetController
,
didChangePanAt
point
:
CGPoint
)
/**
/**
An optional delegation method that is fired when the
An optional delegation method that is fired when the
BottomSheetController pan gesture ends.
BottomSheetController pan gesture ends.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
- Parameter didEndPanAt point: A CGPoint.
- Parameter didEndPanAt point: A CGPoint.
*/
*/
@objc
@objc
optional
func
bottom
SheetController
(
bottomSheet
Controller
:
BottomSheetController
,
didEndPanAt
point
:
CGPoint
)
optional
func
bottom
ViewController
(
bottomView
Controller
:
BottomSheetController
,
didEndPanAt
point
:
CGPoint
)
/**
/**
An optional delegation method that is fired when the
An optional delegation method that is fired when the
BottomSheetController tap gesture executes.
BottomSheetController tap gesture executes.
- Parameter bottom
Sheet
Controller: A BottomSheetController.
- Parameter bottom
View
Controller: A BottomSheetController.
- Parameter didTapAt point: A CGPoint.
- Parameter didTapAt point: A CGPoint.
*/
*/
@objc
@objc
optional
func
bottomSheetController
(
bottomSheetController
:
BottomSheetController
,
didTapAt
point
:
CGPoint
)
optional
func
bottomViewController
(
bottomViewController
:
BottomSheetController
,
didTapAt
point
:
CGPoint
)
}
@objc(BottomSheetLayoutStyle)
public
enum
BottomSheetLayoutStyle
:
Int
{
case
flat
case
hover
}
}
@objc(BottomSheetController)
@objc(BottomSheetController)
...
@@ -219,26 +219,40 @@ open class BottomSheetController: RootController {
...
@@ -219,26 +219,40 @@ open class BottomSheetController: RootController {
/**
/**
A UIPanGestureRecognizer property internally used for the
A UIPanGestureRecognizer property internally used for the
bottom
View
pan gesture.
bottom
Sheet
pan gesture.
*/
*/
internal
fileprivate
(
set
)
var
bottomPanGesture
:
UIPanGestureRecognizer
?
internal
fileprivate
(
set
)
var
bottomPanGesture
:
UIPanGestureRecognizer
?
/**
/**
A UITapGestureRecognizer property internally used for the
A UITapGestureRecognizer property internally used for the
bottom
View
tap gesture.
bottom
Sheet
tap gesture.
*/
*/
internal
fileprivate
(
set
)
var
bottomTapGesture
:
UITapGestureRecognizer
?
internal
fileprivate
(
set
)
var
bottomTapGesture
:
UITapGestureRecognizer
?
/**
/**
A CGFloat property that accesses the bottom
View
threshold of
A CGFloat property that accesses the bottom
Sheet
threshold of
the BottomSheetController. When the panning gesture has
the BottomSheetController. When the panning gesture has
ended, if the position is beyond the threshold,
ended, if the position is beyond the threshold,
the bottom
View
is opened, if it is below the threshold, the
the bottom
Sheet
is opened, if it is below the threshold, the
bottom
View
is closed.
bottom
Sheet
is closed.
*/
*/
@IBInspectable
@IBInspectable
open
var
bottomThreshold
:
CGFloat
=
64
open
var
bottomThreshold
:
CGFloat
=
64
fileprivate
var
bottomViewThreshold
:
CGFloat
=
0
fileprivate
var
bottomSheetThreshold
:
CGFloat
=
0
/// A preset for bottomSheetClosedHeight.
open
var
bottomSheetClosedHeightPreset
=
HeightPreset
.
none
{
didSet
{
bottomSheetClosedHeight
=
CGFloat
(
bottomSheetClosedHeightPreset
.
rawValue
)
}
}
/// The height the BottomSheet should leave open when a FABButton exists.
open
var
bottomSheetClosedHeight
:
CGFloat
=
0
{
didSet
{
layoutSubviews
()
}
}
/**
/**
A BottomSheetControllerDelegate property used to bind
A BottomSheetControllerDelegate property used to bind
...
@@ -248,13 +262,13 @@ open class BottomSheetController: RootController {
...
@@ -248,13 +262,13 @@ open class BottomSheetController: RootController {
/**
/**
A CGFloat property that sets the animation duration of the
A CGFloat property that sets the animation duration of the
bottom
View
when closing and opening. Defaults to 0.25.
bottom
Sheet
when closing and opening. Defaults to 0.25.
*/
*/
@IBInspectable
@IBInspectable
open
var
animationDuration
:
TimeInterval
=
0.25
open
var
animationDuration
:
TimeInterval
=
0.25
/**
/**
A Boolean property that enables and disables the bottom
View
from
A Boolean property that enables and disables the bottom
Sheet
from
opening and closing. Defaults to true.
opening and closing. Defaults to true.
*/
*/
@IBInspectable
@IBInspectable
...
@@ -268,7 +282,7 @@ open class BottomSheetController: RootController {
...
@@ -268,7 +282,7 @@ open class BottomSheetController: RootController {
}
}
/**
/**
A Boolean property that enables and disables the bottom
View
from
A Boolean property that enables and disables the bottom
Sheet
from
opening and closing. Defaults to true.
opening and closing. Defaults to true.
*/
*/
@IBInspectable
@IBInspectable
...
@@ -305,7 +319,7 @@ open class BottomSheetController: RootController {
...
@@ -305,7 +319,7 @@ open class BottomSheetController: RootController {
/**
/**
A DepthPreset property that is used to set the depth of the
A DepthPreset property that is used to set the depth of the
bottom
View
when opened.
bottom
Sheet
when opened.
*/
*/
open
var
depthPreset
=
DepthPreset
.
depth1
open
var
depthPreset
=
DepthPreset
.
depth1
...
@@ -316,12 +330,12 @@ open class BottomSheetController: RootController {
...
@@ -316,12 +330,12 @@ open class BottomSheetController: RootController {
*/
*/
open
let
bottomSheet
=
BottomSheet
()
open
let
bottomSheet
=
BottomSheet
()
/// Indicates whether the bottom
View
or rightView is opened.
/// Indicates whether the bottom
Sheet
or rightView is opened.
open
var
isOpened
:
Bool
{
open
var
isOpened
:
Bool
{
return
isBottomSheetOpened
return
isBottomSheetOpened
}
}
/// indicates if the bottom
View
is opened.
/// indicates if the bottom
Sheet
is opened.
open
var
isBottomSheetOpened
:
Bool
{
open
var
isBottomSheetOpened
:
Bool
{
return
bottomSheet
.
y
!=
Screen
.
height
return
bottomSheet
.
y
!=
Screen
.
height
}
}
...
@@ -333,21 +347,21 @@ open class BottomSheetController: RootController {
...
@@ -333,21 +347,21 @@ open class BottomSheetController: RootController {
open
fileprivate
(
set
)
var
bottomViewController
:
UIViewController
?
open
fileprivate
(
set
)
var
bottomViewController
:
UIViewController
?
/**
/**
A CGFloat property to access the width that the bottom
View
A CGFloat property to access the width that the bottom
Sheet
opens up to.
opens up to.
*/
*/
@IBInspectable
@IBInspectable
open
fileprivate
(
set
)
var
bottom
View
Height
:
CGFloat
!
open
fileprivate
(
set
)
var
bottom
Sheet
Height
:
CGFloat
!
/// Determines the layout style for the bottomSheet.
/// Determines the layout style for the bottomSheet.
open
var
bottomSheet
LayoutStyle
=
BottomSheetLayoutStyle
.
hover
{
open
var
bottomSheet
Style
=
BottomSheetLayoutStyle
.
modal
{
didSet
{
didSet
{
switch
bottomSheet
Layout
Style
{
switch
bottomSheetStyle
{
case
.
hover
:
case
.
modal
:
depthPreset
=
.
depth1
depthPreset
=
.
depth1
case
.
fla
t
:
case
.
persisten
t
:
depthPreset
=
.
none
depthPreset
=
.
none
openBottomSheet
()
layoutSubviews
()
isBottomSheetEnabled
=
false
isBottomSheetEnabled
=
false
}
}
}
}
...
@@ -387,18 +401,20 @@ open class BottomSheetController: RootController {
...
@@ -387,18 +401,20 @@ open class BottomSheetController: RootController {
open
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
bottomSheet
.
width
=
view
.
bounds
.
width
bottomSheet
.
width
=
view
.
bounds
.
width
bottomSheet
.
height
=
bottom
View
Height
bottomSheet
.
height
=
bottom
Sheet
Height
bottom
ViewThreshold
=
view
.
bounds
.
height
-
bottomView
Height
/
2
bottom
SheetThreshold
=
view
.
bounds
.
height
-
bottomSheet
Height
/
2
rootViewController
.
view
.
height
=
view
.
bounds
.
height
-
bottomViewHeight
if
.
persistent
==
bottomSheetStyle
{
rootViewController
.
view
.
height
=
view
.
bounds
.
height
-
bottomSheetHeight
}
guard
let
vc
=
bottomViewController
else
{
guard
let
vc
=
bottomViewController
else
{
return
return
}
}
vc
.
view
.
width
=
bottomSheet
.
bounds
.
width
vc
.
view
.
width
=
bottomSheet
.
bounds
.
width
vc
.
view
.
height
=
bottom
View
Height
vc
.
view
.
height
=
bottom
Sheet
Height
vc
.
view
.
center
=
CGPoint
(
x
:
bottomSheet
.
bounds
.
width
/
2
,
y
:
bottom
View
Height
/
2
)
vc
.
view
.
center
=
CGPoint
(
x
:
bottomSheet
.
bounds
.
width
/
2
,
y
:
bottom
Sheet
Height
/
2
)
}
}
/**
/**
...
@@ -411,20 +427,21 @@ open class BottomSheetController: RootController {
...
@@ -411,20 +427,21 @@ open class BottomSheetController: RootController {
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
prepareBottomSheet
()
prepareBottomSheet
()
bottomSheetClosedHeightPreset
=
.
normal
}
}
/**
/**
A method that is used to set the width of the bottom
View
when
A method that is used to set the width of the bottom
Sheet
when
opened. This is the recommended method of setting the bottom
View
opened. This is the recommended method of setting the bottom
Sheet
width.
width.
- Parameter width: A CGFloat value to set as the new width.
- Parameter width: A CGFloat value to set as the new width.
- Parameter isHidden: A Boolean value of whether the bottom
View
- Parameter isHidden: A Boolean value of whether the bottom
Sheet
should be isHidden after the width has been updated or not.
should be isHidden after the width has been updated or not.
- Parameter animated: A Boolean value that indicates to animate
- Parameter animated: A Boolean value that indicates to animate
the bottom
View
width change.
the bottom
Sheet
width change.
*/
*/
open
func
setBottomSheetHeight
(
height
:
CGFloat
,
isHidden
:
Bool
,
animated
:
Bool
,
duration
:
TimeInterval
=
0.5
)
{
open
func
setBottomSheetHeight
(
height
:
CGFloat
,
isHidden
:
Bool
,
animated
:
Bool
,
duration
:
TimeInterval
=
0.5
)
{
bottom
View
Height
=
height
bottom
Sheet
Height
=
height
if
animated
{
if
animated
{
bottomSheet
.
isShadowPathAutoSizing
=
false
bottomSheet
.
isShadowPathAutoSizing
=
false
...
@@ -489,21 +506,21 @@ open class BottomSheetController: RootController {
...
@@ -489,21 +506,21 @@ open class BottomSheetController: RootController {
}
}
/**
/**
A method that toggles the bottom
View
opened if previously closed,
A method that toggles the bottom
Sheet
opened if previously closed,
or closed if previously opened.
or closed if previously opened.
- Parameter velocity: A CGFloat value that sets the
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
velocity of the user interaction when animating the
bottom
View
. Defaults to 0.
bottom
Sheet
. Defaults to 0.
*/
*/
open
func
toggleBottomSheet
(
velocity
:
CGFloat
=
0
)
{
open
func
toggleBottomSheet
(
velocity
:
CGFloat
=
0
)
{
isBottomSheetOpened
?
closeBottomSheet
(
velocity
:
velocity
)
:
openBottomSheet
(
velocity
:
velocity
)
isBottomSheetOpened
?
closeBottomSheet
(
velocity
:
velocity
)
:
openBottomSheet
(
velocity
:
velocity
)
}
}
/**
/**
A method that opens the bottom
View
.
A method that opens the bottom
Sheet
.
- Parameter velocity: A CGFloat value that sets the
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
velocity of the user interaction when animating the
bottom
View
. Defaults to 0.
bottom
Sheet
. Defaults to 0.
*/
*/
open
func
openBottomSheet
(
velocity
:
CGFloat
=
0
)
{
open
func
openBottomSheet
(
velocity
:
CGFloat
=
0
)
{
guard
isBottomSheetEnabled
else
{
guard
isBottomSheetEnabled
else
{
...
@@ -514,7 +531,7 @@ open class BottomSheetController: RootController {
...
@@ -514,7 +531,7 @@ open class BottomSheetController: RootController {
isUserInteractionEnabled
=
false
isUserInteractionEnabled
=
false
delegate
?
.
bottom
SheetControllerWillOpen
?(
bottomSheet
Controller
:
self
)
delegate
?
.
bottom
ViewControllerWillOpen
?(
bottomView
Controller
:
self
)
UIView
.
animate
(
withDuration
:
TimeInterval
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
bottomSheet
.
y
/
velocity
)))),
UIView
.
animate
(
withDuration
:
TimeInterval
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
bottomSheet
.
y
/
velocity
)))),
animations
:
{
[
weak
self
,
v
=
bottomSheet
]
in
animations
:
{
[
weak
self
,
v
=
bottomSheet
]
in
...
@@ -524,7 +541,7 @@ open class BottomSheetController: RootController {
...
@@ -524,7 +541,7 @@ open class BottomSheetController: RootController {
v
.
position
.
y
=
s
.
view
.
bounds
.
height
-
v
.
bounds
.
height
/
2
v
.
position
.
y
=
s
.
view
.
bounds
.
height
-
v
.
bounds
.
height
/
2
if
.
hover
==
s
.
bottomSheetLayou
tStyle
{
if
.
modal
==
s
.
bottomShee
tStyle
{
s
.
rootViewController
.
view
.
alpha
=
0.5
s
.
rootViewController
.
view
.
alpha
=
0.5
}
}
})
{
[
weak
self
]
_
in
})
{
[
weak
self
]
_
in
...
@@ -532,15 +549,15 @@ open class BottomSheetController: RootController {
...
@@ -532,15 +549,15 @@ open class BottomSheetController: RootController {
return
return
}
}
s
.
delegate
?
.
bottom
SheetControllerDidOpen
?(
bottomSheet
Controller
:
s
)
s
.
delegate
?
.
bottom
ViewControllerDidOpen
?(
bottomView
Controller
:
s
)
}
}
}
}
/**
/**
A method that closes the bottom
View
.
A method that closes the bottom
Sheet
.
- Parameter velocity: A CGFloat value that sets the
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
velocity of the user interaction when animating the
bottom
View
. Defaults to 0.
bottom
Sheet
. Defaults to 0.
*/
*/
open
func
closeBottomSheet
(
velocity
:
CGFloat
=
0
)
{
open
func
closeBottomSheet
(
velocity
:
CGFloat
=
0
)
{
guard
isBottomSheetEnabled
else
{
guard
isBottomSheetEnabled
else
{
...
@@ -549,7 +566,7 @@ open class BottomSheetController: RootController {
...
@@ -549,7 +566,7 @@ open class BottomSheetController: RootController {
isUserInteractionEnabled
=
true
isUserInteractionEnabled
=
true
delegate
?
.
bottom
SheetControllerWillClose
?(
bottomSheet
Controller
:
self
)
delegate
?
.
bottom
ViewControllerWillClose
?(
bottomView
Controller
:
self
)
UIView
.
animate
(
withDuration
:
TimeInterval
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
bottomSheet
.
y
/
velocity
)))),
UIView
.
animate
(
withDuration
:
TimeInterval
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
bottomSheet
.
y
/
velocity
)))),
animations
:
{
[
weak
self
,
v
=
bottomSheet
]
in
animations
:
{
[
weak
self
,
v
=
bottomSheet
]
in
...
@@ -557,9 +574,21 @@ open class BottomSheetController: RootController {
...
@@ -557,9 +574,21 @@ open class BottomSheetController: RootController {
return
return
}
}
v
.
position
.
y
=
s
.
view
.
bounds
.
height
+
v
.
bounds
.
height
/
2
let
h
=
s
.
view
.
bounds
.
height
let
p
=
s
.
bottomSheetHeight
/
2
v
.
position
.
y
=
h
+
p
// if nil == s.bottomSheet.fabButton {
// v.position.y = h + p
// } else {
// let y = v.position.y
// let q = s.bottomSheetClosedHeight / 2
// print(h, p, y, q)
// v.position.y = y > q ? q : h + p
// }
if
.
hover
==
s
.
bottomSheetLayou
tStyle
{
if
.
modal
==
s
.
bottomShee
tStyle
{
s
.
rootViewController
.
view
.
alpha
=
1
s
.
rootViewController
.
view
.
alpha
=
1
}
}
})
{
[
weak
self
,
v
=
bottomSheet
]
_
in
})
{
[
weak
self
,
v
=
bottomSheet
]
_
in
...
@@ -569,11 +598,11 @@ open class BottomSheetController: RootController {
...
@@ -569,11 +598,11 @@ open class BottomSheetController: RootController {
s
.
hideView
(
container
:
v
)
s
.
hideView
(
container
:
v
)
s
.
delegate
?
.
bottom
SheetControllerDidClose
?(
bottomSheet
Controller
:
s
)
s
.
delegate
?
.
bottom
ViewControllerDidClose
?(
bottomView
Controller
:
s
)
}
}
}
}
/// A method that removes the passed in pan and bottom
View
tap gesture recognizers.
/// A method that removes the passed in pan and bottom
Sheet
tap gesture recognizers.
fileprivate
func
removeBottomSheetGestures
()
{
fileprivate
func
removeBottomSheetGestures
()
{
removeBottomPanGesture
()
removeBottomPanGesture
()
removeBottomTapGesture
()
removeBottomTapGesture
()
...
@@ -601,7 +630,7 @@ open class BottomSheetController: RootController {
...
@@ -601,7 +630,7 @@ open class BottomSheetController: RootController {
/**
/**
A method that determines whether the passed point is
A method that determines whether the passed point is
contained within the bounds of the bottom
View
Threshold
contained within the bounds of the bottom
Sheet
Threshold
and height of the BottomSheetController view frame
and height of the BottomSheetController view frame
property.
property.
- Parameter point: A CGPoint to test against.
- Parameter point: A CGPoint to test against.
...
@@ -623,7 +652,13 @@ open class BottomSheetController: RootController {
...
@@ -623,7 +652,13 @@ open class BottomSheetController: RootController {
otherwise.
otherwise.
*/
*/
fileprivate
func
isPointContainedWithinView
(
container
:
UIView
,
point
:
CGPoint
)
->
Bool
{
fileprivate
func
isPointContainedWithinView
(
container
:
UIView
,
point
:
CGPoint
)
->
Bool
{
return
container
.
bounds
.
contains
(
point
)
let
result
=
container
.
bounds
.
contains
(
point
)
guard
false
==
result
,
let
v
=
bottomSheet
.
fabButton
else
{
return
result
}
return
v
.
bounds
.
contains
(
v
.
convert
(
point
,
from
:
container
))
}
}
/**
/**
...
@@ -651,15 +686,15 @@ extension BottomSheetController {
...
@@ -651,15 +686,15 @@ extension BottomSheetController {
prepare
(
viewController
:
bottomViewController
,
withContainer
:
bottomSheet
)
prepare
(
viewController
:
bottomViewController
,
withContainer
:
bottomSheet
)
}
}
/// A method that prepares the bottom
View
.
/// A method that prepares the bottom
Sheet
.
fileprivate
func
prepareBottomSheet
()
{
fileprivate
func
prepareBottomSheet
()
{
bottom
View
Height
=
.
phone
==
Device
.
userInterfaceIdiom
?
280
:
320
bottom
Sheet
Height
=
.
phone
==
Device
.
userInterfaceIdiom
?
280
:
320
view
.
addSubview
(
bottomSheet
)
view
.
addSubview
(
bottomSheet
)
bottomSheet
.
isHidden
=
true
bottomSheet
.
isHidden
=
true
bottomSheet
.
width
=
view
.
bounds
.
width
bottomSheet
.
width
=
view
.
bounds
.
width
bottomSheet
.
height
=
bottom
View
Height
bottomSheet
.
height
=
bottom
Sheet
Height
bottomSheet
.
position
.
y
=
view
.
bounds
.
height
+
bottom
View
Height
/
2
bottomSheet
.
position
.
y
=
view
.
bounds
.
height
+
bottom
Sheet
Height
/
2
bottomSheet
.
zPosition
=
2000
bottomSheet
.
zPosition
=
2000
guard
nil
!=
bottomViewController
else
{
guard
nil
!=
bottomViewController
else
{
...
@@ -716,7 +751,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
...
@@ -716,7 +751,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
/**
/**
A method that is fired when the pan gesture is recognized
A method that is fired when the pan gesture is recognized
for the bottom
View
.
for the bottom
Sheet
.
- Parameter recognizer: A UIPanGestureRecognizer that is
- Parameter recognizer: A UIPanGestureRecognizer that is
passed to the handler when recognized.
passed to the handler when recognized.
*/
*/
...
@@ -734,7 +769,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
...
@@ -734,7 +769,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
originalY
=
bottomSheet
.
position
.
y
originalY
=
bottomSheet
.
position
.
y
showView
(
container
:
bottomSheet
)
showView
(
container
:
bottomSheet
)
delegate
?
.
bottom
SheetController
?(
bottomSheet
Controller
:
self
,
didBeginPanAt
:
point
)
delegate
?
.
bottom
ViewController
?(
bottomView
Controller
:
self
,
didBeginPanAt
:
point
)
case
.
changed
:
case
.
changed
:
let
h
=
bottomSheet
.
bounds
.
height
let
h
=
bottomSheet
.
bounds
.
height
let
translationY
=
recognizer
.
translation
(
in
:
bottomSheet
)
.
y
let
translationY
=
recognizer
.
translation
(
in
:
bottomSheet
)
.
y
...
@@ -744,14 +779,14 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
...
@@ -744,14 +779,14 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
let
a
=
1
-
(
view
.
bounds
.
height
-
bottomSheet
.
position
.
y
)
/
bottomSheet
.
bounds
.
height
let
a
=
1
-
(
view
.
bounds
.
height
-
bottomSheet
.
position
.
y
)
/
bottomSheet
.
bounds
.
height
rootViewController
.
view
.
alpha
=
0.5
<
a
&&
bottomSheet
.
position
.
y
>=
bottomSheet
.
bounds
.
height
/
2
?
a
:
0.5
rootViewController
.
view
.
alpha
=
0.5
<
a
&&
bottomSheet
.
position
.
y
>=
bottomSheet
.
bounds
.
height
/
2
?
a
:
0.5
delegate
?
.
bottom
SheetController
?(
bottomSheet
Controller
:
self
,
didChangePanAt
:
point
)
delegate
?
.
bottom
ViewController
?(
bottomView
Controller
:
self
,
didChangePanAt
:
point
)
case
.
ended
,
.
cancelled
,
.
failed
:
case
.
ended
,
.
cancelled
,
.
failed
:
let
p
=
recognizer
.
velocity
(
in
:
recognizer
.
view
)
let
p
=
recognizer
.
velocity
(
in
:
recognizer
.
view
)
let
y
=
p
.
y
>=
1000
||
p
.
y
<=
-
1000
?
p
.
y
:
0
let
y
=
p
.
y
>=
1000
||
p
.
y
<=
-
1000
?
p
.
y
:
0
delegate
?
.
bottom
SheetController
?(
bottomSheet
Controller
:
self
,
didEndPanAt
:
point
)
delegate
?
.
bottom
ViewController
?(
bottomView
Controller
:
self
,
didEndPanAt
:
point
)
if
bottomSheet
.
y
>=
bottom
View
Threshold
||
y
>
1000
{
if
bottomSheet
.
y
>=
bottom
Sheet
Threshold
||
y
>
1000
{
closeBottomSheet
(
velocity
:
y
)
closeBottomSheet
(
velocity
:
y
)
}
else
{
}
else
{
openBottomSheet
(
velocity
:
y
)
openBottomSheet
(
velocity
:
y
)
...
@@ -762,7 +797,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
...
@@ -762,7 +797,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
/**
/**
A method that is fired when the tap gesture is recognized
A method that is fired when the tap gesture is recognized
for the bottom
View
.
for the bottom
Sheet
.
- Parameter recognizer: A UITapGestureRecognizer that is
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
passed to the handler when recognized.
*/
*/
...
@@ -772,7 +807,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
...
@@ -772,7 +807,7 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
return
return
}
}
delegate
?
.
bottom
SheetController
?(
bottomSheet
Controller
:
self
,
didTapAt
:
recognizer
.
location
(
in
:
view
))
delegate
?
.
bottom
ViewController
?(
bottomView
Controller
:
self
,
didTapAt
:
recognizer
.
location
(
in
:
view
))
guard
isBottomSheetEnabled
&&
isBottomSheetOpened
&&
!
isPointContainedWithinView
(
container
:
bottomSheet
,
point
:
recognizer
.
location
(
in
:
bottomSheet
))
else
{
guard
isBottomSheetEnabled
&&
isBottomSheetOpened
&&
!
isPointContainedWithinView
(
container
:
bottomSheet
,
point
:
recognizer
.
location
(
in
:
bottomSheet
))
else
{
return
return
...
...
Sources/iOS/HeightPreset.swift
View file @
56da8682
...
@@ -32,6 +32,7 @@ import UIKit
...
@@ -32,6 +32,7 @@ import UIKit
@objc(HeightPreset)
@objc(HeightPreset)
public
enum
HeightPreset
:
Int
{
public
enum
HeightPreset
:
Int
{
case
none
=
0
case
tiny
=
20
case
tiny
=
20
case
xsmall
=
28
case
xsmall
=
28
case
small
=
36
case
small
=
36
...
...
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