@@ -18,6 +18,15 @@ open class BaseViewController: UIViewController {
1818 open var navigationBarStyle : NavigationBar . Style { . text( alignment: . center) }
1919 public private( set) lazy var navigationBar = NavigationBar (
2020 style: navigationBarStyle, height: Constant . navigationBarHeight)
21+ private lazy var interactionBlockerView = UIView ( ) . then {
22+ $0. backgroundColor = . clear
23+ $0. isHidden = true
24+ $0. isUserInteractionEnabled = true
25+ }
26+ private lazy var activityIndicator = UIActivityIndicatorView ( style: . large) . then {
27+ $0. hidesWhenStopped = true
28+ }
29+
2130 public override var title : String ? {
2231 get { navigationBar. title }
2332 set { navigationBar. title = newValue }
@@ -29,12 +38,27 @@ open class BaseViewController: UIViewController {
2938 super. viewDidLoad ( )
3039 setupNavigationBar ( )
3140 setNavigationBarHidden ( false )
41+
42+ view. addSubview ( interactionBlockerView)
43+ interactionBlockerView. snp. makeConstraints { make in
44+ make. top. equalTo ( view. safeAreaLayoutGuide. snp. top)
45+ make. leading. trailing. bottom. equalToSuperview ( )
46+ }
47+
48+ view. addSubview ( activityIndicator)
49+ activityIndicator. snp. makeConstraints { make in
50+ make. center. equalToSuperview ( )
51+ }
3252 }
3353
3454 open override func viewDidLayoutSubviews( ) {
3555 super. viewDidLayoutSubviews ( )
3656 updateBottomSafeArea ( )
3757 view. bringSubviewToFront ( navigationBar)
58+ if interactionBlockerView. isHidden == false {
59+ view. bringSubviewToFront ( interactionBlockerView)
60+ view. bringSubviewToFront ( activityIndicator)
61+ }
3862 }
3963
4064 public func setNavigationBarHidden( _ isHidden: Bool ) {
@@ -52,6 +76,7 @@ open class BaseViewController: UIViewController {
5276
5377 private func setupNavigationBar( ) {
5478 navigationController? . setNavigationBarHidden ( true , animated: false )
79+ navigationController? . interactivePopGestureRecognizer? . delegate = self
5580 view. addSubview ( navigationBar)
5681 navigationBar. snp. makeConstraints { make in
5782 make. bottom. equalTo ( view. safeAreaLayoutGuide. snp. top)
@@ -69,3 +94,24 @@ open class BaseViewController: UIViewController {
6994 additionalSafeAreaInsets. bottom = TabBarView . Constant. tabBarHeight
7095 }
7196}
97+
98+ extension BaseViewController : UIGestureRecognizerDelegate {
99+ public func gestureRecognizerShouldBegin( _ gestureRecognizer: UIGestureRecognizer ) -> Bool {
100+ return true
101+ }
102+ }
103+
104+ extension BaseViewController {
105+ public func showLoading( ) {
106+ interactionBlockerView. isHidden = false
107+ view. bringSubviewToFront ( interactionBlockerView)
108+ view. bringSubviewToFront ( activityIndicator)
109+ activityIndicator. startAnimating ( )
110+ view. bringSubviewToFront ( navigationBar)
111+ }
112+
113+ public func hideLoading( ) {
114+ interactionBlockerView. isHidden = true
115+ activityIndicator. stopAnimating ( )
116+ }
117+ }
0 commit comments