Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go back in navigation hierarchy when tapping on the same tab again. #16

Closed
hemangshah opened this issue Sep 24, 2019 · 0 comments
Closed
Assignees

Comments

@hemangshah
Copy link
Owner

Tab 1 ↠ Navigation Controller ↦ View Controller 1 → View Controller 2 → View Controller 3

So we're in View Controller 3 and by tapping on the same tab (Tab 1) again, I will now take back to View Controller 1 (the first view-controller in navigation controller hierarchy).

To achieve this, I've made a slight change in on tab tapped closure block:

        hhTabBarView.onTabTapped = { (tabIndex, isSameTab, controller) in
            if isSameTab {
                if let navcon = controller as? UINavigationController {
                    navcon.popToRootViewController(animated: true)
                } else if let vc = controller as? UIViewController {
                    vc.navigationController?.popToRootViewController(animated: true)
                }
            }
            print("Selected Tab Index:\(tabIndex)")
        }

With this, there'll be a possible highlight issue will occurs as part of this change in 2.3.0, to fix this:

I am suggesting this solution: Integrate this functions in View Controller 1 (and all other where you will have similar navigation flow).

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        // This will be helpful in locking the current tab if we're already in the first view-controller in navigation flow.
        HHTabBarView.shared.lockCurrentTab()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // This will be helpful to unlock the locked tab when we're going forward from the first view-controller in navigation flow.
        HHTabBarView.shared.unlockAllTabs()
    }

P.S. Thanks Nishan for coming up with this issue. 🙏🏼

@hemangshah hemangshah self-assigned this Sep 24, 2019
@hemangshah hemangshah pinned this issue Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant