CosmicMind / Motion

A library used to create beautiful animations and transitions for iOS.

Home Page:http://cosmicmind.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using isMotionEnabled on BottomNavigationController/UITabBarController causes delegate methods to not be called

andrewc94 opened this issue · comments

It seems as though setting the delegate on a BottomNavigationController causes Motion to be disabled while enabling Motion causes delegate methods to not be called.

Material 2.13.5
Motion 1.3.4

BottomNavigationController.zip

I will take a look at your sample. Thank you for sharing this issue.

@OrkhanAlikhanov Let's confirm if this is still an issue. Thank you and apologies for taking a very long time to respond.

@DanielDahan I confirm that this issue is still there. I investigated it a bit. Here is my summary.

The issue

Setting isMotionEnabled = true changes the delegate but does not forward the delegation methods to previousTabBarDelegate.

class AppBottomNavigationController: BottomNavigationController {
  override func prepare() {
        super.prepare()
        delegate = self
        print(delegate === self) // true
        isMotionEnabled = true // changes `delegate`
        print(delegate === self) // false

        isMotionEnabled = false // sets `previousTabBarDelegate` back
        print(delegate === self) // true
    }
}

extension AppBottomNavigationController: UITabBarControllerDelegate {
    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        print("hi") // never called if `isMotionEnabled == true`
    }
}

Possible solution

I think forwarding delegation methods to the tabBarController.previousTabBarDelegate will solve the problem but I am unsure about its side effects. Here is the file where it should be done.

extension MotionTransition: UITabBarControllerDelegate {
public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

@OrkhanAlikhanov I believe this issue may be closed. Please take a look at Motion 1.4.2 to test if this is still an issue. Thank you!