Commit 41f41bcc by Daniel Dahan

working scrollable TabBar

parent 4ca95ebc
...@@ -292,13 +292,13 @@ open class TabBar: Bar { ...@@ -292,13 +292,13 @@ open class TabBar: Bar {
} }
scrollView.contentSize = CGSize(width: w, height: height) scrollView.contentSize = CGSize(width: w, height: height)
scrollView.addSubview(line)
} else { } else {
contentView.grid.axis.columns = buttons.count contentView.grid.axis.columns = buttons.count
centerViews = buttons centerViews = buttons
addSubview(line)
} }
addSubview(line)
updateSelectionLine() updateSelectionLine()
} }
...@@ -338,7 +338,6 @@ extension TabBar { ...@@ -338,7 +338,6 @@ extension TabBar {
line.zPosition = 6000 line.zPosition = 6000
lineColor = Color.blue.base lineColor = Color.blue.base
lineHeight = 3 lineHeight = 3
scrollView.addSubview(line)
} }
/// Prepares the divider. /// Prepares the divider.
...@@ -419,31 +418,27 @@ extension TabBar { ...@@ -419,31 +418,27 @@ extension TabBar {
selected = button selected = button
isAnimating = true isAnimating = true
UIView.animate(withDuration: 0.25, animations: { [weak self, button = button] in line.animate(.duration(0.25),
guard let s = self else { .size(CGSize(width: button.width, height: lineHeight)),
return .position(CGPoint(x: button.center.x, y: .bottom == lineAlignment ? height - lineHeight : 0)),
} .completion { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, button = button, completion = completion] _ in
guard let s = self else {
s.line.width = button.width return
s.line.center.x = button.center.x }
if !s.scrollView.bounds.contains(button.frame) { s.isAnimating = false
let contentOffsetX = (button.x < s.scrollView.bounds.minX) ? button.x : button.frame.maxX - s.scrollView.bounds.width
let normalizedOffsetX = min(max(contentOffsetX, 0), s.scrollView.contentSize.width - s.scrollView.bounds.width) if isTriggeredByUserInteraction {
s.scrollView.setContentOffset(CGPoint(x: normalizedOffsetX, y: 0), animated: false) s.delegate?.tabBar?(tabBar: s, didSelect: button)
} }
}) { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, button = button, completion = completion] _ in
guard let s = self else { completion?(button)
return })
}
if !scrollView.bounds.contains(button.frame) {
s.isAnimating = false let contentOffsetX = (button.x < scrollView.bounds.minX) ? button.x : button.frame.maxX - scrollView.bounds.width
let normalizedOffsetX = min(max(contentOffsetX, 0), scrollView.contentSize.width - scrollView.bounds.width)
if isTriggeredByUserInteraction { scrollView.setContentOffset(CGPoint(x: normalizedOffsetX, y: 0), animated: true)
s.delegate?.tabBar?(tabBar: s, didSelect: button)
}
completion?(button)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment