Ramotion / animated-tab-bar

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
https://www.ramotion.com/animated-tab-bar-ios-app-development-ui-library/
MIT License
11.12k stars 1.33k forks source link

change behavior when tab bar item tapped twice #281

Closed alouanemed closed 4 years ago

alouanemed commented 4 years ago

Is there any method on which I can pop the root controller when a tab bar item tapped twice, similar to the behavioir on Instagram.

igork-ramotion commented 4 years ago

@alouanemed Hey, it seems that it already should work as you expect. Please take a look at source code:

      if selectedIndex != currentIndex {
            let previousItem = items.at(selectedIndex)
            let previousContainer: UIView? = previousItem?.iconView?.icon.superview
            previousContainer?.backgroundColor = items[selectedIndex].bgDefaultColor
            previousItem?.deselectAnimation()

            let currentItem: RAMAnimatedTabBarItem = items[currentIndex]
            currentItem.playAnimation()
            let currentContainer: UIView? = currentItem.iconView?.icon.superview
            currentContainer?.backgroundColor = items[currentIndex].bgSelectedColor

            selectedIndex = index
        } else {
            if let navVC = viewControllers?[selectedIndex] as? UINavigationController {
                navVC.popToRootViewController(animated: true)
            }
        }

If user select on same item second time and current view controller is UINavigationController it will pop to root view controller. Please let me know if you have any problem with this logic

alouanemed commented 4 years ago

although I am using the latest version in my project, nothing happens when I tap multiple times on an item. what do you think? How can I debug this?

Thanks.

igork-ramotion commented 4 years ago

Please take a look at double-tap-example branch, I've add example how it works. Each time you tap on the screen next view controller will be pushed, and then if you press selected tab bar item it will pop to root view controller.

renchris commented 4 years ago

For the else statement when you say "If user select on same item second time and current view controller is UINavigationController it will pop to root view controller", how do we access that for a custom animation class?

Also, I tried to add print statements to see when the else statement runs but it doesn't run when I tap an already selected tab bar item. Why is that?