Last active
April 3, 2020 02:19
-
-
Save aduuub/b0f0e47f15e5eee071f837381851c6c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseViewController: UIViewController { | |
var loadingView: UIView? | |
/// Called when the interactive view controller popping gesture is attempted from the right hand side. | |
/// The view controller should override this if it wants to change its behaviour. | |
/// | |
/// - Returns: true if you want to prevent the interactive gesture. | |
func preventInteractivePopGesture() -> Bool { | |
let isNavBarVisible: Bool = navController?.isNavigationBarHidden == false | |
let isBackButtonVisible: Bool = self.navigationItem.leftBarButtonItem != nil | |
let isLoading: Bool = loadingView != nil | |
if isNavBarVisible && isBackButtonVisible, isLoading == false { | |
// Allow the user to swipe back | |
return false | |
} | |
// Prevent all other cases unless it is specific to the view controller. | |
// In which case they can override this method and return a custom result | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment