Skip to content

Commit 4d26bb6

Browse files
authored
Migrating to UILabel instead of using UIViews due to a bug while animating text (#27)
Updates screenshots Updates documentation
1 parent a255713 commit 4d26bb6

File tree

10 files changed

+173
-108
lines changed

10 files changed

+173
-108
lines changed

DemoApp/DemoApp/CollectionViewController.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import UIKit
88

99
final class CollectionViewController: UIViewController {
1010

11+
// MARK: Internal
12+
1113
var dataSource: UICollectionViewDiffableDataSource<Int, String>?
1214
var snapshot: NSDiffableDataSourceSnapshot<Int, String>?
1315

@@ -42,19 +44,7 @@ final class CollectionViewController: UIViewController {
4244
}
4345
}
4446

45-
private func makeSnapshot(animatingDifferences: Bool = true) {
46-
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
47-
self.snapshot = snapshot
48-
snapshot.appendSections([1])
49-
snapshot.appendItems(
50-
(1...10000).map { "item: \($0) + UUID: \(UUID())" },
51-
toSection: 1)
52-
DispatchQueue.main.async { [weak self] in
53-
self?.dataSource?.apply(
54-
snapshot,
55-
animatingDifferences: animatingDifferences)
56-
}
57-
}
47+
// MARK: Private
5848

5949
private lazy var collectionView: UICollectionView = {
6050
let flowLayout = UICollectionViewFlowLayout()
@@ -70,10 +60,27 @@ final class CollectionViewController: UIViewController {
7060
collectionView.backgroundColor = .white
7161
return collectionView
7262
}()
63+
64+
private func makeSnapshot(animatingDifferences: Bool = true) {
65+
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
66+
self.snapshot = snapshot
67+
snapshot.appendSections([1])
68+
snapshot.appendItems(
69+
(1...10000).map { "item: \($0) + UUID: \(UUID())" },
70+
toSection: 1)
71+
DispatchQueue.main.async { [weak self] in
72+
self?.dataSource?.apply(
73+
snapshot,
74+
animatingDifferences: animatingDifferences)
75+
}
76+
}
77+
7378
}
7479

7580
private final class CollectionCell: UICollectionViewCell {
7681

82+
// MARK: Lifecycle
83+
7784
override init(frame: CGRect) {
7885
super.init(frame: frame)
7986
addSubview(label)
@@ -92,12 +99,16 @@ private final class CollectionCell: UICollectionViewCell {
9299
fatalError("init(coder:) has not been implemented")
93100
}
94101

102+
// MARK: Internal
103+
95104
var text: NSAttributedString? {
96105
didSet {
97106
label.attributedText = text
98107
}
99108
}
100109

110+
// MARK: Private
111+
101112
private let label: LCLabel = {
102113
let label = LCLabel(frame: .zero)
103114
label.backgroundColor = .white

DemoApp/DemoApp/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class LCLabelViewController: UIViewController {
7777
frame: CGRect(origin: rect.origin, size: rect.size),
7878
text: text)
7979
label4.numberOfLines = 0
80-
label4.textAlignment = .center
80+
label4.centeringTextAlignment = .center
8181
label4.delegate = self
8282

8383
rect.origin.y += 100
@@ -99,7 +99,7 @@ final class LCLabelViewController: UIViewController {
9999
label.linkAttributes = [
100100
.foregroundColor: UIColor.white,
101101
]
102-
label.textAlignment = .top
102+
label.centeringTextAlignment = .top
103103
label.isUserInteractionEnabled = true
104104
label.numberOfLines = 1
105105
label.attributedText = text

DemoApp/LCLabelUITests/LCLabelHitTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import XCTest
88
// Screenshots taken on an iPhone 13
99
final class LCLabelHitTests: XCTestCase {
1010

11-
private var app: XCUIApplication!
11+
// MARK: Internal
1212

1313
override func setUpWithError() throws {
1414
continueAfterFailure = false
@@ -122,6 +122,11 @@ final class LCLabelHitTests: XCTestCase {
122122
main.staticTexts["translator"].label,
123123
"")
124124
}
125+
126+
// MARK: Private
127+
128+
private var app: XCUIApplication!
129+
125130
}
126131

127132
private extension XCUIApplication {

DemoApp/LCLabelUITests/LCLabelScrollTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import XCTest
88

99
final class LCLabelScrollTests: XCTestCase {
1010

11-
private var app: XCUIApplication!
11+
// MARK: Internal
1212

1313
override func setUpWithError() throws {
1414
continueAfterFailure = false
@@ -51,4 +51,8 @@ final class LCLabelScrollTests: XCTestCase {
5151
}
5252

5353

54+
// MARK: Private
55+
56+
private var app: XCUIApplication!
57+
5458
}

LCLabel.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |s|
22
s.name = 'LCLabel'
33
s.version = '0.5.0'
4-
s.summary = 'LCLabel is a TextKit 2 based UIView'
5-
s.description = "LCLabel is a TextKit 2 based UIView that mimics a the behaviour of UILabel & UITextView"
4+
s.summary = 'LCLabel is a TextKit 2 based UILabel'
5+
s.description = "LCLabel is a TextKit 2 based UILabel that mimics a the behaviour of UITextView"
66
s.homepage = 'https://github.com/mustiikhalil/LCLabel'
77
s.license = { :type => 'MIT', :file => 'LICENSE' }
88
s.author = { 'mustii' => 'mustii@mmk.one' }

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![codecov](https://codecov.io/gh/mustiikhalil/LCLabel/branch/main/graph/badge.svg?token=KAH2KVQ5MQ)](https://codecov.io/gh/mustiikhalil/LCLabel)
44
![Build status](https://github.com/mustiikhalil/lclabel/actions/workflows/build.yml/badge.svg?branch=main)
55

6-
LCLabel is a TextKit 2 based UIView that mimics a the behaviour of UILabel & UITextView
6+
LCLabel is a TextKit 2 based UILabel that mimics a the behaviour of UITextView
77

88
## Installation
99

@@ -26,8 +26,6 @@ dependencies: [
2626

2727
## How to use:
2828

29-
Using LCLabel is as simple as using a UILabel
30-
3129
```swift
3230
let text = NSMutableAttributedString(
3331
string: "welcome to this new adventure!!!",
@@ -128,6 +126,6 @@ where both labels had zero hitches when scrolling a list around 5 times each tim
128126

129127
`LCLabel` is [MIT-licensed](./LICENSE.md).
130128

131-
### Disclamre
129+
### Disclaimer
132130

133-
[UILabel](https://developer.apple.com/documentation/uikit/uilabel/) and [UITextView](https://developer.apple.com/documentation/uikit/uitextview) are Apple's own components.
131+
[UILabel](https://developer.apple.com/documentation/uikit/uilabel/) and [UITextView](https://developer.apple.com/documentation/uikit/uitextview) are Apple's own components.
4 Bytes
Loading

0 commit comments

Comments
 (0)