diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa7d0a7..ebcdf8b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/Example/SwiftPhotoGallery/Info.plist b/Example/SwiftPhotoGallery/Info.plist
index fee1c8f..37536f8 100644
--- a/Example/SwiftPhotoGallery/Info.plist
+++ b/Example/SwiftPhotoGallery/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 3.2.0
+ 3.2.1
CFBundleSignature
????
CFBundleVersion
diff --git a/Example/SwiftPhotoGallery/MainCollectionViewController.swift b/Example/SwiftPhotoGallery/MainCollectionViewController.swift
index af926dc..e92fbc7 100644
--- a/Example/SwiftPhotoGallery/MainCollectionViewController.swift
+++ b/Example/SwiftPhotoGallery/MainCollectionViewController.swift
@@ -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:
diff --git a/Example/Tests/Info.plist b/Example/Tests/Info.plist
index dc8c70d..43869a4 100644
--- a/Example/Tests/Info.plist
+++ b/Example/Tests/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 3.2.0
+ 3.2.1
CFBundleSignature
????
CFBundleVersion
diff --git a/Example/Tests/SwiftPhotoGalleryTests.swift b/Example/Tests/SwiftPhotoGalleryTests.swift
index e84a596..85b5fb9 100644
--- a/Example/Tests/SwiftPhotoGalleryTests.swift
+++ b/Example/Tests/SwiftPhotoGalleryTests.swift
@@ -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
@@ -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])
diff --git a/Pod/Classes/SwiftPhotoGallery.swift b/Pod/Classes/SwiftPhotoGallery.swift
index eaa4ff0..6310a61 100644
--- a/Pod/Classes/SwiftPhotoGallery.swift
+++ b/Pod/Classes/SwiftPhotoGallery.swift
@@ -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?
@@ -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
}
}
@@ -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 {
@@ -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")
}
diff --git a/SwiftPhotoGallery.podspec b/SwiftPhotoGallery.podspec
index 28ae8b1..de70f0f 100644
--- a/SwiftPhotoGallery.podspec
+++ b/SwiftPhotoGallery.podspec
@@ -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."