Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ImagePickerSheetController/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return window
}()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()

Expand Down
4 changes: 2 additions & 2 deletions ImagePickerSheetController/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ViewController: UIViewController {
super.viewDidLoad()

let button = UIButton(type: .system)
button.setTitle("Tap Me!", for: UIControlState())
button.setTitle("Tap Me!", for: UIControl.State())
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
button.heightAnchor.constraint(equalToConstant: 40).isActive = true
Expand All @@ -32,7 +32,7 @@ class ViewController: UIViewController {

@objc
func presentImagePickerSheet(_ gestureRecognizer: UITapGestureRecognizer) {
let presentImagePickerController: (UIImagePickerControllerSourceType) -> () = { source in
let presentImagePickerController: (UIImagePickerController.SourceType) -> () = { source in
let controller = UIImagePickerController()
controller.delegate = self
var sourceType = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@
TargetAttributes = {
49DC4A501B14F1BC00B4E78E = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
49DC4A5B1B14F1BC00B4E78E = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0900;
LastSwiftMigration = "";
TestTargetID = 49DC4A851B14F31500B4E78E;
};
49DC4A851B14F31500B4E78E = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 5953RHWYWT;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -638,8 +638,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -659,8 +658,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down Expand Up @@ -718,8 +716,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -735,8 +732,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ open class ImagePickerSheetController: UIViewController {
collectionView.showsHorizontalScrollIndicator = false
collectionView.alwaysBounceHorizontal = true
collectionView.register(PreviewCollectionViewCell.self, forCellWithReuseIdentifier: NSStringFromClass(PreviewCollectionViewCell.self))
collectionView.register(PreviewSupplementaryView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self))
collectionView.register(PreviewSupplementaryView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self))

return collectionView
}()
Expand Down Expand Up @@ -144,11 +144,11 @@ open class ImagePickerSheetController: UIViewController {
modalPresentationStyle = .custom
transitioningDelegate = self

NotificationCenter.default.addObserver(sheetController, selector: #selector(SheetController.handleCancelAction), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
NotificationCenter.default.addObserver(sheetController, selector: #selector(SheetController.handleCancelAction), name: UIApplication.didEnterBackgroundNotification, object: nil)
}

deinit {
NotificationCenter.default.removeObserver(sheetController, name: .UIApplicationDidEnterBackground, object: nil)
NotificationCenter.default.removeObserver(sheetController, name: UIApplication.didEnterBackgroundNotification, object: nil)
}

// MARK: - View Lifecycle
Expand Down Expand Up @@ -202,6 +202,12 @@ open class ImagePickerSheetController: UIViewController {
open func addAction(_ action: ImagePickerAction) {
sheetController.addAction(action)
view.setNeedsLayout()

// Explicitly disable animations
CATransaction.begin()
CATransaction.setDisableActions(true)
self.view.layoutIfNeeded()
CATransaction.commit()
}

// MARK: - Images
Expand Down Expand Up @@ -424,9 +430,9 @@ extension ImagePickerSheetController: UICollectionViewDataSource {

public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath:
IndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self), for: indexPath) as! PreviewSupplementaryView
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self), for: indexPath) as! PreviewSupplementaryView
view.isUserInteractionEnabled = false
view.buttonInset = UIEdgeInsetsMake(0.0, previewCheckmarkInset, previewCheckmarkInset, 0.0)
view.buttonInset = UIEdgeInsets.init(top: 0.0, left: previewCheckmarkInset, bottom: previewCheckmarkInset, right: 0.0)
view.selected = selectedAssetIndices.contains(indexPath.section)

supplementaryViews[indexPath.section] = view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PreviewCollectionView: UICollectionView {
if !bouncing {
let possibleIndexPath = indexPathForItem(at: gestureRecognizer.location(in: self))
if let indexPath = possibleIndexPath {
selectItem(at: indexPath, animated: false, scrollPosition: UICollectionViewScrollPosition())
selectItem(at: indexPath, animated: false, scrollPosition: UICollectionView.ScrollPosition())
delegate?.collectionView?(self, didSelectItemAt: indexPath)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PreviewCollectionViewLayout: UICollectionViewFlowLayout {
return layoutAttributes
.filter { rect.intersects($0.frame) }
.reduce([UICollectionViewLayoutAttributes]()) { memo, attributes in
if let supplementaryAttributes = layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: attributes.indexPath) {
if let supplementaryAttributes = layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: attributes.indexPath) {
return memo + [attributes, supplementaryAttributes]
}
return memo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PreviewSupplementaryView: UICollectionReusableView {
let button = UIButton()
button.tintColor = .white
button.isUserInteractionEnabled = false
button.setImage(PreviewSupplementaryView.checkmarkImage, for: UIControlState())
button.setImage(PreviewSupplementaryView.checkmarkImage, for: UIControl.State())
button.setImage(PreviewSupplementaryView.selectedCheckmarkImage, for: .selected)

return button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SheetActionCollectionViewCell: SheetCollectionViewCell {
override func layoutSubviews() {
super.layoutSubviews()

textLabel.frame = UIEdgeInsetsInsetRect(bounds, backgroundInsets)
textLabel.frame = bounds.inset(by: backgroundInsets)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SheetCollectionViewCell: UICollectionViewCell {

let layerMask = layer.mask as? CAShapeLayer
layerMask?.frame = bounds
layerMask?.path = maskPathWithRect(UIEdgeInsetsInsetRect(bounds, backgroundInsets), roundedCorner: roundedCorners)
layerMask?.path = maskPathWithRect(bounds.inset(by: backgroundInsets), roundedCorner: roundedCorners)
}

fileprivate func maskPathWithRect(_ rect: CGRect, roundedCorner: RoundedCorner) -> CGPath {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SheetPreviewCollectionViewCell: SheetCollectionViewCell {
override func layoutSubviews() {
super.layoutSubviews()

collectionView?.frame = UIEdgeInsetsInsetRect(bounds, backgroundInsets)
collectionView?.frame = bounds.inset(by: backgroundInsets)
}

}