Skip to content

Commit

Permalink
Fixed drag.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Feb 9, 2022
1 parent 74559e6 commit 4360085
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/ivanvorobei/SparrowKit",
"state": {
"branch": null,
"revision": "df2ba76dd6a27dfe721a193bb3a7888e311693d1",
"version": "3.5.1"
"revision": "f872b45a3e6aa5e2833ac8d3050a3f026d97ce0b",
"version": "3.5.2"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<key>tvOS Example.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>2</integer>
</dict>
<key>watchOS Example.xcscheme_^#shared#^_</key>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion SPIndicator.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'SPIndicator'
s.version = '1.6.3'
s.version = '1.6.4'
s.summary = 'Floating indicator, mimicrate to indicator which appear when silent mode switched. Can be present from top and bottom.'
s.homepage = 'https://github.com/ivanvorobei/SPIndicator'
s.source = { :git => 'https://github.com/ivanvorobei/SPIndicator.git', :tag => s.version }
Expand Down
13 changes: 2 additions & 11 deletions Sources/SPIndicator/SPIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ open class SPIndicatorView: UIView {
present(duration: self.duration, haptic: haptic, completion: completion)
}


open func present(duration: TimeInterval, haptic: SPIndicatorHaptic = .success, completion: (() -> Void)? = nil) {

if self.presentWindow == nil {
Expand Down Expand Up @@ -251,16 +250,9 @@ open class SPIndicatorView: UIView {
iconView.animate()
}
}

safeAreaInsetsObserver = window.observe(\.safeAreaInsets, changeHandler: { [weak self] window, _ in
guard let self = self else { return }
self.center.x = window.frame.midX
self.toPresentPosition(.visible(self.presentSide))
})
}

@objc open func dismiss() {
safeAreaInsetsObserver?.invalidate()
UIView.animate(withDuration: presentAndDismissDuration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: [.beginFromCurrentState, .curveEaseIn], animations: {
self.toPresentPosition(.prepare(self.presentSide))
if self.presentWithOpacity { self.alpha = 0 }
Expand All @@ -280,6 +272,7 @@ open class SPIndicatorView: UIView {
private var whenGestureEndShoudHide: Bool = false

@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {

if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
self.gestureIsDragging = true
let translation = gestureRecognizer.translation(in: self)
Expand Down Expand Up @@ -364,7 +357,7 @@ open class SPIndicatorView: UIView {
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
case .bottom:
let height = window.frame.height
var bottomSafeAreaInsets = window.safeAreaInsets.bottom
var bottomSafeAreaInsets = window.safeAreaInsets.top
if bottomSafeAreaInsets < 20 { bottomSafeAreaInsets = 20 }
let position = height - bottomSafeAreaInsets - 3 - self.frame.height - self.offset
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
Expand Down Expand Up @@ -402,8 +395,6 @@ open class SPIndicatorView: UIView {
private var spaceBetweenTitles: CGFloat = 1
private var spaceBetweenTitlesAndImage: CGFloat = 16

private var safeAreaInsetsObserver: NSKeyValueObservation?

private var titlesCompactWidth: CGFloat {
if let iconView = self.iconView {
let space = iconView.frame.maxY + spaceBetweenTitlesAndImage
Expand Down

0 comments on commit 4360085

Please sign in to comment.