Skip to content

Commit

Permalink
Merge pull request #22 from dkcas11/development
Browse files Browse the repository at this point in the history
Swift 4.2
  • Loading branch information
dkcas11 authored Dec 11, 2018
2 parents 9811db8 + 340ad76 commit ead1a42
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CRNotifications.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CRNotifications'
s.version = '1.1.6'
s.version = '1.1.7'
s.summary = 'Custom in-app notifications.'

s.description = <<-DESC
Expand Down
13 changes: 6 additions & 7 deletions CRNotifications/Classes/CRNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ internal class CRNotification: UIView {

internal init() {
let deviceWidth = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
let widthFactor: CGFloat = DeviceManager.value(iPhone35: 0.9, iPhone40: 0.9, iPhone47: 0.9, iPhone55: 0.85, iPhone58: 0.9, iPadSmall: 0.5, iPadMedium: 0.45, iPadBig: 0.4)
let heightFactor: CGFloat = DeviceManager.value(iPhone35: 0.2, iPhone40: 0.2, iPhone47: 0.2, iPhone55: 0.2, iPhone58: 0.2, iPadSmall: 0.18, iPadMedium: 0.17, iPadBig: 0.17)
let widthFactor: CGFloat = DeviceManager.value(iPhone35: 0.9, iPhone40: 0.9, iPhone47: 0.9, iPhone55: 0.85, iPhone58: 0.9, iPhone61: 0.9, iPadSmall: 0.5, iPadMedium: 0.45, iPadBig: 0.4)
let heightFactor: CGFloat = DeviceManager.value(iPhone35: 0.22, iPhone40: 0.22, iPhone47: 0.2, iPhone55: 0.2, iPhone58: 0.18, iPhone61: 0.18, iPadSmall: 0.18, iPadMedium: 0.17, iPadBig: 0.17)

let width = deviceWidth * widthFactor
let height = width * heightFactor
Expand Down Expand Up @@ -82,8 +82,8 @@ internal class CRNotification: UIView {
])

NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(greaterThanOrEqualTo: titleLabel.superview!.topAnchor, constant: 6),
titleLabel.topAnchor.constraint(lessThanOrEqualTo: titleLabel.superview!.topAnchor, constant: 2),
titleLabel.topAnchor.constraint(lessThanOrEqualTo: titleLabel.superview!.topAnchor, constant: 6),
titleLabel.topAnchor.constraint(greaterThanOrEqualTo: titleLabel.superview!.topAnchor, constant: 2),
titleLabel.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 8),
titleLabel.trailingAnchor.constraint(equalTo: titleLabel.superview!.trailingAnchor, constant: -8)
])
Expand All @@ -97,8 +97,7 @@ internal class CRNotification: UIView {
}

private func setupTargets() {
NotificationCenter.default.addObserver(self, selector: #selector(didRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(didRotate), name: UIDevice.orientationDidChangeNotification, object: nil)
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissNotification))
let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.dismissNotification))
swipeRecognizer.direction = .up
Expand Down Expand Up @@ -157,7 +156,7 @@ internal class CRNotification: UIView {

/** Animates in the notification **/
internal func showNotification() {
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.68, initialSpringVelocity: 0.1, options: UIViewAnimationOptions(), animations: {
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.68, initialSpringVelocity: 0.1, options: UIView.AnimationOptions(), animations: {
self.frame.origin.y = self.topInset() + 10
})
}
Expand Down
37 changes: 30 additions & 7 deletions CRNotifications/Classes/DeviceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
// iPhone58
// 1125x2436 (375x812)
// - iPhone X
// - iPhone XS
//
// iPhone61
// 828x1792 (414x896)
// - iPhone XR
//
// iPhone 65
// 1242x2688 (414x896)
// - iPhone XS Max
//
//
// ----------------------------------------------------
// Created by Casper Riboe on 21/07/2017.
Expand Down Expand Up @@ -78,8 +88,10 @@ internal class DeviceManager {
return .iPhone55
case CGSize(width: 621.0, height: 1104.0):
return .iPhone55
case CGSize(width: 562.5, height: 1218.0):
return .iPhone58
case CGSize(width: 562.5, height: 1218.0):
return .iPhone58
case CGSize(width: 414.0, height: 896.0):
return .iPhone61
case CGSize(width: 384.0, height: 512.0):
return .iPadSmall
case CGSize(width: 768.0, height: 1024.0):
Expand All @@ -94,7 +106,7 @@ internal class DeviceManager {
}

/// Returns a value based on the current iPhone device.
internal static func value<T>(iPhone35: T, iPhone40: T, iPhone47: T, iPhone55: T, iPhone58: T) -> T {
internal static func value<T>(iPhone35: T, iPhone40: T, iPhone47: T, iPhone55: T, iPhone58: T, iPhone61: T) -> T {
switch device() {
case .iPhone35:
return iPhone35
Expand All @@ -104,6 +116,8 @@ internal class DeviceManager {
return iPhone47
case .iPhone55:
return iPhone55
case .iPhone61:
return iPhone61
default:
return iPhone58
}
Expand All @@ -122,7 +136,7 @@ internal class DeviceManager {
}

/// Returns a value based on the current iPhone or iPad device.
internal static func value<T>(iPhone35: T, iPhone40: T, iPhone47: T, iPhone55: T, iPhone58: T, iPadSmall: T, iPadMedium: T, iPadBig: T) -> T {
internal static func value<T>(iPhone35: T, iPhone40: T, iPhone47: T, iPhone55: T, iPhone58: T, iPhone61: T, iPadSmall: T, iPadMedium: T, iPadBig: T) -> T {
switch device() {
case .iPhone35:
return iPhone35
Expand All @@ -134,22 +148,30 @@ internal class DeviceManager {
return iPhone55
case .iPhone58:
return iPhone58
case .iPhone61:
return iPhone61
case .iPadSmall:
return iPadSmall
case .iPadMedium:
return iPadMedium
case .iPadBig:
return iPadBig
default:
return iPadBig
if UIDevice.current.userInterfaceIdiom == .pad {
return iPadBig
} else {
return iPhone55
}
}
}

/// Returns a value based on the current iPhone or iPad device.
internal static func value<T>(iPhone: T, iPad: T) -> T {
return value(iPhone35: iPhone, iPhone40: iPhone, iPhone47: iPhone, iPhone55: iPhone, iPhone58: iPhone, iPadSmall: iPad, iPadMedium: iPad, iPadBig: iPad)
return value(iPhone35: iPhone, iPhone40: iPhone, iPhone47: iPhone, iPhone55: iPhone, iPhone58: iPhone, iPhone61: iPhone, iPadSmall: iPad, iPadMedium: iPad, iPadBig: iPad)
}

internal static func value<T>(iPhoneX: T, other: T) -> T {
return value(iPhone35: other, iPhone40: other, iPhone47: other, iPhone55: other, iPhone58: iPhoneX, iPadSmall: other, iPadMedium: other, iPadBig: other)
return value(iPhone35: other, iPhone40: other, iPhone47: other, iPhone55: other, iPhone58: iPhoneX, iPhone61: iPhoneX, iPadSmall: other, iPadMedium: other, iPadBig: other)
}

}
Expand All @@ -161,6 +183,7 @@ internal enum Device {
case iPhone47
case iPhone55
case iPhone58
case iPhone61

case iPadSmall
case iPadMedium
Expand Down
22 changes: 19 additions & 3 deletions CRNotificationsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = Criboe;
TargetAttributes = {
AF90178E1E817E2600F4D8F8 = {
Expand Down Expand Up @@ -260,15 +260,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -309,15 +317,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -353,7 +369,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.casperriboe.CRNotificationsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -369,7 +385,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.casperriboe.CRNotificationsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion CRNotificationsExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
2 changes: 1 addition & 1 deletion CRNotificationsExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.6</string>
<string>1.1.7</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions Pods/CRNotifications/CRNotifications/Classes/DeviceManager.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ead1a42

Please sign in to comment.