Skip to content

Commit 2c68287

Browse files
philprimewtmoose
authored andcommitted
Removed delay after physics pan dismiss (SwiftKickMobile#257)
* Make the hide delay configurable
1 parent 70cfe5c commit 2c68287

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 6.0.1
5+
6+
### Features
7+
* #257 Add the ability to specify the hide delay on `PhysicsPanHandler`. When `PhysicsPanHandler`'s dismissal gesture determines that the view is out of the container view's bounds, it waits `hideDelay` seconds before calling `SwiftMessages.hide()`. The default value is 0.2, which is what you'll get when using `presentationStyle = .center`. To specify a different delay, use `presentationStyle = .custom(animator:)` and supply an instance of `PhysicsPanHandler` configured to your liking.
8+
49
## 6.0.0
510

611
### Changes

SwiftMessages.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '6.0.0'
3+
spec.version = '6.0.1'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }

SwiftMessages/PhysicsPanHandler.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import UIKit
1010

1111
open class PhysicsPanHandler {
1212

13+
/// During the dismiss gesture, specifies the delay between the view
14+
/// going out of the screen's bounds and `SwiftMessages.hide()` being called.
15+
public var hideDelay: TimeInterval = 0.2
16+
1317
public struct MotionSnapshot {
1418
var angle: CGFloat
1519
var time: CFAbsoluteTime
@@ -114,12 +118,12 @@ open class PhysicsPanHandler {
114118
let attachmentBehavior = UIAttachmentBehavior(item: messageView, offsetFromCenter: offset, attachedToAnchor: anchorPoint)
115119
state.attachmentBehavior = attachmentBehavior
116120
state.itemBehavior.action = { [weak self, weak messageView, weak containerView] in
117-
guard let strongSelf = self, !strongSelf.isOffScreen, let messageView = messageView, let containerView = containerView, let animator = strongSelf.animator else { return }
121+
guard let self = self, !self.isOffScreen, let messageView = messageView, let containerView = containerView, let animator = self.animator else { return }
118122
let view = (messageView as? BackgroundViewable)?.backgroundView ?? messageView
119123
let frame = containerView.convert(view.bounds, from: view)
120124
if !containerView.bounds.intersects(frame) {
121-
strongSelf.isOffScreen = true
122-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
125+
self.isOffScreen = true
126+
DispatchQueue.main.asyncAfter(deadline: .now() + self.hideDelay) {
123127
animator.delegate?.hide(animator: animator)
124128
}
125129
}

0 commit comments

Comments
 (0)