Commit 6dfc14d5 by Daniel Dahan

updated scrolling behaviour for TabBar when rotating

parent ffd475b2
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.9.0</string>
<string>2.9.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -51,6 +51,11 @@ open class ChipItem: FlatButton {
super.layoutSubviews()
layoutChipItemStyle()
}
open override func prepare() {
super.prepare()
pulseAnimation = .none
}
}
fileprivate extension ChipItem {
......@@ -113,9 +118,6 @@ public enum ChipBarStyle: Int {
}
open class ChipBar: Bar {
/// A boolean indicating if the ChipBar is in an animation state.
open fileprivate(set) var isAnimating = false
/// The total width of the chipItems.
fileprivate var chipItemsTotalWidth: CGFloat {
var w: CGFloat = 0
......@@ -156,6 +158,9 @@ open class ChipBar: Bar {
/// A delegation reference.
open weak var delegate: ChipBarDelegate?
/// The currently selected chipItem.
open fileprivate(set) var selectedChipItem: ChipItem?
/// A preset wrapper around chipItems contentEdgeInsets.
open var chipItemsContentEdgeInsetsPreset: EdgeInsetsPreset {
get {
......@@ -217,6 +222,8 @@ open class ChipBar: Bar {
}
layoutScrollView()
updateScrollView()
}
open override func prepare() {
......@@ -351,11 +358,21 @@ fileprivate extension ChipBar {
delegate?.chipBar?(chipBar: self, willSelect: chipItem)
}
isAnimating = true
selectedChipItem = chipItem
updateScrollView()
}
}
fileprivate extension ChipBar {
/// Updates the scrollView.
func updateScrollView() {
guard let v = selectedChipItem else {
return
}
if !scrollView.frame.contains(chipItem.frame) {
let contentOffsetX = (chipItem.x < scrollView.frame.minX) ? chipItem.x : chipItem.frame.maxX - scrollView.width
let normalizedOffsetX = min(max(contentOffsetX, 0), scrollView.contentSize.width - scrollView.width)
if !scrollView.bounds.contains(v.frame) {
let contentOffsetX = (v.x < scrollView.bounds.minX) ? v.x : v.frame.maxX - scrollView.bounds.width
let normalizedOffsetX = min(max(contentOffsetX, 0), scrollView.contentSize.width - scrollView.bounds.width)
scrollView.setContentOffset(CGPoint(x: normalizedOffsetX, y: 0), animated: true)
}
}
......
......@@ -210,6 +210,8 @@ open class TabBar: Bar {
layoutScrollView()
layoutLine()
updateScrollView()
}
open override func prepare() {
......@@ -401,9 +403,20 @@ fileprivate extension TabBar {
completion?(tabItem)
})
if !scrollView.frame.contains(tabItem.frame) {
let contentOffsetX = (tabItem.x < scrollView.frame.minX) ? tabItem.x : tabItem.frame.maxX - scrollView.width
let normalizedOffsetX = min(max(contentOffsetX, 0), scrollView.contentSize.width - scrollView.width)
updateScrollView()
}
}
fileprivate extension TabBar {
/// Updates the scrollView.
func updateScrollView() {
guard let v = selectedTabItem else {
return
}
if !scrollView.bounds.contains(v.frame) {
let contentOffsetX = (v.x < scrollView.bounds.minX) ? v.x : v.frame.maxX - scrollView.bounds.width
let normalizedOffsetX = min(max(contentOffsetX, 0), scrollView.contentSize.width - scrollView.bounds.width)
scrollView.setContentOffset(CGPoint(x: normalizedOffsetX, y: 0), animated: true)
}
}
......
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