Compare commits

...

31 Commits

Author SHA1 Message Date
Carlos Enumo f859d197f3 Add prepareViewForSkeleton to SkeletonCollectionViewDataSource (#505) 2022-08-11 18:32:08 +02:00
Juanpe 3a11e233c7 Bump version 1.29.4 2022-08-11 16:15:54 +00:00
dependabot[bot] ddd4fdbb1f Bump tzinfo from 1.2.5 to 1.2.10 (#507)
Bumps [tzinfo](https://github.com/tzinfo/tzinfo) from 1.2.5 to 1.2.10.
- [Release notes](https://github.com/tzinfo/tzinfo/releases)
- [Changelog](https://github.com/tzinfo/tzinfo/blob/master/CHANGES.md)
- [Commits](https://github.com/tzinfo/tzinfo/compare/v1.2.5...v1.2.10)

---
updated-dependencies:
- dependency-name: tzinfo
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-11 18:14:28 +02:00
Juanpe Catalán 00394e0b9f Add Swift Package Index badge for platforms 2022-06-01 08:35:50 +02:00
Juanpe daea88df8f Bump version 1.29.3 2022-06-01 06:32:58 +00:00
dependabot[bot] b640c1d8ee Bump cocoapods-downloader from 1.2.2 to 1.6.3 (#497)
Bumps [cocoapods-downloader](https://github.com/CocoaPods/cocoapods-downloader) from 1.2.2 to 1.6.3.
- [Release notes](https://github.com/CocoaPods/cocoapods-downloader/releases)
- [Changelog](https://github.com/CocoaPods/cocoapods-downloader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/CocoaPods/cocoapods-downloader/compare/1.2.2...1.6.3)

---
updated-dependencies:
- dependency-name: cocoapods-downloader
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-01 08:31:25 +02:00
Juanpe 2eaf72ed0e Bump version 1.29.2 2022-01-18 14:21:59 +00:00
Juanpe Catalán 9e61ff3a85 Fix crash when text is empty (#483) 2022-01-18 15:20:32 +01:00
Juanpe Catalán 204b871f17 Update CD.yml 2022-01-18 14:56:28 +01:00
Juanpe Catalán ecb41f1885 Update stale.yml 2022-01-15 10:17:58 +01:00
Juanpe dffbd8cbfd Bump version 1.29.1 2022-01-10 15:33:01 +00:00
Juanpe Catalán 458e5fc29b Fix animation when the transition is .none (#481) 2022-01-10 16:32:00 +01:00
Juanpe a6f335df01 Bump version 1.29.0 2022-01-10 10:24:35 +00:00
Juanpe Catalán 106692fbfb Create new `SkeletonGradient constructor (#480) 2022-01-10 11:23:07 +01:00
Juanpe Catalán cb4dcfd07a Update CD.yml 2022-01-10 11:11:19 +01:00
Juanpe 419172104d Bump version 1.28.0 2022-01-10 10:09:04 +00:00
Juanpe Catalán b40a771510 Improved number of lines calculation (#479)
* Create SkeletonTextNumberOfLines

* Update README format
2022-01-10 11:07:31 +01:00
Juanpe Catalán 73b137cda6 Update CD.yml 2022-01-10 11:07:16 +01:00
Juanpe add7401058 Bump version 1.27.0 2022-01-08 12:40:21 +00:00
Tom Cheung 947e2a63c2 Add skeletonCornerRadius in SkeletonAppearance (#478)
* Add skeletonCornerRadius in SkeletonAppearance

* Remove unnecessary type casting
2022-01-08 13:39:03 +01:00
Juanpe Catalán c5462de1db Update CD.yml 2022-01-08 11:25:33 +01:00
Juanpe 00b5d614b6 Bump version 1.26.2 2022-01-08 10:22:27 +00:00
Nick Thompson 8ba48071de Fix last line text alignment when using padding insets (#477) 2022-01-08 11:20:59 +01:00
Jackson a0980380f2 Add ExampleViewController for programatically creating ViewController (#475)
* Add ExampleViewController for programatically creating view

* Update UITextViewByCodeViewController
2022-01-07 17:05:02 +01:00
Juanpe Catalán dd80fabeea Rename pod_trunk to pod_trunk.yml 2022-01-07 17:04:21 +01:00
Juanpe Catalán d89a70052c Create pod trunk workflow 2022-01-07 17:03:43 +01:00
Juanpe cd12c64e18 Bump version 1.26.1 2022-01-07 15:56:40 +00:00
Juanpe Catalán 2edd715a87 Fix skeleton flow notifications triggered multiple times (#476)
* Fix notification names

* Fix problem with multiple notifications
2022-01-07 16:55:19 +01:00
Juanpe f3cc8f0aba Bump version 1.26.0 2021-11-23 10:41:10 +00:00
Juanpe Catalán a9c22f502a Improve multiline height calculation (#466)
* update line height logic

* update property name

* update README

* update README

* Update README.md

* fix typo
2021-11-23 11:25:59 +01:00
Juanpe ee17db61c6 Bump version 1.25.2 2021-10-21 14:49:00 +00:00
38 changed files with 523 additions and 223 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
daysUntilStale: 7
daysUntilClose: 7
daysUntilStale: 5
daysUntilClose: 3
onlyLabels:
- awaiting user input
staleLabel: given up
+6 -11
View File
@@ -12,8 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup fastlane
run: brew install fastlane
- name: Setup Environment
run: |
brew install fastlane
brew install cocoapods
- name: Publish release
id: publish_release
@@ -32,9 +34,10 @@ jobs:
branch: 'main'
commit_message: 'Bump version ${{ steps.publish_release.outputs.tag_name }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Cocoapods
continue-on-error: true
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
run: |
@@ -42,14 +45,6 @@ jobs:
pod lib lint --allow-warnings
pod trunk push --allow-warnings
- name: Communicate on PR released
uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
Congratulations! 🎉 This was released as part of [SkeletonView ${{ steps.publish_release.outputs.tag_name }}](${{ steps.publish_release.outputs.html_url }}) 🚀
- name: Tweet the release
uses: ethomson/send-tweet-action@v1
with:
+16
View File
@@ -0,0 +1,16 @@
name: Pod trunk
on: [workflow_dispatch]
jobs:
release_version:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Deploy to Cocoapods
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
run: |
set -eo pipefail
pod lib lint --allow-warnings
pod trunk push --allow-warnings
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Va7-1y-Tel">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Va7-1y-Tel">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -12,7 +12,7 @@
<!--Item-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="SkeletonViewExample" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="iOS_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -88,8 +88,8 @@
<rect key="frame" x="0.0" y="287" width="375" height="282"/>
<color key="separatorColor" red="0.1061807256" green="0.84678786989999999" blue="0.031482450150000001" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellIdentifier" rowHeight="120" id="2dN-Bd-tdy" customClass="Cell" customModule="SkeletonViewExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="24.333333969116211" width="375" height="120"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellIdentifier" rowHeight="120" id="2dN-Bd-tdy" customClass="Cell" customModule="iOS_Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="44.666666030883789" width="375" height="120"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="2dN-Bd-tdy" id="7IN-F3-Mr6">
<rect key="frame" x="0.0" y="0.0" width="375" height="120"/>
@@ -299,7 +299,7 @@
<!--Item-->
<scene sceneID="Cfc-AT-AS1">
<objects>
<viewController id="dv8-ph-Ehg" sceneMemberID="viewController">
<viewController id="dv8-ph-Ehg" customClass="UITextViewByCodeViewController" customModule="iOS_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Jwx-gI-Qod">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -5,12 +5,12 @@ import UIKit
class HeaderFooterSection: UITableViewHeaderFooterView {
lazy var titleLabel: UILabel = {
let label = UILabel()
let label = UILabel()
label.text = " "
label.isSkeletonable = true
label.linesCornerRadius = 5
label.linesCornerRadius = 10
return label
}()
@@ -0,0 +1,44 @@
// Copyright © 2022 SkeletonView. All rights reserved.
import UIKit
import SkeletonView
class UITextViewByCodeViewController: UIViewController {
lazy var textView: UITextView = {
let tv = UITextView()
tv.text = " "
tv.linesCornerRadius = 10
tv.isSkeletonable = true
tv.translatesAutoresizingMaskIntoConstraints = false
return tv
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setupElementsConstraints()
showSkeletonForElements()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func setupUI() {
view.addSubview(textView)
}
func setupElementsConstraints() {
textView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 10).isActive = true
textView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor, constant: 10).isActive = true
textView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
textView.heightAnchor.constraint(equalToConstant: 100).isActive = true
}
func showSkeletonForElements() {
textView.showSkeleton()
}
}
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
E21D8BB727888D050041DBCE /* UITextViewByCodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21D8BB627888D050041DBCE /* UITextViewByCodeViewController.swift */; };
F556F5C026CD20A300A80B83 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F5B726CD20A300A80B83 /* ViewController.swift */; };
F556F5C126CD20A300A80B83 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F556F5B826CD20A300A80B83 /* Assets.xcassets */; };
F556F5C226CD20A300A80B83 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F556F5B926CD20A300A80B83 /* LaunchScreen.storyboard */; };
@@ -57,6 +58,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
E21D8BB627888D050041DBCE /* UITextViewByCodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITextViewByCodeViewController.swift; sourceTree = "<group>"; };
F556F59F26CD201B00A80B83 /* iOS Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
F556F5B726CD20A300A80B83 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
F556F5B826CD20A300A80B83 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -106,6 +108,7 @@
F556F6EC26CE813F00A80B83 /* Constants.swift */,
F556F6ED26CE813F00A80B83 /* HeaderFooterSection.swift */,
F556F5B726CD20A300A80B83 /* ViewController.swift */,
E21D8BB627888D050041DBCE /* UITextViewByCodeViewController.swift */,
F556F5B826CD20A300A80B83 /* Assets.xcassets */,
F556F5B926CD20A300A80B83 /* LaunchScreen.storyboard */,
F556F5BB26CD20A300A80B83 /* Main.storyboard */,
@@ -154,7 +157,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1300;
TargetAttributes = {
F556F59E26CD201B00A80B83 = {
CreatedOnToolsVersion = 12.5.1;
@@ -239,6 +242,7 @@
F556F6EE26CE813F00A80B83 /* Cell.swift in Sources */,
F556F5C026CD20A300A80B83 /* ViewController.swift in Sources */,
F556F6F026CE813F00A80B83 /* HeaderFooterSection.swift in Sources */,
E21D8BB727888D050041DBCE /* UITextViewByCodeViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -395,7 +399,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@@ -414,7 +418,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@@ -145,7 +145,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1300;
TargetAttributes = {
F556F5F326CD221300A80B83 = {
CreatedOnToolsVersion = 12.5.1;
@@ -317,7 +317,7 @@
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
@@ -371,7 +371,7 @@
SDKROOT = appletvos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
@@ -391,7 +391,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
@@ -410,7 +410,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
+2 -2
View File
@@ -36,7 +36,7 @@ GEM
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.2.2)
cocoapods-downloader (1.6.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
@@ -182,7 +182,7 @@ GEM
tty-screen (0.7.0)
tty-spinner (0.9.1)
tty-cursor (~> 0.7)
tzinfo (1.2.5)
tzinfo (1.2.10)
thread_safe (~> 0.1)
uber (0.1.0)
unf (0.1.4)
+52 -31
View File
@@ -8,7 +8,7 @@
<a href="https://cocoapods.org/pods/SkeletonView"><img src="https://img.shields.io/cocoapods/v/SkeletonView.svg?style=flat"></a>
<a href="https://github.com/Carthage/Carthage/"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat"></a>
<a href="https://swift.org/package-manager/"><img src="https://img.shields.io/badge/SPM-supported-Green.svg?style=flat"></a>
<img src="https://img.shields.io/badge/platforms-iOS_tvOS-green" />
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FJuanpe%2FSkeletonView%2Fbadge%3Ftype%3Dplatforms"/>
<a href="https://badge.bow-swift.io/recipe?name=SkeletonView&description=An%20elegant%20way%20to%20show%20users%20that%20something%20is%20happening%20and%20also%20prepare%20them%20to%20which%20contents%20he%20is%20waiting&url=https://github.com/juanpe/skeletonview&owner=Juanpe&avatar=https://avatars0.githubusercontent.com/u/1409041?v=4&tag=1.20.0"><img src="https://raw.githubusercontent.com/bow-swift/bow-art/master/badges/nef-playgrounds-badge.svg" alt="SkeletonView Playground" style="height:20px"></a>
</p>
@@ -250,6 +250,7 @@ public protocol SkeletonCollectionViewDataSource: UICollectionViewDataSource {
func collectionSkeletonView(_ skeletonView: UICollectionView, supplementaryViewIdentifierOfKind: String, at indexPath: IndexPath) -> ReusableCellIdentifier? // default: nil
func collectionSkeletonView(_ skeletonView: UICollectionView, skeletonCellForItemAt indexPath: IndexPath) -> UICollectionViewCell? // default: nil
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareCellForSkeleton cell: UICollectionViewCell, at indexPath: IndexPath)
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareViewForSkeleton view: UICollectionReusableView, at indexPath: IndexPath)
}
```
@@ -261,17 +262,19 @@ The rest of the process is the same as ```UITableView```
![](Assets/multilines2.png)
When using elements with text, ```SkeletonView``` draws lines to simulate text.
Besides, you can decide how many lines you want. If ```numberOfLines``` is set to zero, it will calculate how many lines needed to populate the whole skeleton and it will be drawn. Instead, if you set it to one, two or any number greater than zero, it will only draw this number of lines.
You can set some properties for multilines elements.
| Property | Values | Default | Preview
| Property | Type | Default | Preview
| ------- | ------- |------- | -------
| **Filling percent** of the last line.<br/>Please note that for views without multiple lines, the single line will be considered as the last line and **lastLineFillPercent** will be applied to that single line. | `0...100` | `70%`| ![](Assets/multiline_lastline.png)
| **Corner radius** of lines. (**NEW**) | `0...10` | `0` | ![](Assets/multiline_corner.png)
| **lastLineFillPercent** | `CGFloat` | `70`| ![](Assets/multiline_lastline.png)
| **linesCornerRadius** | `Int` | `0` | ![](Assets/multiline_corner.png)
| **skeletonLineSpacing** | `CGFloat` | `10` | ![](Assets/multiline_lineSpacing.png)
| **skeletonPaddingInsets** | `UIEdgeInsets` | `.zero` | ![](Assets/multiline_insets.png)
| **skeletonTextLineHeight** | `SkeletonTextLineHeight` | `.fixed(15)` | ![](Assets/multiline_lineHeight.png)
| **skeletonTextNumberOfLines** | `SkeletonTextNumberOfLines` | `.inherited` | ![](Assets/multiline_corner.png)
<br />
To modify the percent or radius **using code**, set the properties:
```swift
@@ -283,27 +286,55 @@ Or, if you prefer use **IB/Storyboard**:
![](Assets/multiline_customize.png)
<br />
**How to define the number of lines?**
By default, the number of lines is the same as the value of the `numberOfLines` property. And, if it's set to **zero**, it'll calculate how many lines are needed to populate the whole skeleton and draw it.
However, if you want to set a specific number of skeleton lines you can do it by setting the `skeletonTextNumberOfLines` property. This property has two possible values, `inherited` which returns `numberOfLines` value and `custom(Int)` which returns the specific number of lines specified as the associated value.
For example:
```swift
label.skeletonTextNumberOfLines = 3 // .custom(3)
```
<br />
> **⚠️ DEPRECATED!**
>
> **useFontLineHeight** has been deprecated. You can use **skeletonTextLineHeight** instead:
> ```swift
> descriptionTextView.skeletonTextLineHeight = .relativeToFont
> ```
> **📣 IMPORTANT!**
>
> Please note that for views without multiple lines, the single line will be considered
> as the last line.
### 🦋 Appearance
The skeletons have a default appearance. So, when you don't specify the color, gradient or multilines properties, `SkeletonView` uses the default values.
Default values:
- **tintColor**: UIColor
- **tintColor**: `UIColor`
- *default: `.skeletonDefault` (same as `.clouds` but adaptive to dark mode)*
- **gradient**: SkeletonGradient
- *default: `SkeletonGradient(baseColor: .skeletonDefault)`*
- **multilineHeight**: CGFloat
- **multilineHeight**: `CGFloat`
- *default: 15*
- **useFontLineHeight**: Bool
- *default: true*
- **multilineSpacing**: CGFloat
- **multilineSpacing**: `CGFloat`
- *default: 10*
- **multilineLastLineFillPercent**: Int
- **multilineLastLineFillPercent**: `Int`
- *default: 70*
- **multilineCornerRadius**: Int
- **multilineCornerRadius**: `Int`
- *default: 0*
- **skeletonCornerRadius**: CGFloat (IBInspectable) (Make your skeleton view with corner)
- **skeletonCornerRadius**: `CGFloat` (IBInspectable) (Make your skeleton view with corner)
- *default: 0*
To get these default values you can use `SkeletonAppearance.default`. Using this property you can set the values as well:
@@ -312,12 +343,12 @@ SkeletonAppearance.default.multilineHeight = 20
SkeletonAppearance.default.tintColor = .green
```
You can also specifiy these line appearance properties on a per-label basis:
- **lastLineFillPercent**: Int
- **linesCornerRadius**: Int
- **skeletonLineSpacing**: CGFloat
- **skeletonPaddingInsets**: UIEdgeInsets
- **useFontLineHeight**: Bool
> **⚠️ DEPRECATED!**
>
> **useFontLineHeight** has been deprecated. You can use **textLineHeight** instead:
> ```swift
> SkeletonAppearance.default.textLineHeight = .relativeToFont
> ```
### 🎨 Custom colors
@@ -464,16 +495,6 @@ view.showSkeleton()
**Hierarchy in collections**
Here is an illustration that shows how you should specify which elements are skeletonables when you are using an `UITableView`:
<img src="Assets/tableview_scheme.png" width="700px">
As you can see, we have to make skeletonable the tableview, the cell and the UI elements, but we don't need to set as skeletonable the `contentView`
**Skeleton views layout**
Sometimes skeleton layout may not fit your layout because the parent view bounds have changed. ~For example, rotating the device.~
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SkeletonView"
s.version = "1.25.1"
s.version = "1.29.4"
s.summary = "An elegant way to show users that something is happening and also prepare them to which contents he is waiting"
s.description = <<-DESC
Today almost all apps have async processes, as API requests, long runing processes, etc. And while the processes are working, usually developers place a loading view to show users that something is going on.
+12
View File
@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
F5225F2A278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5225F29278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift */; };
F5225F2B278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5225F29278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift */; };
F53D731826D399E100249D46 /* SkeletonTreeNode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F53D731726D399E100249D46 /* SkeletonTreeNode+Extensions.swift */; };
F53D731926D399E100249D46 /* SkeletonTreeNode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F53D731726D399E100249D46 /* SkeletonTreeNode+Extensions.swift */; };
F53D731B26D3A35100249D46 /* SkeletonExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = F53D731A26D3A35100249D46 /* SkeletonExtended.swift */; };
@@ -99,6 +101,8 @@
F556F6E126CE367600A80B83 /* UIView+SkeletonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6DF26CE367600A80B83 /* UIView+SkeletonView.swift */; };
F556F6F626CE876300A80B83 /* UIView+Swizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6DC26CE33CE00A80B83 /* UIView+Swizzling.swift */; };
F556F70826D38F3100A80B83 /* SkeletonTreeNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F70726D38F3100A80B83 /* SkeletonTreeNode.swift */; };
F5C84884274BB6F000004D1A /* SkeletonTextLineHeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C84883274BB6F000004D1A /* SkeletonTextLineHeight.swift */; };
F5C84885274BB6F000004D1A /* SkeletonTextLineHeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C84883274BB6F000004D1A /* SkeletonTextLineHeight.swift */; };
OBJ_101 /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_31 /* Int+Extensions.swift */; };
OBJ_103 /* UIColor+Skeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_33 /* UIColor+Skeleton.swift */; };
OBJ_104 /* UITableView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_34 /* UITableView+Extensions.swift */; };
@@ -149,6 +153,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
F5225F29278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonTextNumberOfLines.swift; sourceTree = "<group>"; };
F53D731726D399E100249D46 /* SkeletonTreeNode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SkeletonTreeNode+Extensions.swift"; sourceTree = "<group>"; };
F53D731A26D3A35100249D46 /* SkeletonExtended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonExtended.swift; sourceTree = "<group>"; };
F53D732226D3C3A800249D46 /* UILabel+SKExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+SKExtensions.swift"; sourceTree = "<group>"; };
@@ -208,6 +213,7 @@
F556F6DC26CE33CE00A80B83 /* UIView+Swizzling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Swizzling.swift"; sourceTree = "<group>"; };
F556F6DF26CE367600A80B83 /* UIView+SkeletonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+SkeletonView.swift"; sourceTree = "<group>"; };
F556F70726D38F3100A80B83 /* SkeletonTreeNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonTreeNode.swift; sourceTree = "<group>"; };
F5C84883274BB6F000004D1A /* SkeletonTextLineHeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonTextLineHeight.swift; sourceTree = "<group>"; };
OBJ_11 /* SkeletonLayerBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonLayerBuilder.swift; sourceTree = "<group>"; };
OBJ_12 /* SkeletonMultilineLayerBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonMultilineLayerBuilder.swift; sourceTree = "<group>"; };
OBJ_14 /* CollectionSkeleton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionSkeleton.swift; sourceTree = "<group>"; };
@@ -515,6 +521,8 @@
OBJ_55 /* SkeletonGradient.swift */,
F556F6B826CE262700A80B83 /* GradientDirection.swift */,
F556F6C126CE27FD00A80B83 /* SkeletonType.swift */,
F5C84883274BB6F000004D1A /* SkeletonTextLineHeight.swift */,
F5225F29278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift */,
);
path = Models;
sourceTree = "<group>";
@@ -822,6 +830,7 @@
F556F6B626CE258300A80B83 /* GradientDirection+Animations.swift in Sources */,
F556F69F26CD553B00A80B83 /* UIView+Extensions.swift in Sources */,
F556F58526CD1F3900A80B83 /* Recoverable.swift in Sources */,
F5C84885274BB6F000004D1A /* SkeletonTextLineHeight.swift in Sources */,
F556F58626CD1F3900A80B83 /* RecoverableViewState.swift in Sources */,
F556F58726CD1F3900A80B83 /* SkeletonAnimationBuilder.swift in Sources */,
F556F58826CD1F3900A80B83 /* SkeletonConfig.swift in Sources */,
@@ -829,6 +838,7 @@
F556F58A26CD1F3900A80B83 /* SkeletonGradient.swift in Sources */,
F556F6C326CE27FD00A80B83 /* SkeletonType.swift in Sources */,
F556F58B26CD1F3900A80B83 /* SkeletonLayer.swift in Sources */,
F5225F2B278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift in Sources */,
F556F6A226CD566C00A80B83 /* UIView+SKExtensions.swift in Sources */,
F556F69326CD506C00A80B83 /* Deprecated.swift in Sources */,
F556F6BA26CE262700A80B83 /* GradientDirection.swift in Sources */,
@@ -904,6 +914,7 @@
F556F69E26CD553B00A80B83 /* UIView+Extensions.swift in Sources */,
OBJ_117 /* Recoverable.swift in Sources */,
OBJ_118 /* RecoverableViewState.swift in Sources */,
F5C84884274BB6F000004D1A /* SkeletonTextLineHeight.swift in Sources */,
OBJ_119 /* SkeletonAnimationBuilder.swift in Sources */,
OBJ_120 /* SkeletonConfig.swift in Sources */,
OBJ_121 /* SkeletonFlowHandler.swift in Sources */,
@@ -911,6 +922,7 @@
F556F6C226CE27FD00A80B83 /* SkeletonType.swift in Sources */,
OBJ_123 /* SkeletonLayer.swift in Sources */,
F556F6E026CE367600A80B83 /* UIView+SkeletonView.swift in Sources */,
F5225F2A278C2BCE0061A9B0 /* SkeletonTextNumberOfLines.swift in Sources */,
F556F6A126CD566C00A80B83 /* UIView+SKExtensions.swift in Sources */,
F556F69226CD506C00A80B83 /* Deprecated.swift in Sources */,
F556F6B926CE262700A80B83 /* GradientDirection.swift in Sources */,
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,8 +26,8 @@ public class SkeletonViewAppearance {
public var gradient = SkeletonGradient(baseColor: .skeletonDefault)
public var multilineHeight: CGFloat = 15
public var useFontLineHeight: Bool = true
public lazy var textLineHeight: SkeletonTextLineHeight = .fixed(SkeletonAppearance.default.multilineHeight)
public var multilineSpacing: CGFloat = 10
@@ -37,5 +37,7 @@ public class SkeletonViewAppearance {
public var renderSingleLineAsView: Bool = false
public var skeletonCornerRadius: Float = 0
}
// codebeat:enable[TOO_MANY_IVARS]
@@ -15,6 +15,7 @@ public protocol SkeletonCollectionViewDataSource: UICollectionViewDataSource {
func collectionSkeletonView(_ skeletonView: UICollectionView, supplementaryViewIdentifierOfKind: String, at indexPath: IndexPath) -> ReusableCellIdentifier?
func collectionSkeletonView(_ skeletonView: UICollectionView, skeletonCellForItemAt indexPath: IndexPath) -> UICollectionViewCell?
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareCellForSkeleton cell: UICollectionViewCell, at indexPath: IndexPath)
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareViewForSkeleton view: UICollectionReusableView, at indexPath: IndexPath)
}
public extension SkeletonCollectionViewDataSource {
@@ -35,6 +36,8 @@ public extension SkeletonCollectionViewDataSource {
}
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareCellForSkeleton cell: UICollectionViewCell, at indexPath: IndexPath) { }
func collectionSkeletonView(_ skeletonView: UICollectionView, prepareViewForSkeleton view: UICollectionReusableView, at indexPath: IndexPath) { }
}
public protocol SkeletonCollectionViewDelegate: UICollectionViewDelegate { }
@@ -48,3 +48,47 @@ public extension UIView {
}
}
public extension UILabel {
@IBInspectable
@available(*, deprecated, renamed: "skeletonTextLineHeight")
var useFontLineHeight: Bool {
get {
textLineHeight == .relativeToFont
}
set {
textLineHeight = newValue ? .relativeToFont : .fixed(SkeletonAppearance.default.multilineHeight)
}
}
}
public extension UITextView {
@IBInspectable
@available(*, deprecated, renamed: "skeletonTextLineHeight")
var useFontLineHeight: Bool {
get {
textLineHeight == .relativeToFont
}
set {
textLineHeight = newValue ? .relativeToFont : .fixed(SkeletonAppearance.default.multilineHeight)
}
}
}
public extension SkeletonViewAppearance {
@available(*, deprecated, renamed: "textLineHeight")
var useFontLineHeight: Bool {
get {
textLineHeight == .relativeToFont
}
set {
textLineHeight = newValue ? .relativeToFont : .fixed(SkeletonAppearance.default.multilineHeight)
}
}
}
@@ -29,4 +29,8 @@ public struct SkeletonGradient {
}
}
public init(colors: [UIColor]) {
self.gradientColors = colors
}
}
@@ -0,0 +1,30 @@
//
// Copyright SkeletonView. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// SkeletonTextLineHeight.swift
//
// Created by Juanpe Catalán on 22/11/21.
import UIKit
public enum SkeletonTextLineHeight: Equatable {
/// Calculates the line height based on the font line height.
case relativeToFont
/// Calculates the line height based on the height constraints.
///
/// If no constraints exist, the height will be set to the `multilineHeight`
/// value defined in the `SkeletonAppearance`.
case relativeToConstraints
/// Returns the specific height specified as the associated value.
case fixed(CGFloat)
}
@@ -0,0 +1,32 @@
//
// Copyright SkeletonView. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// SkeletonTextNumberOfLines.swift
//
// Created by Juanpe Catalán on 10/1/22.
import UIKit
public enum SkeletonTextNumberOfLines: Equatable, ExpressibleByIntegerLiteral {
/// Returns `numberOfLines` value.
case inherited
/// Returns the specific number of lines specified as the associated value.
case custom(Int)
}
public extension SkeletonTextNumberOfLines {
init(integerLiteral value: Int) {
self = .custom(value)
}
}
@@ -33,10 +33,4 @@ public extension UILabel {
set { multilineSpacing = newValue }
}
@IBInspectable
var useFontLineHeight: Bool {
get { usesTextHeightForLines }
set { usesTextHeightForLines = newValue }
}
}
@@ -15,9 +15,36 @@ import UIKit
public extension UILabel {
/// Defines the skeleton paddings.
var skeletonPaddingInsets: UIEdgeInsets {
get { return paddingInsets }
set { paddingInsets = newValue }
get {
paddingInsets
}
set {
paddingInsets = newValue
}
}
/// Defines the logic for calculating the height of the skeleton lines.
/// Default: `SkeletonAppearance.default.textLineHeight`
var skeletonTextLineHeight: SkeletonTextLineHeight {
get {
textLineHeight
}
set {
textLineHeight = newValue
}
}
/// Defines the logic for calculating the number of lines of the skeleton.
/// Default: `inherited`
var skeletonTextNumberOfLines: SkeletonTextNumberOfLines {
get {
skeletonNumberOfLines
}
set {
skeletonNumberOfLines = newValue
}
}
}
@@ -32,11 +32,5 @@ public extension UITextView {
get { return multilineSpacing }
set { multilineSpacing = newValue }
}
@IBInspectable
var useFontLineHeight: Bool {
get { usesTextHeightForLines }
set { usesTextHeightForLines = newValue }
}
}
@@ -15,9 +15,36 @@ import UIKit
public extension UITextView {
/// Defines the skeleton paddings.
var skeletonPaddingInsets: UIEdgeInsets {
get { return paddingInsets }
set { paddingInsets = newValue }
get {
paddingInsets
}
set {
paddingInsets = newValue
}
}
/// Defines the logic for calculating the height of the skeleton lines.
/// Default: `SkeletonAppearance.default.textLineHeight`
var skeletonTextLineHeight: SkeletonTextLineHeight {
get {
textLineHeight
}
set {
textLineHeight = newValue
}
}
/// Defines the logic for calculating the number of lines of the skeleton.
/// Default: `inherited`
var skeletonTextNumberOfLines: SkeletonTextNumberOfLines {
get {
skeletonNumberOfLines
}
set {
skeletonNumberOfLines = newValue
}
}
}
@@ -51,13 +51,13 @@ extension SkeletonCollectionDataSource: UITableViewDataSource {
let fakeCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
originalTableViewDataSource?.collectionSkeletonView(tableView, prepareCellForSkeleton: fakeCell, at: indexPath)
skeletonViewIfContainerSkeletonIsActive(container: tableView, view: fakeCell)
skeletonizeViewIfContainerSkeletonIsActive(container: tableView, view: fakeCell)
return fakeCell
}
originalTableViewDataSource?.collectionSkeletonView(tableView, prepareCellForSkeleton: cell, at: indexPath)
skeletonViewIfContainerSkeletonIsActive(container: tableView, view: cell)
skeletonizeViewIfContainerSkeletonIsActive(container: tableView, view: cell)
return cell
}
}
@@ -88,13 +88,13 @@ extension SkeletonCollectionDataSource: UICollectionViewDataSource {
let fakeCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath)
originalCollectionViewDataSource?.collectionSkeletonView(collectionView, prepareCellForSkeleton: fakeCell, at: indexPath)
skeletonViewIfContainerSkeletonIsActive(container: collectionView, view: fakeCell)
skeletonizeViewIfContainerSkeletonIsActive(container: collectionView, view: fakeCell)
return fakeCell
}
originalCollectionViewDataSource?.collectionSkeletonView(collectionView, prepareCellForSkeleton: cell, at: indexPath)
skeletonViewIfContainerSkeletonIsActive(container: collectionView, view: cell)
skeletonizeViewIfContainerSkeletonIsActive(container: collectionView, view: cell)
return cell
}
@@ -103,7 +103,9 @@ extension SkeletonCollectionDataSource: UICollectionViewDataSource {
at indexPath: IndexPath) -> UICollectionReusableView {
if let viewIdentifier = originalCollectionViewDataSource?.collectionSkeletonView(collectionView, supplementaryViewIdentifierOfKind: kind, at: indexPath) {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: viewIdentifier, for: indexPath)
skeletonViewIfContainerSkeletonIsActive(container: collectionView, view: view)
originalCollectionViewDataSource?.collectionSkeletonView(collectionView, prepareViewForSkeleton: view, at: indexPath)
skeletonizeViewIfContainerSkeletonIsActive(container: collectionView, view: view)
return view
}
@@ -113,12 +115,15 @@ extension SkeletonCollectionDataSource: UICollectionViewDataSource {
}
extension SkeletonCollectionDataSource {
private func skeletonViewIfContainerSkeletonIsActive(container: UIView, view: UIView) {
private func skeletonizeViewIfContainerSkeletonIsActive(container: UIView, view: UIView) {
guard container.sk.isSkeletonActive,
let skeletonConfig = container._currentSkeletonConfig else {
return
}
view.showSkeleton(skeletonConfig: skeletonConfig)
view.showSkeleton(
skeletonConfig: skeletonConfig,
notifyDelegate: false
)
}
}
@@ -9,17 +9,23 @@
import UIKit
class SkeletonCollectionDelegate: NSObject {
weak var originalTableViewDelegate: SkeletonTableViewDelegate?
weak var originalCollectionViewDelegate: SkeletonCollectionViewDelegate?
init(tableViewDelegate: SkeletonTableViewDelegate? = nil, collectionViewDelegate: SkeletonCollectionViewDelegate? = nil) {
init(
tableViewDelegate: SkeletonTableViewDelegate? = nil,
collectionViewDelegate: SkeletonCollectionViewDelegate? = nil
) {
self.originalTableViewDelegate = tableViewDelegate
self.originalCollectionViewDelegate = collectionViewDelegate
}
}
// MARK: - UITableViewDelegate
extension SkeletonCollectionDelegate: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
headerOrFooterView(tableView, for: originalTableViewDelegate?.collectionSkeletonView(tableView, identifierForHeaderInSection: section))
}
@@ -42,24 +48,40 @@ extension SkeletonCollectionDelegate: UITableViewDelegate {
cell.hideSkeleton()
originalTableViewDelegate?.tableView?(tableView, didEndDisplaying: cell, forRowAt: indexPath)
}
private func headerOrFooterView(_ tableView: UITableView, for viewIdentifier: String? ) -> UIView? {
guard let viewIdentifier = viewIdentifier, let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: viewIdentifier) else { return nil }
skeletonViewIfContainerSkeletonIsActive(container: tableView, view: header)
return header
}
}
// MARK: - UICollectionViewDelegate
extension SkeletonCollectionDelegate: UICollectionViewDelegate { }
extension SkeletonCollectionDelegate {
private func skeletonViewIfContainerSkeletonIsActive(container: UIView, view: UIView) {
private extension SkeletonCollectionDelegate {
func skeletonizeViewIfContainerSkeletonIsActive(container: UIView, view: UIView) {
guard container.sk.isSkeletonActive,
let skeletonConfig = container._currentSkeletonConfig else {
let skeletonConfig = container._currentSkeletonConfig
else {
return
}
view.showSkeleton(skeletonConfig: skeletonConfig)
view.showSkeleton(
skeletonConfig: skeletonConfig,
notifyDelegate: false
)
}
func headerOrFooterView(_ tableView: UITableView, for viewIdentifier: String? ) -> UIView? {
guard let viewIdentifier = viewIdentifier,
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: viewIdentifier)
else {
return nil
}
skeletonizeViewIfContainerSkeletonIsActive(
container: tableView,
view: header
)
return header
}
}
@@ -59,8 +59,8 @@ struct SkeletonLayer {
/// If there is more than one line, or custom preferences have been set for a single line, draw custom layers
func addTextLinesIfNeeded() {
guard let textView = holderAsTextView else { return }
let config = SkeletonMultilinesLayerConfig(lines: textView.numberOfLines,
lineHeight: textView.lineHeight,
let config = SkeletonMultilinesLayerConfig(lines: textView.estimatedNumberOfLines,
lineHeight: textView.estimatedLineHeight,
type: type,
lastLineFillPercent: textView.lastLineFillingPercent,
multilineCornerRadius: textView.multilineCornerRadius,
@@ -75,8 +75,8 @@ struct SkeletonLayer {
func updateLinesIfNeeded() {
guard let textView = holderAsTextView else { return }
let config = SkeletonMultilinesLayerConfig(lines: textView.numberOfLines,
lineHeight: textView.lineHeight,
let config = SkeletonMultilinesLayerConfig(lines: textView.estimatedNumberOfLines,
lineHeight: textView.estimatedLineHeight,
type: type,
lastLineFillPercent: textView.lastLineFillingPercent,
multilineCornerRadius: textView.multilineCornerRadius,
@@ -91,7 +91,7 @@ struct SkeletonLayer {
var holderAsTextView: SkeletonTextNode? {
guard let textView = holder as? SkeletonTextNode,
(textView.numberOfLines == -1 || textView.numberOfLines == 0 || textView.numberOfLines > 1 || textView.numberOfLines == 1 && !SkeletonAppearance.default.renderSingleLineAsView) else {
(textView.estimatedNumberOfLines == -1 || textView.estimatedNumberOfLines == 0 || textView.estimatedNumberOfLines > 1 || textView.estimatedNumberOfLines == 1 && !SkeletonAppearance.default.renderSingleLineAsView) else {
return nil
}
return textView
@@ -15,15 +15,16 @@ import UIKit
protocol SkeletonTextNode {
var lineHeight: CGFloat { get }
var numberOfLines: Int { get }
var textLineHeight: SkeletonTextLineHeight { get }
var estimatedLineHeight: CGFloat { get }
var estimatedNumberOfLines: Int { get }
var textAlignment: NSTextAlignment { get }
var lastLineFillingPercent: Int { get }
var multilineCornerRadius: Int { get }
var multilineSpacing: CGFloat { get }
var paddingInsets: UIEdgeInsets { get }
var usesTextHeightForLines: Bool { get }
var shouldCenterTextVertically: Bool { get }
}
enum SkeletonTextNodeAssociatedKeys {
@@ -33,26 +34,46 @@ enum SkeletonTextNodeAssociatedKeys {
static var multilineSpacing = "multilineSpacing"
static var paddingInsets = "paddingInsets"
static var backupHeightConstraints = "backupHeightConstraints"
static var usesTextHeightForLines = "usesTextHeightForLines"
static var textLineHeight = "textLineHeight"
static var skeletonNumberOfLines = "skeletonNumberOfLines"
}
extension UILabel: SkeletonTextNode {
var lineHeight: CGFloat {
let constraintsLineHeight = backupHeightConstraints.first?.constant ?? SkeletonAppearance.default.multilineHeight
if useFontLineHeight,
let fontLineHeight = font?.lineHeight {
return fontLineHeight > constraintsLineHeight ? constraintsLineHeight : fontLineHeight
} else {
return constraintsLineHeight
var estimatedLineHeight: CGFloat {
switch textLineHeight {
case .fixed(let height):
return height
case .relativeToFont:
return fontLineHeight ?? SkeletonAppearance.default.multilineHeight
case .relativeToConstraints:
guard let constraintsLineHeight = heightConstraints.first?.constant,
estimatedNumberOfLines != 0 else {
return SkeletonAppearance.default.multilineHeight
}
return constraintsLineHeight / CGFloat(estimatedNumberOfLines)
}
}
var usesTextHeightForLines: Bool {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.usesTextHeightForLines) as? Bool ?? SkeletonAppearance.default.useFontLineHeight }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.usesTextHeightForLines) }
var textLineHeight: SkeletonTextLineHeight {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.textLineHeight) as? SkeletonTextLineHeight ?? SkeletonAppearance.default.textLineHeight }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.textLineHeight) }
}
var skeletonNumberOfLines: SkeletonTextNumberOfLines {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.skeletonNumberOfLines) as? SkeletonTextNumberOfLines ?? SkeletonTextNumberOfLines.inherited }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.skeletonNumberOfLines) }
}
var estimatedNumberOfLines: Int {
switch skeletonNumberOfLines {
case .inherited:
return numberOfLines
case .custom(let lines):
return lines >= 0 ? lines : 1
}
}
var lastLineFillingPercent: Int {
@@ -83,29 +104,50 @@ extension UILabel: SkeletonTextNode {
var shouldCenterTextVertically: Bool {
true
}
var fontLineHeight: CGFloat? {
if let attributedText = attributedText,
attributedText.length > 0 {
let attributes = attributedText.attributes(at: 0, effectiveRange: nil)
let fontAttribute = attributes.first(where: { $0.key == .font })
return fontAttribute?.value as? CGFloat ?? font.lineHeight
} else {
return font.lineHeight
}
}
}
extension UITextView: SkeletonTextNode {
var lineHeight: CGFloat {
let constraintsLineHeight = heightConstraints.first?.constant ?? SkeletonAppearance.default.multilineHeight
if useFontLineHeight,
let fontLineHeight = font?.lineHeight {
return fontLineHeight > constraintsLineHeight ? constraintsLineHeight : fontLineHeight
} else {
return constraintsLineHeight
var estimatedLineHeight: CGFloat {
switch textLineHeight {
case .fixed(let height):
return height
case .relativeToFont:
return fontLineHeight ?? SkeletonAppearance.default.multilineHeight
case .relativeToConstraints:
return SkeletonAppearance.default.multilineHeight
}
}
var usesTextHeightForLines: Bool {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.usesTextHeightForLines) as? Bool ?? SkeletonAppearance.default.useFontLineHeight }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.usesTextHeightForLines) }
var textLineHeight: SkeletonTextLineHeight {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.textLineHeight) as? SkeletonTextLineHeight ?? SkeletonAppearance.default.textLineHeight }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.textLineHeight) }
}
var numberOfLines: Int {
-1
var skeletonNumberOfLines: SkeletonTextNumberOfLines {
get { return ao_get(pkey: &SkeletonTextNodeAssociatedKeys.skeletonNumberOfLines) as? SkeletonTextNumberOfLines ?? SkeletonTextNumberOfLines.inherited }
set { ao_set(newValue, pkey: &SkeletonTextNodeAssociatedKeys.skeletonNumberOfLines) }
}
var estimatedNumberOfLines: Int {
switch skeletonNumberOfLines {
case .inherited:
return -1
case .custom(let lines):
return lines >= -1 ? lines : 1
}
}
var lastLineFillingPercent: Int {
@@ -137,4 +179,16 @@ extension UITextView: SkeletonTextNode {
var shouldCenterTextVertically: Bool {
false
}
var fontLineHeight: CGFloat? {
if let attributedText = attributedText,
attributedText.length > 0 {
let attributes = attributedText.attributes(at: 0, effectiveRange: nil)
let fontAttribute = attributes.first(where: { $0.key == .font })
return fontAttribute?.value as? CGFloat ?? font?.lineHeight
} else {
return font?.lineHeight
}
}
}
@@ -21,15 +21,15 @@ class SkeletonFlowHandler: SkeletonFlowDelegate {
func didShowSkeletons(rootView: UIView) {
skeletonLog(rootView.sk.skeletonTreeDescription)
NotificationCenter.default.post(name: .skeletonWillAppearNotification, object: rootView, userInfo: nil)
NotificationCenter.default.post(name: .skeletonDidAppearNotification, object: rootView, userInfo: nil)
}
func willBeginUpdatingSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .skeletonWillAppearNotification, object: rootView, userInfo: nil)
NotificationCenter.default.post(name: .skeletonWillUpdateNotification, object: rootView, userInfo: nil)
}
func didUpdateSkeletons(rootView: UIView) {
NotificationCenter.default.post(name: .skeletonWillAppearNotification, object: rootView, userInfo: nil)
NotificationCenter.default.post(name: .skeletonDidUpdateNotification, object: rootView, userInfo: nil)
}
func willBeginLayingSkeletonsIfNeeded(rootView: UIView) {
@@ -78,7 +78,7 @@ extension CALayer {
insertSublayer(sublayer.contentLayer, at: index)
switch transition {
case .none:
completion?()
DispatchQueue.main.async { completion?() }
case .crossDissolve(let duration):
sublayer.contentLayer.setOpacity(from: 0, to: 1, duration: duration, completion: completion)
}
@@ -88,15 +88,16 @@ extension CALayer {
private extension CALayer {
func alignLayerFrame(_ rect: CGRect, alignment: NSTextAlignment, isRTL: Bool) -> CGRect {
func alignLayerFrame(_ rect: CGRect, paddingInsets: UIEdgeInsets, alignment: NSTextAlignment, isRTL: Bool) -> CGRect {
var newRect = rect
let superlayerWidth = (superlayer?.bounds.width ?? 0)
switch alignment {
case .natural where isRTL,
.right:
newRect.origin.x = (superlayer?.bounds.width ?? 0) - rect.origin.x - rect.width
newRect.origin.x = superlayerWidth - rect.width - paddingInsets.right
case .center:
newRect.origin.x = rect.origin.x + ((superlayer?.bounds.width ?? 0) - rect.width) / 2
newRect.origin.x = (superlayerWidth + paddingInsets.left - paddingInsets.right - rect.width) / 2
case .natural, .left, .justified:
break
@unknown default:
@@ -211,7 +212,7 @@ extension CALayer {
height: size.height)
if index == totalLines - 1 {
frame = alignLayerFrame(newFrame, alignment: alignment, isRTL: isRTL)
frame = alignLayerFrame(newFrame, paddingInsets: paddingInsets, alignment: alignment, isRTL: isRTL)
} else {
frame = newFrame
}
@@ -16,15 +16,15 @@ import UIKit
extension UILabel {
var desiredHeightBasedOnNumberOfLines: CGFloat {
let spaceNeededForEachLine = lineHeight * CGFloat(numberOfLines)
let spaceNeededForSpaces = skeletonLineSpacing * CGFloat(numberOfLines - 1)
let spaceNeededForEachLine = estimatedLineHeight * CGFloat(estimatedNumberOfLines)
let spaceNeededForSpaces = skeletonLineSpacing * CGFloat(estimatedNumberOfLines - 1)
let padding = paddingInsets.top + paddingInsets.bottom
return spaceNeededForEachLine + spaceNeededForSpaces + padding
}
func updateHeightConstraintsIfNeeded() {
guard numberOfLines > 1 || numberOfLines == 0 else { return }
guard estimatedNumberOfLines > 1 || estimatedNumberOfLines == 0 else { return }
// Workaround to simulate content when the label is contained in a `UIStackView`.
if isSuperviewAStackView, bounds.height == 0 {
@@ -88,7 +88,7 @@ extension UIView {
}
var _skeletonableCornerRadius: Float {
get { return ao_get(pkey: &ViewAssociatedKeys.skeletonCornerRadius) as? Float ?? 0.0 }
get { return ao_get(pkey: &ViewAssociatedKeys.skeletonCornerRadius) as? Float ?? SkeletonViewAppearance.shared.skeletonCornerRadius }
set { ao_set(newValue, pkey: &ViewAssociatedKeys.skeletonCornerRadius) }
}
}
@@ -15,16 +15,30 @@ import UIKit
extension UIView {
func showSkeleton(skeletonConfig config: SkeletonConfig) {
func showSkeleton(
skeletonConfig config: SkeletonConfig,
notifyDelegate: Bool = true
) {
_isSkeletonAnimated = config.animated
_flowDelegate = SkeletonFlowHandler()
_flowDelegate?.willBeginShowingSkeletons(rootView: self)
if notifyDelegate {
_flowDelegate = SkeletonFlowHandler()
_flowDelegate?.willBeginShowingSkeletons(rootView: self)
}
recursiveShowSkeleton(skeletonConfig: config, root: self)
}
func updateSkeleton(skeletonConfig config: SkeletonConfig) {
func updateSkeleton(
skeletonConfig config: SkeletonConfig,
notifyDelegate: Bool = true
) {
_isSkeletonAnimated = config.animated
_flowDelegate?.willBeginUpdatingSkeletons(rootView: self)
if notifyDelegate {
_flowDelegate?.willBeginUpdatingSkeletons(rootView: self)
}
recursiveUpdateSkeleton(skeletonConfig: config, root: self)
}
@@ -19,67 +19,17 @@ class SkeletonDebugTests: XCTestCase {
func testSkeletonDescriptionWithViewNotSkeletonableNotReturnsSkullEmojiAndChildren() {
/// given
let view = UIView()
let expectedDescription = "<UIView: \(Unmanaged.passUnretained(view).toOpaque())>"
let expectedDictionary: [String : Any] = [
"isSkeletonable" : false,
"type" : "UIView",
"reference" : "\(Unmanaged.passUnretained(view).toOpaque())"
]
/// when
let obtainedDescription = view.skeletonDescription
let obtainedDictionary = view.sk.treeNode.dictionaryRepresentation
/// then
XCTAssertEqual(expectedDescription, obtainedDescription)
}
func testSkeletonDescriptionWithViewSkeletonableReturnsSkullEmojiButNotChildren() {
/// given
let view = UIView()
view.isSkeletonable = true
let expectedDescription = "<UIView: \(Unmanaged.passUnretained(view).toOpaque()) | ☠️ >"
/// when
let obtainedDescription = view.skeletonDescription
/// then
XCTAssertEqual(expectedDescription, obtainedDescription)
}
func testSkeletonDescriptionWithViewSkeletonableAndChildrenReturnsSkullEmojiAndChildren() {
/// given
let view = UIView()
let childView = UIView()
view.addSubview(childView)
view.isSkeletonable = true
childView.isSkeletonable = true
let expectedDescription = """
<UIView: \(Unmanaged.passUnretained(view).toOpaque()) | (1) subSkeletons | >
"""
/// when
let obtainedDescription = view.skeletonDescription
/// then
XCTAssertEqual(expectedDescription, obtainedDescription)
}
func testSkeletonHierarchyWithSkeletonableViewsReturnsFullHierarchy() {
/// given
let view = UIView()
let childView = UIView()
let subchildView = UIView()
view.addSubview(childView)
childView.addSubview(subchildView)
view.isSkeletonable = true
childView.isSkeletonable = true
subchildView.isSkeletonable = true
let expectedDescription = "⬇⬇ ☠️ Root view hierarchy with Skeletons ⬇⬇<UIView:\(Unmanaged.passUnretained(view).toOpaque()) | (1) subSkeletons | ☠️ ><UIView: \(Unmanaged.passUnretained(childView).toOpaque()) | (1) subSkeletons | ☠️ ><UIView: \(Unmanaged.passUnretained(subchildView).toOpaque()) | ☠️ >"
.replacingOccurrences(of: " ", with: "")
/// when
let obtainedDescription = view.skeletonHierarchy()
.replacingOccurrences(of: "\n", with: "")
.replacingOccurrences(of: " ", with: "")
/// then
XCTAssertEqual(expectedDescription, obtainedDescription)
XCTAssertEqual(expectedDictionary.keys, obtainedDictionary.keys)
}
}
+18 -13
View File
@@ -1,33 +1,38 @@
fastlane documentation
================
----
# Installation
Make sure you have the latest version of the Xcode command line tools installed:
```
```sh
xcode-select --install
```
Install _fastlane_ using
```
[sudo] gem install fastlane -NV
```
or alternatively using `brew install fastlane`
For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane)
# Available Actions
### bump_version
```
fastlane bump_version
```sh
[bundle exec] fastlane bump_version
```
### release_current
```sh
[bundle exec] fastlane release_current
```
fastlane release_current
```
----
This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
More information about fastlane can be found on [fastlane.tools](https://fastlane.tools).
The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools).
More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools).
The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools).