Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class IntentViewController: UIViewController, INUIHostedViewControlling {
@IBOutlet weak var reposLabel: UILabel!
@IBOutlet weak var followersLabel: UILabel!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
// MARK: - INUIHostedViewControlling
// Prepare your view controller for the interaction to handle.
func configureView(for parameters: Set<INParameter>, of interaction: INInteraction, interactiveBehavior: INUIInteractiveBehavior, context: INUIHostedViewContext, completion: @escaping (Bool, Set<INParameter>, CGSize) -> Void) {
guard
let intent = interaction.intent as? CheckMyGitHubIntent,
let name = intent.name
else {
return
}
activityIndicator.isHidden = false
activityIndicator.startAnimating()
Fetcher.fetch(name: name) { [weak self] user, followers in
guard let user = user else {
self?.hideActivityIndicator()
return
}
DispatchQueue.main.async {
self?.reposLabel.text = "Repos: \(user.repos)"
self?.followersLabel.text = "Followers: \(followers.count)"
self?.hideActivityIndicator()
}
}
completion(true, parameters, self.desiredSize)
}
var desiredSize: CGSize {
var size = self.extensionContext!.hostedViewMaximumAllowedSize
size.height = UIFont.systemFont(ofSize: 15).lineHeight * 3
return size
}
private func hideActivityIndicator() {
DispatchQueue.main.async {
self.activityIndicator.isHidden = true
self.activityIndicator.stopAnimating()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.