Skip to content

Commit

Permalink
Fixed background color warning in UITableViewHeaderFooterView (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanpe authored Jun 28, 2021
1 parent ee94dd8 commit 220fc40
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Extensions/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ViewAssociatedKeys {
static var labelViewState = "labelViewState"
static var imageViewState = "imageViewState"
static var buttonViewState = "buttonViewState"
static var headerFooterViewState = "headerFooterViewState"
static var currentSkeletonConfig = "currentSkeletonConfig"
static var skeletonCornerRadius = "skeletonCornerRadius"
static var disabledWhenSkeletonIsActive = "disabledWhenSkeletonIsActive"
Expand Down
10 changes: 10 additions & 0 deletions Sources/Helpers/PrepareForSkeletonProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ extension UIButton {
}
}
}

extension UITableViewHeaderFooterView {
override func prepareViewForSkeleton() {
backgroundView?.backgroundColor = .clear

if isUserInteractionDisabledWhenSkeletonIsActive {
isUserInteractionEnabled = false
}
}
}
19 changes: 19 additions & 0 deletions Sources/Recoverable/Recoverable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@ extension UIButton {
}
}
}

extension UITableViewHeaderFooterView {
var headerFooterState: RecoverableTableViewHeaderFooterViewState? {
get { return ao_get(pkey: &ViewAssociatedKeys.headerFooterViewState) as? RecoverableTableViewHeaderFooterViewState }
set { ao_setOptional(newValue, pkey: &ViewAssociatedKeys.headerFooterViewState) }
}

override func saveViewState() {
super.saveViewState()
headerFooterState = RecoverableTableViewHeaderFooterViewState(view: self)
}

override func recoverViewState(forced: Bool) {
super.recoverViewState(forced: forced)
startTransition { [weak self] in
self?.backgroundView?.backgroundColor = self?.headerFooterState?.backgroundViewColor
}
}
}
8 changes: 8 additions & 0 deletions Sources/Recoverable/RecoverableViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ struct RecoverableButtonViewState {
self.title = view.titleLabel?.text
}
}

struct RecoverableTableViewHeaderFooterViewState {
var backgroundViewColor: UIColor?

init(view: UITableViewHeaderFooterView) {
self.backgroundViewColor = view.backgroundView?.backgroundColor
}
}

0 comments on commit 220fc40

Please sign in to comment.