Skip to content

Commit

Permalink
Merge pull request #339 from mohn93/develop
Browse files Browse the repository at this point in the history
Add  hiddenWhenSkeletonIsActive property
  • Loading branch information
Juanpe authored Oct 19, 2020
2 parents 5e22f38 + a87f730 commit c329553
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ You can change the skeleton configuration at any time like its colour, animation
(4) view.updateAnimatedGradientSkeleton() // Gradient animated
```

**Hiding views when the animation starts**

Sometimes you wanna hide some view when the animation starts, so there is a quick property that you can use to make this happen:

```swift
view.isHiddenWhenSkeletonIsActive = true // This works only when isSkeletonable = true
```

**Debug**

Expand Down
1 change: 1 addition & 0 deletions Sources/Extensions/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UIKit
// codebeat:disable[TOO_MANY_IVARS]
enum ViewAssociatedKeys {
static var skeletonable = "skeletonable"
static var hiddenWhenSkeletonIsActive = "hiddenWhenSkeletonIsActive"
static var status = "status"
static var skeletonLayer = "layer"
static var flowDelegate = "flowDelegate"
Expand Down
11 changes: 11 additions & 0 deletions Sources/Extensions/UIView+IBInspectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public extension UIView {
get { return skeletonable }
set { skeletonable = newValue }
}

@IBInspectable
var isHiddenWhenSkeletonIsActive: Bool {
get { return hiddenWhenSkeletonIsActive }
set { hiddenWhenSkeletonIsActive = newValue }
}

@IBInspectable
var skeletonCornerRadius: Float {
Expand All @@ -23,6 +29,11 @@ public extension UIView {
get { return ao_get(pkey: &ViewAssociatedKeys.skeletonable) as? Bool ?? false }
set { ao_set(newValue, pkey: &ViewAssociatedKeys.skeletonable) }
}

private var hiddenWhenSkeletonIsActive: Bool {
get { return ao_get(pkey: &ViewAssociatedKeys.hiddenWhenSkeletonIsActive) as? Bool ?? false }
set { ao_set(newValue, pkey: &ViewAssociatedKeys.hiddenWhenSkeletonIsActive) }
}

private var skeletonableCornerRadius: Float {
get { return ao_get(pkey: &ViewAssociatedKeys.skeletonCornerRadius) as? Float ?? 0.0 }
Expand Down
6 changes: 6 additions & 0 deletions Sources/SkeletonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ extension UIView {
}

private func recursiveShowSkeleton(skeletonConfig config: SkeletonConfig, root: UIView? = nil) {
if isHiddenWhenSkeletonIsActive {
isHidden = true
}
guard isSkeletonable && !isSkeletonActive else { return }
currentSkeletonConfig = config
swizzleLayoutSubviews()
Expand Down Expand Up @@ -183,6 +186,9 @@ extension UIView {

private func recursiveHideSkeleton(reloadDataAfter reload: Bool, transition: SkeletonTransitionStyle, root: UIView? = nil) {
guard isSkeletonActive else { return }
if isHiddenWhenSkeletonIsActive {
isHidden = false
}
currentSkeletonConfig?.transition = transition
isUserInteractionEnabled = true
removeDummyDataSourceIfNeeded(reloadAfter: reload)
Expand Down

0 comments on commit c329553

Please sign in to comment.