Skip to content

Commit

Permalink
Post show/update/hide notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Diogo Tridapalli <diogot@users.noreply.github.com>
  • Loading branch information
diogot committed Feb 3, 2020
1 parent ab87ba9 commit 9b01576
Showing 1 changed file with 18 additions and 1 deletion.
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")
}

0 comments on commit 9b01576

Please sign in to comment.