Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Skiba committed Jan 6, 2017
1 parent eba8fda commit 7b88105
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
1 change: 0 additions & 1 deletion RIGImageGallery/RIGImageGalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ open class RIGImageGalleryViewController: UIPageViewController {
dataSource = self
delegate = self
automaticallyAdjustsScrollViewInsets = false
view.backgroundColor = .black
handleImagesUpdate(oldValue: [])
configureDoneButton()
configureActionButton()
Expand Down
42 changes: 24 additions & 18 deletions RIGImageGallery/RIGSingleImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,35 @@ open class RIGSingleImageViewController: UIViewController {
}

open let scrollView = RIGAutoCenteringScrollView()
open let activityIndicator: UIActivityIndicatorView = {
let activityIndicator = UIActivityIndicatorView()
activityIndicator.activityIndicatorViewStyle = .gray
activityIndicator.hidesWhenStopped = true
return activityIndicator
}()
open var activityIndicator: UIActivityIndicatorView? {
didSet {
oldValue?.removeFromSuperview()
if let newValue = activityIndicator {
view.addSubview(newValue)
NSLayoutConstraint.activate([
newValue.centerXAnchor.constraint(equalTo: view.layoutMarginsGuide.centerXAnchor),
newValue.centerYAnchor.constraint(equalTo: view.layoutMarginsGuide.centerYAnchor),
])
}
}
}

public convenience init(viewerItem: RIGImageGalleryItem) {
self.init()
self.viewerItem = viewerItem
viewerItemUpdated()
}

open override func loadView() {
open override func viewDidLoad() {
super.viewDidLoad()
automaticallyAdjustsScrollViewInsets = false
view = UIView()
view.addSubview(scrollView)
view.addSubview(activityIndicator)
view.clipsToBounds = true
view.addSubview(scrollView)
let indicatorView = UIActivityIndicatorView()
indicatorView.activityIndicatorViewStyle = .gray
indicatorView.hidesWhenStopped = true
self.activityIndicator = indicatorView
configureConstraints()
view.setNeedsLayout()
}

open override func viewDidLayoutSubviews() {
Expand All @@ -55,11 +63,11 @@ open class RIGSingleImageViewController: UIViewController {
private extension RIGSingleImageViewController {

func viewerItemUpdated() {
if viewerItem?.isLoading == true && !activityIndicator.isAnimating {
activityIndicator.startAnimating()
if viewerItem?.isLoading == true && activityIndicator?.isAnimating == false {
activityIndicator?.startAnimating()
}
else if viewerItem?.isLoading == false && activityIndicator.isAnimating {
activityIndicator.stopAnimating()
else if viewerItem?.isLoading == false && activityIndicator?.isAnimating == true {
activityIndicator?.stopAnimating()
}
scrollView.allowZoom = viewerItem?.image != nil
scrollView.isUserInteractionEnabled = viewerItem?.isLoading == false
Expand All @@ -71,14 +79,12 @@ private extension RIGSingleImageViewController {

func configureConstraints() {
scrollView.translatesAutoresizingMaskIntoConstraints = false
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
activityIndicator?.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
scrollView.topAnchor.constraint(equalTo: view.topAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
activityIndicator.centerXAnchor.constraint(equalTo: view.layoutMarginsGuide.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: view.layoutMarginsGuide.centerYAnchor),
])
}
}

0 comments on commit 7b88105

Please sign in to comment.