-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create superClass for loading view and empty state views
- Loading branch information
grenos
committed
Apr 12, 2020
1 parent
c0b7c87
commit 6a1c689
Showing
6 changed files
with
74 additions
and
55 deletions.
There are no files selected for viewing
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
Binary file modified
BIN
+576 Bytes
(100%)
...odeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
67 changes: 67 additions & 0 deletions
67
GHFollowers/Components/ViewControllers/GFDataLoadingVC.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// GFDataLoadingVC.swift | ||
// GHFollowers | ||
// | ||
// Created by Vasileios Gkreen on 12/04/2020. | ||
// Copyright © 2020 Vasileios Gkreen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class GFDataLoadingVC: UIViewController { | ||
|
||
var containerView: UIView! | ||
|
||
func showLoadingView() { | ||
// init container view and set it to fill the entire screen | ||
containerView = UIView(frame: view.bounds) | ||
// add the container view into the VC view (which ever is going to call this func) | ||
view.addSubview(containerView) | ||
|
||
containerView.backgroundColor = .systemBackground | ||
containerView.alpha = 0 | ||
|
||
// animate alpha | ||
UIView.animate(withDuration: 0.25) { | ||
self.containerView.alpha = 0.8 | ||
} | ||
|
||
|
||
// add activity indicator | ||
let activityIndicator = UIActivityIndicatorView(style: .large) | ||
containerView.addSubview(activityIndicator) | ||
|
||
activityIndicator.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
// center indicator on containerView | ||
NSLayoutConstraint.activate([ | ||
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor) | ||
]) | ||
|
||
activityIndicator.startAnimating() | ||
|
||
} | ||
|
||
func dismissLoadingView() { | ||
// We will always going to dismiss Loading View from a background thread | ||
// because we call this function from the Network manager closure (promise) | ||
// to avoid that we need to throw it in the main thread | ||
DispatchQueue.main.async { | ||
self.containerView.removeFromSuperview() | ||
self.containerView = nil | ||
} | ||
} | ||
|
||
|
||
// calling this function from a VC we wiil pass the message and a the view so we know where to constrain it | ||
func showEmptyStateView(with message: String, in view: UIView) { | ||
let emptyStateView = GFEmptyStateView(message: message) | ||
// fill up the entire screen | ||
emptyStateView.frame = view.bounds | ||
// add it to the VC subView | ||
view.addSubview(emptyStateView) | ||
} | ||
|
||
|
||
} |
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
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
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