Skip to content

Commit

Permalink
Bump deployment target to iOS13 + code cleanup (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralbeik authored Jul 16, 2022
1 parent 7c92b07 commit 5bb17db
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 229 deletions.
4 changes: 2 additions & 2 deletions Drops.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Drops'
s.version = '1.4.0'
s.version = '1.5.0'
s.summary = 'A µFramework for showing iOS 13 like system alerts'
s.description = <<-DESC
A µFramework for showing alerts like the one used when copying from pasteboard or connecting Apple pencil.
Expand All @@ -15,5 +15,5 @@ Pod::Spec.new do |s|
s.source_files = 'Sources/**/*.swift'
s.swift_versions = ['5.1', '5.2', '5.3']
s.requires_arc = true
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '13.0'
end
16 changes: 8 additions & 8 deletions Drops.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
074942172642D46E0031D338 /* Drops.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 07D8146D26361DB7003F51DB /* Drops.framework */; };
074942182642D46E0031D338 /* Drops.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 07D8146D26361DB7003F51DB /* Drops.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0755C206263B5EFA002209FD /* DropTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0755C205263B5EFA002209FD /* DropTests.swift */; };
077DCFD2264B2C4000BF2447 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 077DCFD1264B2C4000BF2447 /* UIView+Extensions.swift */; };
0785D38426416EF3004D6171 /* PassthroughWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0785D37926416D84004D6171 /* PassthroughWindow.swift */; };
0785D38526416EF3004D6171 /* PassthroughView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0785D37726416D6A004D6171 /* PassthroughView.swift */; };
0785D38626416EF3004D6171 /* AnimationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0785D37F26416E0E004D6171 /* AnimationContext.swift */; };
Expand Down Expand Up @@ -109,7 +108,6 @@
074942132642D4160031D338 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0755C1E1263A4EF0002209FD /* DropView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropView.swift; sourceTree = "<group>"; };
0755C205263B5EFA002209FD /* DropTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropTests.swift; sourceTree = "<group>"; };
077DCFD1264B2C4000BF2447 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
0785D3732640BBF7004D6171 /* Drops.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drops.swift; sourceTree = "<group>"; };
0785D37726416D6A004D6171 /* PassthroughView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PassthroughView.swift; sourceTree = "<group>"; };
0785D37926416D84004D6171 /* PassthroughWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PassthroughWindow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -233,7 +231,6 @@
0785D37726416D6A004D6171 /* PassthroughView.swift */,
0785D37926416D84004D6171 /* PassthroughWindow.swift */,
0785D38C2641F487004D6171 /* Presenter.swift */,
077DCFD1264B2C4000BF2447 /* UIView+Extensions.swift */,
0785D37B26416DB3004D6171 /* Weak.swift */,
0785D37D26416DDF004D6171 /* WindowViewController.swift */,
);
Expand Down Expand Up @@ -499,7 +496,6 @@
0785D38726416EF3004D6171 /* Drop.swift in Sources */,
0785D38826416EF3004D6171 /* Animator.swift in Sources */,
0785D38626416EF3004D6171 /* AnimationContext.swift in Sources */,
077DCFD2264B2C4000BF2447 /* UIView+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -558,6 +554,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = C3VKVFB3SA;
INFOPLIST_FILE = UIKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand All @@ -578,6 +575,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = C3VKVFB3SA;
INFOPLIST_FILE = UIKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand All @@ -598,6 +596,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = C3VKVFB3SA;
ENABLE_PREVIEWS = NO;
INFOPLIST_FILE = SwiftUIExample/Info.plist;
Expand All @@ -619,6 +618,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = C3VKVFB3SA;
ENABLE_PREVIEWS = NO;
INFOPLIST_FILE = SwiftUIExample/Info.plist;
Expand Down Expand Up @@ -686,7 +686,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -744,7 +744,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -768,7 +768,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -797,7 +797,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import PackageDescription
let package = Package(
name: "Drops",
platforms: [
.iOS(.v10)
.iOS(.v13)
],
products: [
.library(name: "Drops", targets: ["Drops"])
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A µFramework for showing alerts like the one used when copying from pasteboard
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fomaralbeik%2FDrops%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/omaralbeik/Drops)
## Features

- iOS 10+
- iOS 13+
- Can be used in SwiftUI and UIKit applications
- Light/Dark modes
- Interactive dismissal
Expand Down Expand Up @@ -119,7 +119,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) is a tool for ma

```swift
dependencies: [
.package(url: "https://github.com/omaralbeik/Drops.git", from: "1.4.0")
.package(url: "https://github.com/omaralbeik/Drops.git", from: "1.5.0")
]
```

Expand All @@ -134,7 +134,7 @@ $ swift build
To integrate Drops into your Xcode project using [CocoaPods](https://cocoapods.org), specify it in your Podfile:

```rb
pod 'Drops', :git => 'https://github.com/omaralbeik/Drops.git', :tag => '1.4.0'
pod 'Drops', :git => 'https://github.com/omaralbeik/Drops.git', :tag => '1.5.0'
```

### Carthage
Expand Down
76 changes: 38 additions & 38 deletions Sources/Animator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ internal final class Animator {
var closePercent: CGFloat = 0.0
var panTranslationY: CGFloat = 0.0
}

init(position: Drop.Position, delegate: AnimatorDelegate) {
self.position = position
self.delegate = delegate
}

let position: Drop.Position
weak var delegate: AnimatorDelegate?

var context: AnimationContext?
var panState = PanState()

let showDuration: TimeInterval = 0.75
let hideDuration: TimeInterval = 0.25
let springDamping: CGFloat = 0.8
Expand All @@ -56,59 +56,59 @@ internal final class Animator {
let closePercentThreshold: CGFloat = 0.33
let closeAbsoluteThreshold: CGFloat = 75.0
let bounceOffset: CGFloat = 5

private lazy var panGestureRecognizer: UIPanGestureRecognizer = {
let recognizer = UIPanGestureRecognizer()
recognizer.addTarget(self, action: #selector(handlePan))
return recognizer
}()

func install(context: AnimationContext) {
let view = context.view
let container = context.container

self.context = context

view.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(view)

var constraints = [
view.centerXAnchor.constraint(equalTo: container.safeArea.centerXAnchor),
view.leadingAnchor.constraint(greaterThanOrEqualTo: container.safeArea.leadingAnchor, constant: 20),
view.trailingAnchor.constraint(lessThanOrEqualTo: container.safeArea.trailingAnchor, constant: -20),
view.centerXAnchor.constraint(equalTo: container.safeAreaLayoutGuide.centerXAnchor),
view.leadingAnchor.constraint(greaterThanOrEqualTo: container.safeAreaLayoutGuide.leadingAnchor, constant: 20),
view.trailingAnchor.constraint(lessThanOrEqualTo: container.safeAreaLayoutGuide.trailingAnchor, constant: -20)
]

switch position {
case .top:
constraints += [
view.topAnchor.constraint(equalTo: container.safeArea.topAnchor, constant: bounceOffset),
view.topAnchor.constraint(equalTo: container.safeAreaLayoutGuide.topAnchor, constant: bounceOffset)
]
case .bottom:
constraints += [
view.bottomAnchor.constraint(equalTo: container.safeArea.bottomAnchor, constant: -bounceOffset),
view.bottomAnchor.constraint(equalTo: container.safeAreaLayoutGuide.bottomAnchor, constant: -bounceOffset)
]
}

NSLayoutConstraint.activate(constraints)
container.layoutIfNeeded()

let animationDistance = view.frame.height

switch position {
case .top:
view.transform = CGAffineTransform(translationX: 0, y: -animationDistance)
case .bottom:
view.transform = CGAffineTransform(translationX: 0, y: animationDistance)
}

view.addGestureRecognizer(panGestureRecognizer)
}

func show(context: AnimationContext, completion: @escaping AnimationCompletion) {
install(context: context)
show(completion: completion)
}

func hide(context: AnimationContext, completion: @escaping AnimationCompletion) {
let position = self.position
let view = context.view
Expand All @@ -129,18 +129,18 @@ internal final class Animator {
completion: completion
)
}

func show(completion: @escaping AnimationCompletion) {
guard let view = context?.view else {
completion(false)
return
}

view.alpha = 0

let animationDistance = abs(view.transform.ty)
let initialSpringVelocity = animationDistance == 0.0 ? 0.0 : min(0.0, panState.closeSpeed / animationDistance)

UIView.animate(
withDuration: showDuration,
delay: 0.0,
Expand All @@ -154,7 +154,7 @@ internal final class Animator {
completion: completion
)
}

@objc
func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
switch gestureRecognizer.state {
Expand All @@ -175,59 +175,59 @@ internal final class Animator {
break
}
}

func panChanged(current: PanState, view: UIView, velocity: CGPoint, translation: CGPoint) -> PanState {
var state = current
var velocity = velocity
var translation = translation
let height = view.bounds.height - bounceOffset
if height <= 0 { return state }

if case .top = position {
velocity.y *= -1.0
translation.y *= -1.0
}

var translationAmount = translation.y >= 0 ? translation.y : -pow(abs(translation.y), 0.7)

if !state.closing {
if !rubberBanding, translationAmount < 0 { return state }
state.closing = true
delegate?.panStarted(animator: self)
}

if !rubberBanding, translationAmount < 0 { translationAmount = 0 }

switch position {
case .top:
view.transform = CGAffineTransform(translationX: 0, y: -translationAmount)
case .bottom:
view.transform = CGAffineTransform(translationX: 0, y: translationAmount)
}

state.closeSpeed = velocity.y
state.closePercent = translation.y / height
state.panTranslationY = translation.y

return state
}

func panEnded(current: PanState) -> PanState? {
if current.closeSpeed > closeSpeedThreshold {
delegate?.hide(animator: self)
return nil
}

if current.closePercent > closePercentThreshold {
delegate?.hide(animator: self)
return nil
}

if current.panTranslationY > closeAbsoluteThreshold {
delegate?.hide(animator: self)
return nil
}

return .init()
}
}
Loading

0 comments on commit 5bb17db

Please sign in to comment.