Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post show/update/hide notifications #227

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Sources/SkeletonFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import UIKit

import UIKit

protocol SkeletonFlowDelegate {
func willBeginShowingSkeletons(rootView: UIView)
func didShowSkeletons(rootView: UIView)
Expand All @@ -15,17 +17,21 @@ protocol SkeletonFlowDelegate {

class SkeletonFlowHandler: SkeletonFlowDelegate {
func willBeginShowingSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .willBeginShowingSkeletons, object: rootView, userInfo: nil)
rootView.addAppNotificationsObservers()
}

func didShowSkeletons(rootView: UIView) {
printSkeletonHierarchy(in: rootView)
NotificationCenter.default.post(name: .didShowSkeletons, object: rootView, userInfo: nil)
}

func willBeginUpdatingSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .willBeginUpdatingSkeletons, object: rootView, userInfo: nil)
}

func didUpdateSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .didUpdateSkeletons, object: rootView, userInfo: nil)
}

func willBeginLayingSkeletonsIfNeeded(rootView: UIView) {
Expand All @@ -35,10 +41,21 @@ class SkeletonFlowHandler: SkeletonFlowDelegate {
}

func willBeginHidingSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .willBeginHidingSkeletons, object: rootView, userInfo: nil)
rootView.removeAppNoticationsObserver()
}

func didHideSkeletons(rootView: UIView) {
rootView.flowDelegate = nil
NotificationCenter.default.post(name: .didHideSkeletons, object: rootView, userInfo: nil)
}
}

public extension Notification.Name {
static let willBeginShowingSkeletons = Notification.Name("willBeginShowingSkeletons")
static let didShowSkeletons = Notification.Name("didShowSkeletons")
static let willBeginUpdatingSkeletons = Notification.Name("willBeginUpdatingSkeletons")
static let didUpdateSkeletons = Notification.Name("didUpdateSkeletons")
static let willBeginHidingSkeletons = Notification.Name("willBeginHidingSkeletons")
static let didHideSkeletons = Notification.Name("didHideSkeletons")
}