Skip to content

Commit

Permalink
Merge pull request #159 from nhuanvd/compatible
Browse files Browse the repository at this point in the history
Support iOS 10
  • Loading branch information
gordontucker authored Jan 14, 2022
2 parents 7f0702f + 7d49317 commit bfb67e0
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion FittedSheets.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"tag": "2.4.2"
},
"platforms": {
"ios": "11.0"
"ios": "10.0"
},
"social_media_url": "https://twitter.com/tuckeredoutfmly",
"requires_arc": true,
Expand Down
8 changes: 6 additions & 2 deletions FittedSheets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
42F0967527040EE7009774EA /* Compatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42F0967427040EE7009774EA /* Compatible.swift */; };
C4E231E524E55E4E00D367FD /* BlurDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E231E424E55E4E00D367FD /* BlurDemo.swift */; };
F8034165212625DD00EAD717 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8034164212625DD00EAD717 /* AppDelegate.swift */; };
F803416A212625DD00EAD717 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F8034168212625DD00EAD717 /* Main.storyboard */; };
Expand Down Expand Up @@ -99,6 +100,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
42F0967427040EE7009774EA /* Compatible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compatible.swift; sourceTree = "<group>"; };
46334410249C041700F334E5 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
C4E231E424E55E4E00D367FD /* BlurDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurDemo.swift; sourceTree = "<group>"; };
F8034161212625DD00EAD717 /* Demos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demos.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -254,6 +256,7 @@
isa = PBXGroup;
children = (
F8C1A06A24E2FF4600807078 /* Localization */,
42F0967427040EE7009774EA /* Compatible.swift */,
F8A42B4924D1E241005DE55B /* SheetViewController.swift */,
F8A42B4B24D1E2EF005DE55B /* SheetContentViewController.swift */,
F803419C212F208300EAD717 /* Yalta.swift */,
Expand Down Expand Up @@ -503,6 +506,7 @@
F8A42B9624DB3495005DE55B /* SheetView.swift in Sources */,
F8C1A07024E3017F00807078 /* Localize.swift in Sources */,
F857D0A22204B776004C862F /* SheetSize.swift in Sources */,
42F0967527040EE7009774EA /* Compatible.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -711,7 +715,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = FittedSheets/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -742,7 +746,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = FittedSheets/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
55 changes: 55 additions & 0 deletions FittedSheets/Compatible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// File.swift
//
//
// Created by Nhuan Vu on 8/25/21.
//

#if os(iOS) || os(tvOS) || os(watchOS)
import UIKit

extension UIView {
open var compatibleSafeAreaInsets: UIEdgeInsets {
if #available(iOS 11.0, *) {
return self.safeAreaInsets
} else {
return .zero
}
}
}

extension CALayer {
open var compatibleMaskedCorners: CACornerMask {
get {
if #available(iOS 11.0, *) {
return self.maskedCorners
} else {
return []
}
}
set {
if #available(iOS 11.0, *) {
self.maskedCorners = newValue
}
}
}
}

extension UIViewController {
open var compatibleAdditionalSafeAreaInsets: UIEdgeInsets {
get {
if #available(iOS 11.0, *) {
return self.additionalSafeAreaInsets
} else {
return .zero
}
}
set {
if #available(iOS 11.0, *) {
self.additionalSafeAreaInsets = newValue
}
}
}
}

#endif // os(iOS) || os(tvOS) || os(watchOS)
6 changes: 3 additions & 3 deletions FittedSheets/SheetContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ public class SheetContentViewController: UIViewController {
view.top.pinToSuperview()
}
if self.options.shouldExtendBackground, self.options.pullBarHeight > 0 {
self.childViewController.additionalSafeAreaInsets = UIEdgeInsets(top: self.options.pullBarHeight, left: 0, bottom: 0, right: 0)
self.childViewController.compatibleAdditionalSafeAreaInsets = UIEdgeInsets(top: self.options.pullBarHeight, left: 0, bottom: 0, right: 0)
}

self.childViewController.didMove(toParent: self)

self.childContainerView.layer.masksToBounds = true
self.childContainerView.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
self.childContainerView.layer.compatibleMaskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
}

private func setupContentView() {
Expand All @@ -220,7 +220,7 @@ public class SheetContentViewController: UIViewController {
}

self.contentWrapperView.layer.masksToBounds = true
self.contentWrapperView.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
self.contentWrapperView.layer.compatibleMaskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]

self.contentView.addSubview(overflowView) {
$0.edges(.left, .right).pinToSuperview()
Expand Down
4 changes: 2 additions & 2 deletions FittedSheets/SheetTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
// Use a normal animation to animate the shadown and background view
UIView.animate(withDuration: self.options.transitionDuration * 0.6, delay: 0, options: [.curveEaseOut], animations: {
if self.options.shrinkPresentingViewController {
let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.top ?? 0
let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.compatibleSafeAreaInsets.top ?? 0

presenter.view.layer.transform = CATransform3DConcat(CATransform3DMakeTranslation(0, topSafeArea/2, 0), CATransform3DMakeScale(0.92, 0.92, 1))
presenter.view.layer.cornerRadius = self.options.presentingViewCornerRadius
Expand Down Expand Up @@ -121,7 +121,7 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
guard self.options.shrinkPresentingViewController, let presenter = self.presenter else { return }
let scale: CGFloat = min(1, 0.92 + (0.08 * percentComplete))

let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.top ?? 0
let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.compatibleSafeAreaInsets.top ?? 0

presenter.view.layer.transform = CATransform3DConcat(CATransform3DMakeTranslation(0, (1 - percentComplete) * topSafeArea/2, 0), CATransform3DMakeScale(scale, scale, 1))
presenter.view.layer.cornerRadius = self.options.presentingViewCornerRadius * (1 - percentComplete)
Expand Down
6 changes: 3 additions & 3 deletions FittedSheets/SheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class SheetViewController: UIViewController {
public override func viewDidLoad() {
super.viewDidLoad()

self.additionalSafeAreaInsets = UIEdgeInsets(top: -self.options.pullBarHeight, left: 0, bottom: 0, right: 0)
self.compatibleAdditionalSafeAreaInsets = UIEdgeInsets(top: -self.options.pullBarHeight, left: 0, bottom: 0, right: 0)

self.view.backgroundColor = UIColor.clear
self.addPanGestureRecognizer()
Expand Down Expand Up @@ -336,7 +336,7 @@ public class SheetViewController: UIViewController {
if (self.options.useFullScreenMode) {
top = 0
} else {
top = max(12, UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.safeAreaInsets.top ?? 12)
top = max(12, UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.compatibleSafeAreaInsets.top ?? 12)
}
$0.bottom.pinToSuperview()
$0.top.pinToSuperview(inset: top, relation: .greaterThanOrEqual).priority = UILayoutPriority(999)
Expand Down Expand Up @@ -519,7 +519,7 @@ public class SheetViewController: UIViewController {
if self.options.useFullScreenMode {
fullscreenHeight = self.view.bounds.height - self.minimumSpaceAbovePullBar
} else {
fullscreenHeight = self.view.bounds.height - self.view.safeAreaInsets.top - self.minimumSpaceAbovePullBar
fullscreenHeight = self.view.bounds.height - self.view.compatibleSafeAreaInsets.top - self.minimumSpaceAbovePullBar
}
switch (size) {
case .fixed(let height):
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PackageDescription
let package = Package(
name: "FittedSheets",
platforms: [
.iOS(.v11), .tvOS(.v10), .macOS(.v10_12), .watchOS(.v3)
.iOS(.v10), .tvOS(.v10), .macOS(.v10_12), .watchOS(.v3)
],
products: [
.library(name: "FittedSheets", targets: ["FittedSheets"]),
Expand Down

0 comments on commit bfb67e0

Please sign in to comment.