Skip to content

Commit

Permalink
not treat non-visible edge cells as visible (#31)
Browse files Browse the repository at this point in the history
* make cells that is on the edge not visible

* add test
  • Loading branch information
lkzhao authored Oct 16, 2017
1 parent 1e1b5fb commit 15843a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CollectionKitTests/FlowLayoutSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class FlowLayoutSpec: QuickSpec {
layout.mockLayout(parentSize: (130, 130), (50, 50), (50, 50), (50, 50))
expect(layout.frames).to(equal(frames((0, 0, 50, 50), (60, 0, 50, 50), (0, 60, 50, 50))))
}

it("should not display cells outside of the visible area") {
let layout = FlowLayout<CGSize>().transposed()
layout.mockLayout(parentSize: (100, 50), (50, 50), (50, 50), (50, 50), (50, 50))
let visible = layout.visibleIndexes(activeFrame: CGRect(x: 50, y: 0, width: 100, height: 50))
expect(visible).to(equal([1, 2]))
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Layout/SimpleLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ open class VerticalSimpleLayout<Data>: SimpleLayout<Data> {
var visibleIndexes = [Int]()
while index < frames.count {
let frame = frames[index]
if frame.minY > activeFrame.maxY {
if frame.minY >= activeFrame.maxY {
break
}
if frame.maxY >= activeFrame.minY {
if frame.maxY > activeFrame.minY {
visibleIndexes.append(index)
}
index += 1
Expand All @@ -88,10 +88,10 @@ open class HorizontalSimpleLayout<Data>: SimpleLayout<Data> {
var visibleIndexes = [Int]()
while index < frames.count {
let frame = frames[index]
if frame.minX > activeFrame.maxX {
if frame.minX >= activeFrame.maxX {
break
}
if frame.maxX >= activeFrame.minX {
if frame.maxX > activeFrame.minX {
visibleIndexes.append(index)
}
index += 1
Expand Down

0 comments on commit 15843a1

Please sign in to comment.