Skip to content

Commit

Permalink
Merge pull request #19 from prolificinteractive/swift-4
Browse files Browse the repository at this point in the history
Updated for Swift 3.2 and 4.0
  • Loading branch information
htinlinn authored Sep 22, 2017
2 parents 50464ff + 357684c commit 88b58ba
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: objective-c
osx_image: xcode8.1
osx_image: xcode9
podfile: Example/Podfile

before_install:
- pod repo update --silent

script:
- set -o pipefail && xcodebuild test -workspace Example/Optik.xcworkspace -scheme Optik-Example -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.1' | xcpretty
- pod lib lint
- set -o pipefail && xcodebuild test -workspace Example/Optik.xcworkspace -scheme Optik-Example -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.0' | xcpretty
- pod lib lint
2 changes: 1 addition & 1 deletion Example/.swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
34 changes: 25 additions & 9 deletions Example/Optik.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0810;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
Expand Down Expand Up @@ -297,9 +297,16 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Optik_Example/Pods-Optik_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/AlamofireImage/AlamofireImage.framework",
"${BUILT_PRODUCTS_DIR}/Optik/Optik.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AlamofireImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Optik.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -327,9 +334,12 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Optik_Tests/Pods-Optik_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Optik/Optik.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Optik.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand All @@ -342,13 +352,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Optik_Example-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;
};
C1CD7E2768F81665C8539E60 /* [CP] Copy Pods Resources */ = {
Expand All @@ -372,13 +385,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Optik_Tests-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;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -469,7 +485,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -507,7 +523,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -525,7 +541,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "com.prolificinteractive.Optik-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -540,7 +556,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "com.prolificinteractive.Optik-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -560,7 +576,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -576,7 +592,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
17 changes: 16 additions & 1 deletion Example/Optik/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,10 +39,15 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
}
4 changes: 3 additions & 1 deletion Example/Optik/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>
10 changes: 7 additions & 3 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

target 'Optik_Example' do
pod 'Optik', :path => '../'
pod 'AlamofireImage', '3.1.0'
platform :ios, '9.0'

pod 'Optik', :path => '../'
pod 'AlamofireImage', '3.3.0'
end

target 'Optik_Tests' do
pod 'Optik', :path => '../'
platform :ios, '9.0'

pod 'Optik', :path => '../'
end
20 changes: 10 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
PODS:
- Alamofire (4.1.0)
- AlamofireImage (3.1.0):
- Alamofire (~> 4.0)
- Alamofire (4.5.1)
- AlamofireImage (3.3.0):
- Alamofire (~> 4.5)
- Optik (0.2.0)

DEPENDENCIES:
- AlamofireImage (= 3.1.0)
- AlamofireImage (= 3.3.0)
- Optik (from `../`)

EXTERNAL SOURCES:
Optik:
:path: "../"
:path: ../

SPEC CHECKSUMS:
Alamofire: e266cf991b933498df791e645e0d8ac294492153
AlamofireImage: bb8c8351c51cb1633bb6be69b6dbbaff37ce65b7
Optik: 1601123d313b0ef1925912bcb97c1d18fedf5a4b
Alamofire: 2d95912bf4c34f164fdfc335872e8c312acaea4a
AlamofireImage: 2e784dc5d00f04903a52c1d169181469c805c3df
Optik: 3d3905f19e503f8fc30343edea05856721b38014

PODFILE CHECKSUM: c4cc51091b7726b48b7d19365a55eb8f1cc861f2
PODFILE CHECKSUM: 3873430f0694557b2b3fc21b9a5a450f371f986e

COCOAPODS: 1.2.0
COCOAPODS: 1.3.1
2 changes: 1 addition & 1 deletion Optik.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Optik provides a simple viewing experience for a set of images, whether stored l
s.author = { "htinlinn" => "linn@prolificinteractive.com" }
s.source = { :git => "https://github.com/prolificinteractive/Optik.git", :tag => s.version.to_s }

s.platform = :ios, '8.0'
s.platform = :ios, '9.0'
s.requires_arc = true

s.source_files = 'Optik/Classes/**/*'
Expand Down
90 changes: 40 additions & 50 deletions Optik/Classes/AlbumViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import UIKit
internal final class AlbumViewController: UIViewController {

private struct Constants {
static let SpacingBetweenImages: CGFloat = 40
static let DismissButtonDimension: CGFloat = 60
static let spacingBetweenImages: CGFloat = 40
static let dismissButtonDimension: CGFloat = 60

static let TransitionAnimationDuration: TimeInterval = 0.3
static let transitionAnimationDuration: TimeInterval = 0.3
static let artificialDelayDuration: TimeInterval = 0.001
}

// MARK: - Properties
Expand Down Expand Up @@ -71,6 +72,8 @@ internal final class AlbumViewController: UIViewController {
private var imageData: ImageData
private var initialImageDisplayIndex: Int
private var activityIndicatorColor: UIColor?

private var dismissButton: UIButton?
private var dismissButtonImage: UIImage?
private var dismissButtonPosition: DismissButtonPosition

Expand All @@ -95,7 +98,7 @@ internal final class AlbumViewController: UIViewController {

pageViewController = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .horizontal,
options: [UIPageViewControllerOptionInterPageSpacingKey : Constants.SpacingBetweenImages])
options: [UIPageViewControllerOptionInterPageSpacingKey : Constants.spacingBetweenImages])

super.init(nibName: nil, bundle: nil)

Expand All @@ -116,14 +119,19 @@ internal final class AlbumViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

// HACK: UIKit doesn't animate status bar transition on iOS 9. So, manually animate it.

if !viewDidAppear {
viewDidAppear = true

UIView.animate(withDuration: Constants.TransitionAnimationDuration, animations: {

// UIKit doesn't animate status bar transition on iOS 9. So, manually animate it.
UIView.animate(withDuration: Constants.transitionAnimationDuration, animations: {
self.setNeedsStatusBarAppearanceUpdate()
})
})

// Wait for the safe area insets to be in effect and set up the constraints.
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Constants.artificialDelayDuration, execute: {
self.setupDismissButtonConstraints()
})
}
}

Expand Down Expand Up @@ -170,48 +178,30 @@ internal final class AlbumViewController: UIViewController {
dismissButton.translatesAutoresizingMaskIntoConstraints = false
dismissButton.setImage(dismissButtonImage, for: UIControlState())
dismissButton.addTarget(self, action: #selector(AlbumViewController.didTapDismissButton(_:)), for: .touchUpInside)

let xAnchorAttribute = dismissButtonPosition.xAnchorAttribute()
let yAnchorAttribute = dismissButtonPosition.yAnchorAttribute()

view.addSubview(dismissButton)

view.addConstraint(
NSLayoutConstraint(item: dismissButton,
attribute: xAnchorAttribute,
relatedBy: .equal,
toItem: view,
attribute: xAnchorAttribute,
multiplier: 1,
constant: 0)
)
view.addConstraint(
NSLayoutConstraint(item: dismissButton,
attribute: yAnchorAttribute,
relatedBy: .equal,
toItem: view,
attribute: yAnchorAttribute,
multiplier: 1,
constant: 0)
)
view.addConstraint(
NSLayoutConstraint(item: dismissButton,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: Constants.DismissButtonDimension)
)
view.addConstraint(
NSLayoutConstraint(item: dismissButton,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: Constants.DismissButtonDimension)
)

self.dismissButton = dismissButton
}

private func setupDismissButtonConstraints() {
if #available(iOS 11.0, *), view.safeAreaInsets.top > 0 {
// Using `safeAreaLayoutGuide` on devices other than iPhone X causes a visual glitch
// where the button shifts down before dimissing.
// So, restrict this to devices with top inset that is greater than 0.
dismissButton?.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
} else {
dismissButton?.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
}

switch dismissButtonPosition {
case .topLeading:
dismissButton?.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
case .topTrailing:
dismissButton?.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
}

dismissButton?.widthAnchor.constraint(equalToConstant: Constants.dismissButtonDimension).isActive = true
dismissButton?.heightAnchor.constraint(equalToConstant: Constants.dismissButtonDimension).isActive = true
}

private func setupPanGestureRecognizer() {
Expand Down
2 changes: 1 addition & 1 deletion Optik/Classes/Animation/SpringAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

/// Animation that moves a given view to a new target using spring physics.
internal final class SpringAnimation<T: VectorRepresentable, U: AnimatableProperty> where T == U.PropertyType {
internal final class SpringAnimation<T, U: AnimatableProperty> where T == U.PropertyType {

// MARK: - Properties

Expand Down
Loading

0 comments on commit 88b58ba

Please sign in to comment.