Skip to content

Commit

Permalink
mixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuhiro Hayashi committed Jul 17, 2017
1 parent 8aa9833 commit 770c724
Showing 1 changed file with 1 addition and 70 deletions.
71 changes: 1 addition & 70 deletions PagingKit/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ public class PagingMenuView: UIScrollView {
}
}

public var isInfinity = false {
didSet {
showsHorizontalScrollIndicator = !isInfinity
}
}

public override init(frame: CGRect) {
super.init(frame: frame)
containerView.frame = bounds
Expand All @@ -65,11 +59,7 @@ public class PagingMenuView: UIScrollView {

public override func layoutSubviews() {
super.layoutSubviews()

if isInfinity {
recenterIfNeeded()
}


if numberOfItem != 0 {
let visibleBounds = convert(bounds, to: containerView)
tileCell(from: max(0, visibleBounds.minX * 0.75), to: min(contentSize.width, visibleBounds.maxX * 1.5))
Expand Down Expand Up @@ -258,65 +248,6 @@ public class PagingMenuView: UIScrollView {
}
}

private func tileCellInfinity(from minX: CGFloat, to maxX: CGFloat) {
guard let dataSource = dataSource else {
return
}

if visibleCell.isEmpty {
placeNewCellOnRight(with: minX, index: numberOfItem - 1, dataSource: dataSource)
}

if var lastCell = visibleCell.last {
var rightEdge = lastCell.frame.maxX
while rightEdge < maxX {
rightEdge = placeNewCellOnRight(with: rightEdge, index: lastCell.index, dataSource: dataSource)
lastCell = visibleCell.last!
}
}

if var firstCell = visibleCell.first {
var leftEdge = firstCell.frame.minX
while leftEdge > minX {
leftEdge = placeNewCellOnLeft(with: leftEdge, index: firstCell.index, dataSource: dataSource)
firstCell = visibleCell.first!
}
}

var lastCell = visibleCell.last!
while lastCell.frame.minX > maxX {
lastCell.removeFromSuperview()
let recycleCell = visibleCell.removeLast()

// enqueue
if let cells = queue[recycleCell.identifier] {
queue[recycleCell.identifier] = cells + [recycleCell]
} else {
queue[recycleCell.identifier] = [recycleCell]
}

lastCell = visibleCell.last!
}


var firstCell = visibleCell.first!
while firstCell.frame.maxX < minX {
firstCell.removeFromSuperview()
let recycleCell = visibleCell.removeFirst()

// enqueue
if let cells = queue[recycleCell.identifier] {
queue[recycleCell.identifier] = cells + [recycleCell]
} else {
queue[recycleCell.identifier] = [recycleCell]
}

firstCell = visibleCell.first!
}
}



public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let selectedCell = touches.first.flatMap { $0.location(in: self) }.flatMap { hitTest($0, with: event) as? PagingMenuCell }
if let index = selectedCell?.index {
Expand Down

0 comments on commit 770c724

Please sign in to comment.