Commit 6dfc14d5 by Daniel Dahan

updated scrolling behaviour for TabBar when rotating

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