Skip to content

Commit 113c5f4

Browse files
authored
Make verticalLayoutDirection configurable after initialization (#146)
1 parent 545707d commit 113c5f4

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

MagazineLayout/Public/MagazineLayout.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,21 @@ public final class MagazineLayout: UICollectionViewLayout {
3030
/// - flipsHorizontallyInOppositeLayoutDirection: Indicates whether the horizontal coordinate
3131
/// system is automatically flipped at appropriate times. In practice, this is used to support
3232
/// right-to-left layout.
33-
/// - verticalLayoutDirection: The vertical layout direction of items in the collection view. This property changes the
34-
/// behavior of scroll-position-preservation when performing batch updates or when the collection view's bounds changes.
35-
public init(
36-
flipsHorizontallyInOppositeLayoutDirection: Bool = true,
37-
verticalLayoutDirection: MagazineLayoutVerticalLayoutDirection = .topToBottom)
38-
{
33+
public init(flipsHorizontallyInOppositeLayoutDirection: Bool = true) {
3934
_flipsHorizontallyInOppositeLayoutDirection = flipsHorizontallyInOppositeLayoutDirection
40-
self.verticalLayoutDirection = verticalLayoutDirection
4135
super.init()
4236
}
4337

4438
required init?(coder aDecoder: NSCoder) {
4539
_flipsHorizontallyInOppositeLayoutDirection = true
46-
verticalLayoutDirection = .topToBottom
4740
super.init(coder: aDecoder)
4841
}
4942

5043
// MARK: Public
44+
45+
/// The vertical layout direction of items in the collection view. This property changes the behavior of
46+
/// scroll-position-preservation when performing batch updates or when the collection view's bounds changes.
47+
public var verticalLayoutDirection = MagazineLayoutVerticalLayoutDirection.topToBottom
5148

5249
override public class var layoutAttributesClass: AnyClass {
5350
return MagazineLayoutCollectionViewLayoutAttributes.self
@@ -844,7 +841,6 @@ public final class MagazineLayout: UICollectionViewLayout {
844841
// MARK: Private
845842

846843
private let _flipsHorizontallyInOppositeLayoutDirection: Bool
847-
private let verticalLayoutDirection: MagazineLayoutVerticalLayoutDirection
848844

849845
private lazy var modelState: ModelState = {
850846
return ModelState(currentVisibleBoundsProvider: { [weak self] in

Tests/ContentInsetAdjustingContentOffsetTests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import XCTest
1919
final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
2020

2121
func testContentOffsetIsNotAdjustedForTopInsetChangeWithToTopBottomLayout() {
22-
let layout = MagazineLayout(verticalLayoutDirection: .topToBottom)
22+
let layout = MagazineLayout()
2323
let collectionView = StubCollectionView(
2424
frame: .zero,
2525
collectionViewLayout: layout)
@@ -33,7 +33,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
3333
}
3434

3535
func testContentOffsetIsAdjustedForTopInsetChangeWithBottomToTopLayout() {
36-
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
36+
let layout = MagazineLayout()
37+
layout.verticalLayoutDirection = .bottomToTop
3738
let collectionView = StubCollectionView(
3839
frame: .zero,
3940
collectionViewLayout: layout)
@@ -47,7 +48,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
4748
}
4849

4950
func testContentOffsetIsAdjustedForBottomInsetChangeWithBottomToTopLayout() {
50-
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
51+
let layout = MagazineLayout()
52+
layout.verticalLayoutDirection = .bottomToTop
5153
let collectionView = StubCollectionView(
5254
frame: .zero,
5355
collectionViewLayout: layout)
@@ -61,7 +63,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
6163
}
6264

6365
func testContentOffsetIsAdjustedForTopAndBottomInsetChangesWithBottomToTopLayout() {
64-
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
66+
let layout = MagazineLayout()
67+
layout.verticalLayoutDirection = .bottomToTop
6568
let collectionView = StubCollectionView(
6669
frame: .zero,
6770
collectionViewLayout: layout)

0 commit comments

Comments
 (0)