Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature loading indicator #53

Merged
merged 6 commits into from
Nov 11, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
29D699E91B70ABFC0021FA73 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29D699E71B70ABFC0021FA73 /* LaunchScreen.xib */; };
29D699F51B70ABFC0021FA73 /* ImagePickerDemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D699F41B70ABFC0021FA73 /* ImagePickerDemoTests.swift */; };
29D699FF1B70ACD50021FA73 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 29D699FE1B70ACD50021FA73 /* Podfile */; };
C3771E008DA39CF04754C8A9 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 733A7AD0105A657A80502E72 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
C3771E008DA39CF04754C8A9 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 733A7AD0105A657A80502E72 /* Pods.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down
4 changes: 2 additions & 2 deletions Demo/ImagePickerDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ DEPENDENCIES:

EXTERNAL SOURCES:
ImagePicker:
:path: ../../
:path: "../../"

SPEC CHECKSUMS:
ImagePicker: 32becfa25b8e9179e60c45411b577340d35e3e32

COCOAPODS: 0.39.0.beta.4
COCOAPODS: 0.39.0
6 changes: 3 additions & 3 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public class BottomContainerView: UIView {
public override init(frame: CGRect) {
super.init(frame: frame)

for view in [borderPickerButton, pickerButton, doneButton, stackView, topSeparator] {
addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
[borderPickerButton, pickerButton, doneButton, stackView, topSeparator].forEach {
addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
}

backgroundColor = pickerConfiguration.backgroundColor
Expand Down
44 changes: 36 additions & 8 deletions Source/BottomView/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class ImageStackView: UIView {

weak var delegate: ImageStackViewDelegate?

lazy var activityView: UIActivityIndicatorView = {
let view = UIActivityIndicatorView()
view.alpha = 0.0

return view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd ad a return here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}()

var views: [UIImageView] = {
var array = [UIImageView]()
for i in 0...3 {
Expand All @@ -35,11 +42,9 @@ class ImageStackView: UIView {

subscribe()

for view in views {
addSubview(view)
}

views[0].alpha = 1
views.forEach { addSubview($0) }
addSubview(activityView)
views.first?.alpha = 1
layoutSubviews()
}

Expand Down Expand Up @@ -85,12 +90,23 @@ class ImageStackView: UIView {
view.frame = CGRect(origin: origin, size: viewSize)
}
}

func startLoader() {
if let firstVisibleView = views.filter({ $0.alpha == 1.0 }).last {
activityView.frame.origin.x = firstVisibleView.center.x
activityView.frame.origin.y = firstVisibleView.center.y
}

activityView.startAnimating()
UIView.animateWithDuration(0.3) {
self.activityView.alpha = 1.0
}
}
}

extension ImageStackView {

func imageDidPush(notification: NSNotification) {

//TODO indexOf in swift 2
let emptyView = views.filter {$0.image == nil}.first

Expand All @@ -100,12 +116,14 @@ extension ImageStackView {

if let sender = notification.object as? ImageStack {
renderViews(sender.assets)
activityView.stopAnimating()
}
}

func imageStackDidChangeContent(notification: NSNotification) {
if let sender = notification.object as? ImageStack {
renderViews(sender.assets)
activityView.stopAnimating()
}
}

Expand All @@ -132,6 +150,13 @@ extension ImageStackView {
view.image = nil
view.alpha = 0
}

if index == photos.count {
UIView.animateWithDuration(0.3) {
self.activityView.frame.origin.x = view.center.x + 3
self.activityView.frame.origin.y = view.center.y + 3
}
}
}
}

Expand All @@ -141,9 +166,12 @@ extension ImageStackView {
UIView.animateWithDuration(0.3, animations: {
imageView.transform = CGAffineTransformMakeScale(1.05, 1.05)
}) { _ in
UIView.animateWithDuration(0.2) { _ in
UIView.animateWithDuration(0.2, animations: { () -> Void in
self.activityView.alpha = 0.0
imageView.transform = CGAffineTransformIdentity
}
}, completion: { _ in
self.activityView.stopAnimating()
})
}
}
}
4 changes: 1 addition & 3 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public class ImageGalleryView: UIView {
collectionView.registerClass(ImageGalleryViewCell.self,
forCellWithReuseIdentifier: CollectionView.reusableIdentifier)

for view in [collectionView, topSeparator] {
addSubview(view)
}
[collectionView, topSeparator].forEach { addSubview($0) }

topSeparator.addSubview(indicator)
imagesBeforeLoading = 0
Expand Down
1 change: 1 addition & 0 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public class ImagePickerController: UIViewController {
extension ImagePickerController: BottomContainerViewDelegate {

func pickerButtonDidPress() {
bottomContainer.stackView.startLoader()
collapseGalleryView { [unowned self] in
self.cameraController.takePicture()
}
Expand Down