Skip to content

Commit

Permalink
Migrating to UILabel instead of using UIViews due to a bug while anim…
Browse files Browse the repository at this point in the history
…ating text (#27)

Updates screenshots

Updates documentation
  • Loading branch information
mustiikhalil authored Jun 5, 2022
1 parent a255713 commit 4d26bb6
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 108 deletions.
37 changes: 24 additions & 13 deletions DemoApp/DemoApp/CollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import UIKit

final class CollectionViewController: UIViewController {

// MARK: Internal

var dataSource: UICollectionViewDiffableDataSource<Int, String>?
var snapshot: NSDiffableDataSourceSnapshot<Int, String>?

Expand Down Expand Up @@ -42,19 +44,7 @@ final class CollectionViewController: UIViewController {
}
}

private func makeSnapshot(animatingDifferences: Bool = true) {
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
self.snapshot = snapshot
snapshot.appendSections([1])
snapshot.appendItems(
(1...10000).map { "item: \($0) + UUID: \(UUID())" },
toSection: 1)
DispatchQueue.main.async { [weak self] in
self?.dataSource?.apply(
snapshot,
animatingDifferences: animatingDifferences)
}
}
// MARK: Private

private lazy var collectionView: UICollectionView = {
let flowLayout = UICollectionViewFlowLayout()
Expand All @@ -70,10 +60,27 @@ final class CollectionViewController: UIViewController {
collectionView.backgroundColor = .white
return collectionView
}()

private func makeSnapshot(animatingDifferences: Bool = true) {
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
self.snapshot = snapshot
snapshot.appendSections([1])
snapshot.appendItems(
(1...10000).map { "item: \($0) + UUID: \(UUID())" },
toSection: 1)
DispatchQueue.main.async { [weak self] in
self?.dataSource?.apply(
snapshot,
animatingDifferences: animatingDifferences)
}
}

}

private final class CollectionCell: UICollectionViewCell {

// MARK: Lifecycle

override init(frame: CGRect) {
super.init(frame: frame)
addSubview(label)
Expand All @@ -92,12 +99,16 @@ private final class CollectionCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}

// MARK: Internal

var text: NSAttributedString? {
didSet {
label.attributedText = text
}
}

// MARK: Private

private let label: LCLabel = {
let label = LCLabel(frame: .zero)
label.backgroundColor = .white
Expand Down
4 changes: 2 additions & 2 deletions DemoApp/DemoApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class LCLabelViewController: UIViewController {
frame: CGRect(origin: rect.origin, size: rect.size),
text: text)
label4.numberOfLines = 0
label4.textAlignment = .center
label4.centeringTextAlignment = .center
label4.delegate = self

rect.origin.y += 100
Expand All @@ -99,7 +99,7 @@ final class LCLabelViewController: UIViewController {
label.linkAttributes = [
.foregroundColor: UIColor.white,
]
label.textAlignment = .top
label.centeringTextAlignment = .top
label.isUserInteractionEnabled = true
label.numberOfLines = 1
label.attributedText = text
Expand Down
7 changes: 6 additions & 1 deletion DemoApp/LCLabelUITests/LCLabelHitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import XCTest
// Screenshots taken on an iPhone 13
final class LCLabelHitTests: XCTestCase {

private var app: XCUIApplication!
// MARK: Internal

override func setUpWithError() throws {
continueAfterFailure = false
Expand Down Expand Up @@ -122,6 +122,11 @@ final class LCLabelHitTests: XCTestCase {
main.staticTexts["translator"].label,
"")
}

// MARK: Private

private var app: XCUIApplication!

}

private extension XCUIApplication {
Expand Down
6 changes: 5 additions & 1 deletion DemoApp/LCLabelUITests/LCLabelScrollTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import XCTest

final class LCLabelScrollTests: XCTestCase {

private var app: XCUIApplication!
// MARK: Internal

override func setUpWithError() throws {
continueAfterFailure = false
Expand Down Expand Up @@ -51,4 +51,8 @@ final class LCLabelScrollTests: XCTestCase {
}


// MARK: Private

private var app: XCUIApplication!

}
4 changes: 2 additions & 2 deletions LCLabel.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Pod::Spec.new do |s|
s.name = 'LCLabel'
s.version = '0.5.0'
s.summary = 'LCLabel is a TextKit 2 based UIView'
s.description = "LCLabel is a TextKit 2 based UIView that mimics a the behaviour of UILabel & UITextView"
s.summary = 'LCLabel is a TextKit 2 based UILabel'
s.description = "LCLabel is a TextKit 2 based UILabel that mimics a the behaviour of UITextView"
s.homepage = 'https://github.com/mustiikhalil/LCLabel'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'mustii' => '[email protected]' }
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![codecov](https://codecov.io/gh/mustiikhalil/LCLabel/branch/main/graph/badge.svg?token=KAH2KVQ5MQ)](https://codecov.io/gh/mustiikhalil/LCLabel)
![Build status](https://github.com/mustiikhalil/lclabel/actions/workflows/build.yml/badge.svg?branch=main)

LCLabel is a TextKit 2 based UIView that mimics a the behaviour of UILabel & UITextView
LCLabel is a TextKit 2 based UILabel that mimics a the behaviour of UITextView

## Installation

Expand All @@ -26,8 +26,6 @@ dependencies: [

## How to use:

Using LCLabel is as simple as using a UILabel

```swift
let text = NSMutableAttributedString(
string: "welcome to this new adventure!!!",
Expand Down Expand Up @@ -128,6 +126,6 @@ where both labels had zero hitches when scrolling a list around 5 times each tim

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

### Disclamre
### Disclaimer

[UILabel](https://developer.apple.com/documentation/uikit/uilabel/) and [UITextView](https://developer.apple.com/documentation/uikit/uitextview) are Apple's own components.
[UILabel](https://developer.apple.com/documentation/uikit/uilabel/) and [UITextView](https://developer.apple.com/documentation/uikit/uitextview) are Apple's own components.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4d26bb6

Please sign in to comment.