From 437a3bbe6d01cab88656441b2fef95080d198869 Mon Sep 17 00:00:00 2001 From: Christoffer Winterkvist Date: Tue, 17 Oct 2017 08:12:48 +0200 Subject: [PATCH 1/2] Update .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b572ea5..7e8fa93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -osx_image: xcode8 -language: objective-c +osx_image: xcode9 +language: swift script: - xcodebuild clean build -project Whisper.xcodeproj -scheme "Whisper-iOS" -sdk iphonesimulator From aeff2e2b9852cccea3430ce25f6dc77d01600b71 Mon Sep 17 00:00:00 2001 From: Christoffer Winterkvist Date: Tue, 17 Oct 2017 08:21:39 +0200 Subject: [PATCH 2/2] Refactor computing safeAreaInsets in Shout- and WhistleFactory This commit refactors the iPhone X fix (https://github.com/hyperoslo/Whisper/pull/179) to reduce the amount of `#available(iOS 11.0, *)` annotations. --- Demo/WhisperDemo/Podfile.lock | 8 +++---- .../WhisperDemo.xcodeproj/project.pbxproj | 8 ++++++- Source/ShoutFactory.swift | 21 ++++++------------- Source/UIView+Extensions.swift | 14 +++++++++++++ Source/WhistleFactory.swift | 11 +++------- Whisper.xcodeproj/project.pbxproj | 4 ++++ 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 Source/UIView+Extensions.swift diff --git a/Demo/WhisperDemo/Podfile.lock b/Demo/WhisperDemo/Podfile.lock index 7645158..3ba4d40 100644 --- a/Demo/WhisperDemo/Podfile.lock +++ b/Demo/WhisperDemo/Podfile.lock @@ -1,16 +1,16 @@ PODS: - - Whisper (4.0.0) + - Whisper (5.0.0) DEPENDENCIES: - Whisper (from `../../`) EXTERNAL SOURCES: Whisper: - :path: "../../" + :path: ../../ SPEC CHECKSUMS: - Whisper: 08be92623311f8e53201e62e17f6d7b9599a4714 + Whisper: 39b833d0f279912a7f38a19c4ba603435514a550 PODFILE CHECKSUM: e20a3f258a5cd7e57b37f62aadb18fd14d135133 -COCOAPODS: 1.2.0 +COCOAPODS: 1.3.1 diff --git a/Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj b/Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj index 9bde9dc..fcdcf76 100644 --- a/Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj +++ b/Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj @@ -230,9 +230,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-WhisperDemo/Pods-WhisperDemo-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Whisper/Whisper.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Whisper.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -245,13 +248,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-WhisperDemo-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; BCC353EC93296D0E781E45A8 /* [CP] Copy Pods Resources */ = { diff --git a/Source/ShoutFactory.swift b/Source/ShoutFactory.swift index a643574..3211985 100644 --- a/Source/ShoutFactory.swift +++ b/Source/ShoutFactory.swift @@ -174,27 +174,18 @@ open class ShoutView: UIView { if subtitleLabel.text?.isEmpty ?? true { titleLabel.center.y = imageView.center.y - 2.5 } - if #available(iOS 11.0, *) { - frame = CGRect(x: 0, y: self.safeAreaInsets.top, width: totalWidth, height: internalHeight + Dimensions.touchOffset) - } else { - frame = CGRect(x: 0, y: 0, width: totalWidth, height: internalHeight + Dimensions.touchOffset) - } + + frame = CGRect(x: 0, y: safeYCoordinate, + width: totalWidth, height: internalHeight + Dimensions.touchOffset) } // MARK: - Frame open override var frame: CGRect { didSet { - if #available(iOS 11.0, *) { - backgroundView.frame = CGRect(x: 0, y: self.safeAreaInsets.top, - width: frame.size.width, - height: frame.size.height - Dimensions.touchOffset) - } else { - // Fallback on earlier versions - backgroundView.frame = CGRect(x: 0, y: 0, - width: frame.size.width, - height: frame.size.height - Dimensions.touchOffset) - } + backgroundView.frame = CGRect(x: 0, y: safeYCoordinate, + width: frame.size.width, + height: frame.size.height - Dimensions.touchOffset) indicatorView.frame = CGRect(x: (backgroundView.frame.size.width - Dimensions.indicatorWidth) / 2, y: backgroundView.frame.height - Dimensions.indicatorHeight - 5, diff --git a/Source/UIView+Extensions.swift b/Source/UIView+Extensions.swift new file mode 100644 index 0000000..f68a796 --- /dev/null +++ b/Source/UIView+Extensions.swift @@ -0,0 +1,14 @@ +import UIKit + +extension UIView { + var safeYCoordinate: CGFloat { + let y: CGFloat + if #available(iOS 11.0, *) { + y = safeAreaInsets.top + } else { + y = 0 + } + + return y + } +} diff --git a/Source/WhistleFactory.swift b/Source/WhistleFactory.swift index bf9b8ec..e25105f 100644 --- a/Source/WhistleFactory.swift +++ b/Source/WhistleFactory.swift @@ -116,14 +116,9 @@ open class WhistleFactory: UIViewController { titleLabel.sizeToFit() } - if #available(iOS 11.0, *) { - whistleWindow.frame = CGRect(x: 0, y: self.view.safeAreaInsets.top, width: labelWidth, - height: titleLabelHeight) - } else { - // Fallback on earlier versions - whistleWindow.frame = CGRect(x: 0, y: 0, width: labelWidth, - height: titleLabelHeight) - } + whistleWindow.frame = CGRect(x: 0, y: view.safeYCoordinate, + width: labelWidth, + height: titleLabelHeight) view.frame = whistleWindow.bounds titleLabel.frame = view.bounds } diff --git a/Whisper.xcodeproj/project.pbxproj b/Whisper.xcodeproj/project.pbxproj index f420bb1..17c612c 100644 --- a/Whisper.xcodeproj/project.pbxproj +++ b/Whisper.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 290531131C20517E00FB382C /* WhisperFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2905310B1C20517E00FB382C /* WhisperFactory.swift */; }; 290531141C20517E00FB382C /* WhisperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2905310C1C20517E00FB382C /* WhisperView.swift */; }; 290531151C20517E00FB382C /* WhistleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2905310D1C20517E00FB382C /* WhistleFactory.swift */; }; + BDA2138F1F95D75F003FBC71 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA2138E1F95D75F003FBC71 /* UIView+Extensions.swift */; }; D2D71BB81D54B62B006AB907 /* Showing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D71BB71D54B62B006AB907 /* Showing.swift */; }; D5170D641C4955F3006F2F37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5170D631C4955F3006F2F37 /* Config.swift */; }; /* End PBXBuildFile section */ @@ -28,6 +29,7 @@ 2905310C1C20517E00FB382C /* WhisperView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhisperView.swift; sourceTree = ""; }; 2905310D1C20517E00FB382C /* WhistleFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhistleFactory.swift; sourceTree = ""; }; 290531171C2051F400FB382C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BDA2138E1F95D75F003FBC71 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = ""; }; D2D71BB71D54B62B006AB907 /* Showing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Showing.swift; sourceTree = ""; }; D5170D631C4955F3006F2F37 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -71,6 +73,7 @@ 2905310C1C20517E00FB382C /* WhisperView.swift */, 2905310D1C20517E00FB382C /* WhistleFactory.swift */, D5170D631C4955F3006F2F37 /* Config.swift */, + BDA2138E1F95D75F003FBC71 /* UIView+Extensions.swift */, ); path = Source; sourceTree = ""; @@ -173,6 +176,7 @@ files = ( 290531121C20517E00FB382C /* ShoutFactory.swift in Sources */, 290531141C20517E00FB382C /* WhisperView.swift in Sources */, + BDA2138F1F95D75F003FBC71 /* UIView+Extensions.swift in Sources */, 290531151C20517E00FB382C /* WhistleFactory.swift in Sources */, 290531111C20517E00FB382C /* Message.swift in Sources */, 290531131C20517E00FB382C /* WhisperFactory.swift in Sources */,