Commit 608a8a06 by Daniel Dahan

issue-931: Fixed issue where selectedTabItem was not updated correctly during a…

issue-931: Fixed issue where selectedTabItem was not updated correctly during a porgrammatic transition.
parent 51789152
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Updated to [Motion 1.2.3](https://github.com/CosmicMind/Motion/releases/tag/1.2.3). * Updated to [Motion 1.2.3](https://github.com/CosmicMind/Motion/releases/tag/1.2.3).
* [issue-919](https://github.com/CosmicMind/Material/issues/919): Fixed issue where lifecycle methods were being called on tab item view controllers prematurely. * [issue-919](https://github.com/CosmicMind/Material/issues/919): Fixed issue where lifecycle methods were being called on tab item view controllers prematurely.
* [pr-923](https://github.com/CosmicMind/Material/pull/923): Merge PR that fixes [issue-919](https://github.com/CosmicMind/Material/issues/919). * [pr-923](https://github.com/CosmicMind/Material/pull/923): Merge PR that fixes [issue-919](https://github.com/CosmicMind/Material/issues/919).
* [issue-931](https://github.com/CosmicMind/Material/issues/931): Fixed issue where selectedTabItem was not updated correctly during a porgrammatic transition.
## 2.12.3 ## 2.12.3
......
...@@ -328,14 +328,13 @@ fileprivate extension TabBar { ...@@ -328,14 +328,13 @@ fileprivate extension TabBar {
} }
/** /**
Prepares the line animation handlers. Prepares the tabItem animation handler.
- Parameter tabItem: A TabItem. - Parameter tabItem: A TabItem.
*/ */
func prepareTabItemHandler(tabItem: TabItem) { func prepareTabItemHandler(tabItem: TabItem) {
removeTabItemHandler(tabItem: tabItem) removeTabItemHandler(tabItem: tabItem)
tabItem.addTarget(self, action: #selector(handleTabItemsChange(tabItem:)), for: .touchUpInside) tabItem.addTarget(self, action: #selector(handleTabItemsChange(tabItem:)), for: .touchUpInside)
tabItem.addTarget(self, action: #selector(handleLineAnimation(tabItem:)), for: .touchUpInside)
} }
/// Prepares the contentView. /// Prepares the contentView.
...@@ -411,23 +410,18 @@ fileprivate extension TabBar { ...@@ -411,23 +410,18 @@ fileprivate extension TabBar {
fileprivate extension TabBar { fileprivate extension TabBar {
/** /**
Removes the line animation handlers. Removes the tabItem animation handler.
- Parameter tabItem: A TabItem. - Parameter tabItem: A TabItem.
*/ */
func removeTabItemHandler(tabItem: TabItem) { func removeTabItemHandler(tabItem: TabItem) {
tabItem.removeTarget(self, action: #selector(handleLineAnimation(tabItem:)), for: .touchUpInside) tabItem.removeTarget(self, action: #selector(handleTabItemsChange(tabItem:)), for: .touchUpInside)
} }
} }
fileprivate extension TabBar { fileprivate extension TabBar {
@objc
func handleTabItemsChange(tabItem: TabItem) {
selectedTabItem = tabItem
}
/// Handles the tabItem touch event. /// Handles the tabItem touch event.
@objc @objc
func handleLineAnimation(tabItem: TabItem) { func handleTabItemsChange(tabItem: TabItem) {
guard !(false == delegate?.tabBar?(tabBar: self, shouldSelect: tabItem)) else { guard !(false == delegate?.tabBar?(tabBar: self, shouldSelect: tabItem)) else {
return return
} }
...@@ -463,6 +457,15 @@ extension TabBar { ...@@ -463,6 +457,15 @@ extension TabBar {
extension TabBar { extension TabBar {
/** /**
Retrieves the tabItem color for a given state.
- Parameter for state: A TabItemState.
- Returns: A UIColor.
*/
open func getTabItemColor(for state: TabItemState) -> UIColor {
return tabItemsColorForState[state]!
}
/**
Sets the color for the tabItems given a TabItemState. Sets the color for the tabItems given a TabItemState.
- Parameter _ color: A UIColor. - Parameter _ color: A UIColor.
- Parameter for state: A TabItemState. - Parameter for state: A TabItemState.
...@@ -473,6 +476,15 @@ extension TabBar { ...@@ -473,6 +476,15 @@ extension TabBar {
} }
/** /**
Retrieves the line color for a given state.
- Parameter for state: A TabItemLineState.
- Returns: A UIColor.
*/
open func getLineColor(for state: TabItemLineState) -> UIColor {
return lineColorForState[state]!
}
/**
Sets the color for the line given a TabItemLineState. Sets the color for the line given a TabItemLineState.
- Parameter _ color: A UIColor. - Parameter _ color: A UIColor.
- Parameter for state: A TabItemLineState. - Parameter for state: A TabItemLineState.
...@@ -520,6 +532,8 @@ fileprivate extension TabBar { ...@@ -520,6 +532,8 @@ fileprivate extension TabBar {
delegate?.tabBar?(tabBar: self, willSelect: tabItem) delegate?.tabBar?(tabBar: self, willSelect: tabItem)
} }
selectedTabItem = tabItem
line.animate(.duration(0.25), line.animate(.duration(0.25),
.size(width: tabItem.bounds.width, height: lineHeight), .size(width: tabItem.bounds.width, height: lineHeight),
.position(x: tabItem.center.x, y: .bottom == lineAlignment ? bounds.height - lineHeight / 2 : lineHeight / 2), .position(x: tabItem.center.x, y: .bottom == lineAlignment ? bounds.height - lineHeight / 2 : lineHeight / 2),
......
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