Skip to content
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
14 changes: 5 additions & 9 deletions MagazineLayout/Public/MagazineLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,21 @@ public final class MagazineLayout: UICollectionViewLayout {
/// - flipsHorizontallyInOppositeLayoutDirection: Indicates whether the horizontal coordinate
/// system is automatically flipped at appropriate times. In practice, this is used to support
/// right-to-left layout.
/// - verticalLayoutDirection: The vertical layout direction of items in the collection view. This property changes the
/// behavior of scroll-position-preservation when performing batch updates or when the collection view's bounds changes.
public init(
flipsHorizontallyInOppositeLayoutDirection: Bool = true,
verticalLayoutDirection: MagazineLayoutVerticalLayoutDirection = .topToBottom)
{
public init(flipsHorizontallyInOppositeLayoutDirection: Bool = true) {
_flipsHorizontallyInOppositeLayoutDirection = flipsHorizontallyInOppositeLayoutDirection
self.verticalLayoutDirection = verticalLayoutDirection
super.init()
}

required init?(coder aDecoder: NSCoder) {
_flipsHorizontallyInOppositeLayoutDirection = true
verticalLayoutDirection = .topToBottom
super.init(coder: aDecoder)
}

// MARK: Public

/// The vertical layout direction of items in the collection view. This property changes the behavior of
/// scroll-position-preservation when performing batch updates or when the collection view's bounds changes.
public var verticalLayoutDirection = MagazineLayoutVerticalLayoutDirection.topToBottom

override public class var layoutAttributesClass: AnyClass {
return MagazineLayoutCollectionViewLayoutAttributes.self
Expand Down Expand Up @@ -844,7 +841,6 @@ public final class MagazineLayout: UICollectionViewLayout {
// MARK: Private

private let _flipsHorizontallyInOppositeLayoutDirection: Bool
private let verticalLayoutDirection: MagazineLayoutVerticalLayoutDirection

private lazy var modelState: ModelState = {
return ModelState(currentVisibleBoundsProvider: { [weak self] in
Expand Down
11 changes: 7 additions & 4 deletions Tests/ContentInsetAdjustingContentOffsetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import XCTest
final class ContentInsetAdjustingContentOffsetTests: XCTestCase {

func testContentOffsetIsNotAdjustedForTopInsetChangeWithToTopBottomLayout() {
let layout = MagazineLayout(verticalLayoutDirection: .topToBottom)
let layout = MagazineLayout()
let collectionView = StubCollectionView(
frame: .zero,
collectionViewLayout: layout)
Expand All @@ -33,7 +33,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
}

func testContentOffsetIsAdjustedForTopInsetChangeWithBottomToTopLayout() {
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
let layout = MagazineLayout()
layout.verticalLayoutDirection = .bottomToTop
let collectionView = StubCollectionView(
frame: .zero,
collectionViewLayout: layout)
Expand All @@ -47,7 +48,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
}

func testContentOffsetIsAdjustedForBottomInsetChangeWithBottomToTopLayout() {
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
let layout = MagazineLayout()
layout.verticalLayoutDirection = .bottomToTop
let collectionView = StubCollectionView(
frame: .zero,
collectionViewLayout: layout)
Expand All @@ -61,7 +63,8 @@ final class ContentInsetAdjustingContentOffsetTests: XCTestCase {
}

func testContentOffsetIsAdjustedForTopAndBottomInsetChangesWithBottomToTopLayout() {
let layout = MagazineLayout(verticalLayoutDirection: .bottomToTop)
let layout = MagazineLayout()
layout.verticalLayoutDirection = .bottomToTop
let collectionView = StubCollectionView(
frame: .zero,
collectionViewLayout: layout)
Expand Down