Skip to content

Commit

Permalink
Merge pull request #63 from Inspirato/develop
Browse files Browse the repository at this point in the history
carousel bug fixes
  • Loading branch information
justinvallely authored Oct 19, 2017
2 parents d10b6c3 + 6ee97bb commit e0b9c10
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Master

## 3.2.1 (2017-10-19)

##### Bug Fixes

* Fixes issue with loading the first image when a page isn't specified in the presentation completion block
* Fixes unit tests

## 3.2.0 (2017-10-18)

##### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftPhotoGallery/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.0</string>
<string>3.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 3 additions & 1 deletion Example/SwiftPhotoGallery/MainCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class MainCollectionViewController: UICollectionViewController {
gallery.modalPresentationStyle = .custom
gallery.transitioningDelegate = self

// present(gallery, animated: true, completion: nil)
/// Load the first page like this:

// present(gallery, animated: true, completion: nil)

/// Or load on a specific page like this:

Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.0</string>
<string>3.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 3 additions & 1 deletion Example/Tests/SwiftPhotoGalleryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class SwiftPhotoGalleryTests: XCTestCase {

func testProgramaticInitialization() {
testGallery.viewDidLoad()

testGallery.isRevolvingCarouselEnabled = false

expect(self.testGallery.delegate).toNot(beNil())
expect(self.testGallery.delegate) === testHelper

Expand All @@ -44,6 +45,7 @@ class SwiftPhotoGalleryTests: XCTestCase {

func testFirstImagesLoadedAfterInitialization() {
testGallery.viewDidLoad()
testGallery.isRevolvingCarouselEnabled = false

let indexPath = IndexPath(item: 0, section: 0)
testGallery.imageCollectionView.reloadItems(at: [indexPath])
Expand Down
19 changes: 16 additions & 3 deletions Pod/Classes/SwiftPhotoGallery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import UIKit
public class SwiftPhotoGallery: UIViewController {

fileprivate var animateImageTransition = false
fileprivate var isViewFirstAppearing = true

public weak var dataSource: SwiftPhotoGalleryDataSource?
public weak var delegate: SwiftPhotoGalleryDelegate?
Expand Down Expand Up @@ -72,10 +73,11 @@ public class SwiftPhotoGallery: UIViewController {
}
get {
pageBeforeRotation = Int(imageCollectionView.contentOffset.x / imageCollectionView.frame.size.width)
guard isRevolvingCarouselEnabled else {
if isRevolvingCarouselEnabled {
return Int(imageCollectionView.contentOffset.x / imageCollectionView.frame.size.width) - 1
} else {
return Int(imageCollectionView.contentOffset.x / imageCollectionView.frame.size.width)
}
return Int(imageCollectionView.contentOffset.x / imageCollectionView.frame.size.width) - 1
}
}

Expand Down Expand Up @@ -170,6 +172,13 @@ public class SwiftPhotoGallery: UIViewController {
setupGestureRecognizers()
}

public override func viewDidAppear(_ animated: Bool) {
if currentPage < 0 {
currentPage = 0
isViewFirstAppearing = false
}
}

#if os(iOS)
public override var prefersStatusBarHidden: Bool {
get {
Expand Down Expand Up @@ -416,7 +425,11 @@ extension SwiftPhotoGallery: UICollectionViewDataSource {
cell.image = getImage(currentPage: 0)
case UICollectionElementKindSectionHeader:
cell = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "SwiftPhotoGalleryCell", for: indexPath) as! SwiftPhotoGalleryCell
cell.image = getImage(currentPage: numberOfImages - 1)
if isViewFirstAppearing {
cell.image = getImage(currentPage: 0)
} else {
cell.image = getImage(currentPage: numberOfImages - 1)
}
default:
assertionFailure("Unexpected element kind")
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftPhotoGallery.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "SwiftPhotoGallery"
s.version = "3.2.0"
s.version = "3.2.1"
s.summary = "Photo gallery for iOS and tvOS written in Swift"
s.description = <<-DESC
"Photo gallery for iOS and tvOS written in Swift. Photos can be panned and zoomed (iOS). Includes a customizable page indicator, support for any orientation (iOS), and supports images of varying sizes. Includes unit tests."
Expand Down

0 comments on commit e0b9c10

Please sign in to comment.