Skip to content

Commit

Permalink
Support for Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
m-revetria committed Jun 7, 2017
1 parent f518329 commit 4664dee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Source/ActionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,15 @@ open class ActionController<ActionViewType: UICollectionViewCell, ActionDataType

// MARK: - Event handlers

func cancelButtonDidTouch(_ sender: UIButton) {
@objc func cancelButtonDidTouch(_ sender: UIButton) {
self.dismiss()
}

func tapGestureDidRecognize(_ gesture: UITapGestureRecognizer) {
@objc func tapGestureDidRecognize(_ gesture: UITapGestureRecognizer) {
self.dismiss()
}

func swipeGestureDidRecognize(_ gesture: UISwipeGestureRecognizer) {
@objc func swipeGestureDidRecognize(_ gesture: UISwipeGestureRecognizer) {
self.dismiss()
}

Expand Down
23 changes: 20 additions & 3 deletions Source/DynamicCollectionViewFlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ open class DynamicCollectionViewFlowLayout: UICollectionViewFlowLayout {

return top
}

private func isRTL(for view: UIView) -> Bool {
if #available(iOS 9.0, *) {
return UIView.userInterfaceLayoutDirection(for: view.semanticContentAttribute) == .rightToLeft
} else {
return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
}
}

@discardableResult
func setupAttributesForIndexPath(_ indexPath: IndexPath?) -> UICollectionViewLayoutAttributes? {
guard let indexPath = indexPath, let animator = dynamicAnimator, let collectionView = collectionView else {
Expand All @@ -148,15 +157,23 @@ open class DynamicCollectionViewFlowLayout: UICollectionViewFlowLayout {
var initialFrame = CGRect(x: 0, y: originY + frame.origin.y, width: collectionItemSize.width, height: collectionItemSize.height)

// Calculate x position depending on alignment value
var translationX: CGFloat

let collectionViewContentWidth = collectionView.bounds.size.width - collectionView.contentInset.left - collectionView.contentInset.right
let rightMargin = (collectionViewContentWidth - frame.size.width)
let leftMargin = CGFloat(0.0)

var translationX: CGFloat
switch itemsAligment {
case .center:
translationX = (collectionViewContentWidth - frame.size.width) * 0.5
case .fill, .left:
translationX = 0.0
translationX = leftMargin
case .right:
translationX = (collectionViewContentWidth - frame.size.width)
translationX = rightMargin
case .leading:
translationX = isRTL(for: collectionView) ? rightMargin : leftMargin
case .trailing:
translationX = isRTL(for: collectionView) ? leftMargin : rightMargin
}

frame.origin.x = translationX
Expand Down
10 changes: 6 additions & 4 deletions XLActionController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -326,6 +327,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -350,7 +352,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -369,7 +371,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.XLActionController;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -381,7 +383,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.XLActionControllerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -393,7 +395,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.XLActionControllerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down

0 comments on commit 4664dee

Please sign in to comment.