Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored animation logic into an animator that accepts a UILabel so… #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Example/Example/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="rYz-Gt-6NH">
<rect key="frame" x="20" y="8" width="335" height="210.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="The heroic tale 💪 of one developer's pursuit of the perfect typing animation - there will be a 🐲!" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="S1C-Sz-CSn" customClass="TypewriterLabel" customModule="GhostTypewriter">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="The heroic tale 💪 of one developer's pursuit of the perfect typing animation - there will be a 🐲!" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="S1C-Sz-CSn">
<rect key="frame" x="0.0" y="0.0" width="335" height="98.5"/>
<fontDescription key="fontDescription" name="AmericanTypewriter-Bold" family="American Typewriter" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mrA-eT-4zu" customClass="TypewriterLabel" customModule="GhostTypewriter">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mrA-eT-4zu">
<rect key="frame" x="0.0" y="106.5" width="335" height="104"/>
<string key="text">OK...truth time...the part about a dragon and the part about being heroic - not true 😫.

Expand Down Expand Up @@ -165,13 +165,13 @@ This really is just an excuse to show you the animation in action and how it can
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="4uW-fX-GXd">
<rect key="frame" x="20" y="8" width="335" height="210.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="The heroic tale 💪 of one developer's pursuit of the perfect typing animation - there will be a 🐲!" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EmO-Ah-7fm" customClass="TypewriterLabel" customModule="GhostTypewriter">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="The heroic tale 💪 of one developer's pursuit of the perfect typing animation - there will be a 🐲!" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EmO-Ah-7fm">
<rect key="frame" x="0.0" y="0.0" width="335" height="98.5"/>
<fontDescription key="fontDescription" name="AmericanTypewriter-Bold" family="American Typewriter" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vre-s3-dVX" customClass="TypewriterLabel" customModule="GhostTypewriter">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vre-s3-dVX">
<rect key="frame" x="0.0" y="106.5" width="335" height="104"/>
<string key="text">OK...truth time...the part about a dragon and the part about being heroic - not true 😫.

Expand Down Expand Up @@ -276,7 +276,7 @@ This really is just an excuse to show you the animation in action and how it can
</scene>
</scenes>
<resources>
<image name="backward" width="64" height="64"/>
<image name="forward" width="64" height="64"/>
<image name="backward" width="21.333333969116211" height="21.333333969116211"/>
<image name="forward" width="21.333333969116211" height="21.333333969116211"/>
</resources>
</document>
69 changes: 41 additions & 28 deletions Example/Example/ViewControllers/BackwardHideViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@ class BackwardHideViewController: UIViewController {
@IBOutlet weak private var restartButton: UIButton!
@IBOutlet weak private var completeButton: UIButton!

@IBOutlet weak private var titleLabel: TypewriterLabel! {
@IBOutlet weak private var titleLabel: UILabel! {
didSet {
titleLabel.styleAsMultilineBackwardlyHidingAnimation()
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.numberOfLines = 0
titleLabelTypewriterAnimator = TypewriterAnimator.backwardlyHiding(label: titleLabel)
}
}

@IBOutlet weak private var descriptionLabel: TypewriterLabel! {
private var titleLabelTypewriterAnimator: TypewriterAnimator!

@IBOutlet weak private var descriptionLabel: UILabel! {
didSet {
descriptionLabel.styleAsMultilineBackwardlyHidingAnimation()
descriptionLabel.lineBreakMode = .byWordWrapping
descriptionLabel.numberOfLines = 0
descriptionLabelTypewriterAnimator = TypewriterAnimator.backwardlyHiding(label: descriptionLabel)
}
}

private lazy var programmaticLabel: TypewriterLabel = {
let programmaticLabel = TypewriterLabel()
programmaticLabel.styleAsMultilineBackwardlyHidingAnimation()
private var descriptionLabelTypewriterAnimator: TypewriterAnimator!

private lazy var programmaticLabel: UILabel = {
let programmaticLabel = UILabel()
programmaticLabel.lineBreakMode = .byWordWrapping
programmaticLabel.numberOfLines = 0
programmaticLabel.font = UIFont(name: "American Typewriter", size: 15)

let text = "Still not convinced...\n\nWell this label shows support for attributed labels created programmatically rather than via storyboards so maybe that will soothe you."
Expand All @@ -51,9 +60,13 @@ class BackwardHideViewController: UIViewController {

programmaticLabel.attributedText = attributedString

programmaticLabelTypewriterAnimator = TypewriterAnimator.backwardlyHiding(label: programmaticLabel)

return programmaticLabel
}()

private var programmaticLabelTypewriterAnimator: TypewriterAnimator!

// MARK: - ViewLifecycle

override func viewDidLoad() {
Expand All @@ -71,11 +84,11 @@ class BackwardHideViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = true

programmaticLabel.startTypewritingAnimation {
if !(self.descriptionLabel.isComplete) {
self.descriptionLabel.startTypewritingAnimation {
if !(self.titleLabel.isComplete) {
self.titleLabel.startTypewritingAnimation {
programmaticLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.descriptionLabelTypewriterAnimator.isComplete) {
self.descriptionLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.titleLabelTypewriterAnimator.isComplete) {
self.titleLabelTypewriterAnimator.startTypewritingAnimation {
self.stopButtonPressed(self.stopButton!)
}
}
Expand All @@ -91,9 +104,9 @@ class BackwardHideViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = true

titleLabel.stopTypewritingAnimation()
descriptionLabel.stopTypewritingAnimation()
programmaticLabel.stopTypewritingAnimation()
titleLabelTypewriterAnimator.stopTypewritingAnimation()
descriptionLabelTypewriterAnimator.stopTypewritingAnimation()
programmaticLabelTypewriterAnimator.stopTypewritingAnimation()
}

@IBAction func resetButtonPressed(_ sender: Any) {
Expand All @@ -103,9 +116,9 @@ class BackwardHideViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = false

titleLabel.resetTypewritingAnimation()
descriptionLabel.resetTypewritingAnimation()
programmaticLabel.resetTypewritingAnimation()
titleLabelTypewriterAnimator.resetTypewritingAnimation()
descriptionLabelTypewriterAnimator.resetTypewritingAnimation()
programmaticLabelTypewriterAnimator.resetTypewritingAnimation()
}

@IBAction func restartButtonPressed(_ sender: Any) {
Expand All @@ -115,13 +128,13 @@ class BackwardHideViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = true

titleLabel.resetTypewritingAnimation()
descriptionLabel.resetTypewritingAnimation()
programmaticLabel.restartTypewritingAnimation {
if !(self.descriptionLabel.isComplete) {
self.descriptionLabel.startTypewritingAnimation {
if !(self.titleLabel.isComplete) {
self.titleLabel.startTypewritingAnimation {
titleLabelTypewriterAnimator.resetTypewritingAnimation()
descriptionLabelTypewriterAnimator.resetTypewritingAnimation()
programmaticLabelTypewriterAnimator.restartTypewritingAnimation {
if !(self.descriptionLabelTypewriterAnimator.isComplete) {
self.descriptionLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.titleLabelTypewriterAnimator.isComplete) {
self.titleLabelTypewriterAnimator.startTypewritingAnimation {
self.stopButtonPressed(self.stopButton!)
}
}
Expand All @@ -137,8 +150,8 @@ class BackwardHideViewController: UIViewController {
completeButton.isEnabled = false
restartButton.isEnabled = true

programmaticLabel.completeTypewritingAnimation()
descriptionLabel.completeTypewritingAnimation()
titleLabel.completeTypewritingAnimation()
programmaticLabelTypewriterAnimator.completeTypewritingAnimation()
descriptionLabelTypewriterAnimator.completeTypewritingAnimation()
titleLabelTypewriterAnimator.completeTypewritingAnimation()
}
}
71 changes: 42 additions & 29 deletions Example/Example/ViewControllers/ForwardRevealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@ class ForwardRevealViewController: UIViewController {
@IBOutlet weak private var restartButton: UIButton!
@IBOutlet weak private var completeButton: UIButton!

@IBOutlet weak private var titleLabel: TypewriterLabel! {
@IBOutlet weak private var titleLabel: UILabel! {
didSet {
titleLabel.styleAsMultilineForwardlyRevealingAnimation()
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.numberOfLines = 0
titleLabelTypewriterAnimator = TypewriterAnimator.forwardlyRevealing(label: titleLabel)
}
}

@IBOutlet weak private var descriptionLabel: TypewriterLabel! {
private var titleLabelTypewriterAnimator: TypewriterAnimator!

@IBOutlet weak private var descriptionLabel: UILabel! {
didSet {
descriptionLabel.styleAsMultilineForwardlyRevealingAnimation()
descriptionLabel.lineBreakMode = .byWordWrapping
descriptionLabel.numberOfLines = 0
descriptionLabelTypewriterAnimator = TypewriterAnimator.forwardlyRevealing(label: descriptionLabel)
}
}

private lazy var programmaticLabel: TypewriterLabel = {
let programmaticLabel = TypewriterLabel()
programmaticLabel.styleAsMultilineForwardlyRevealingAnimation()
private var descriptionLabelTypewriterAnimator: TypewriterAnimator!

private lazy var programmaticLabel: UILabel = {
let programmaticLabel = UILabel()
programmaticLabel.lineBreakMode = .byWordWrapping
programmaticLabel.numberOfLines = 0
programmaticLabel.font = UIFont(name: "American Typewriter", size: 15)

let text = "Still not convinced...\n\nWell this label shows support for attributed labels created programmatically rather than via storyboards so maybe that will soothe you."
Expand All @@ -51,9 +60,13 @@ class ForwardRevealViewController: UIViewController {

programmaticLabel.attributedText = attributedString

programmaticLabelTypewriterAnimator = TypewriterAnimator.forwardlyRevealing(label: programmaticLabel)

return programmaticLabel
}()

private var programmaticLabelTypewriterAnimator: TypewriterAnimator!

// MARK: - ViewLifecycle

override func viewDidLoad() {
Expand All @@ -70,12 +83,12 @@ class ForwardRevealViewController: UIViewController {
resetButton.isEnabled = true
completeButton.isEnabled = true
restartButton.isEnabled = true
titleLabel.startTypewritingAnimation {
if !(self.descriptionLabel.isComplete) {
self.descriptionLabel.startTypewritingAnimation {
if !(self.programmaticLabel.isComplete) {
self.programmaticLabel.startTypewritingAnimation {

titleLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.descriptionLabelTypewriterAnimator.isComplete) {
self.descriptionLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.programmaticLabelTypewriterAnimator.isComplete) {
self.programmaticLabelTypewriterAnimator.startTypewritingAnimation {
self.stopButtonPressed(self.stopButton!)
}
}
Expand All @@ -91,9 +104,9 @@ class ForwardRevealViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = true

titleLabel.stopTypewritingAnimation()
descriptionLabel.stopTypewritingAnimation()
programmaticLabel.stopTypewritingAnimation()
titleLabelTypewriterAnimator.stopTypewritingAnimation()
descriptionLabelTypewriterAnimator.stopTypewritingAnimation()
programmaticLabelTypewriterAnimator.stopTypewritingAnimation()
}

@IBAction func resetButtonPressed(_ sender: Any) {
Expand All @@ -103,9 +116,9 @@ class ForwardRevealViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = false

titleLabel.resetTypewritingAnimation()
descriptionLabel.resetTypewritingAnimation()
programmaticLabel.resetTypewritingAnimation()
titleLabelTypewriterAnimator.resetTypewritingAnimation()
descriptionLabelTypewriterAnimator.resetTypewritingAnimation()
programmaticLabelTypewriterAnimator.resetTypewritingAnimation()
}

@IBAction func restartButtonPressed(_ sender: Any) {
Expand All @@ -115,13 +128,13 @@ class ForwardRevealViewController: UIViewController {
completeButton.isEnabled = true
restartButton.isEnabled = true

descriptionLabel.resetTypewritingAnimation()
programmaticLabel.resetTypewritingAnimation()
titleLabel.restartTypewritingAnimation {
if !(self.descriptionLabel.isComplete) {
self.descriptionLabel.startTypewritingAnimation {
if !(self.programmaticLabel.isComplete) {
self.programmaticLabel.startTypewritingAnimation {
descriptionLabelTypewriterAnimator.resetTypewritingAnimation()
programmaticLabelTypewriterAnimator.resetTypewritingAnimation()
titleLabelTypewriterAnimator.restartTypewritingAnimation {
if !(self.descriptionLabelTypewriterAnimator.isComplete) {
self.descriptionLabelTypewriterAnimator.startTypewritingAnimation {
if !(self.programmaticLabelTypewriterAnimator.isComplete) {
self.programmaticLabelTypewriterAnimator.startTypewritingAnimation {
self.stopButtonPressed(self.stopButton!)
}
}
Expand All @@ -137,8 +150,8 @@ class ForwardRevealViewController: UIViewController {
completeButton.isEnabled = false
restartButton.isEnabled = true

titleLabel.completeTypewritingAnimation()
descriptionLabel.completeTypewritingAnimation()
programmaticLabel.completeTypewritingAnimation()
titleLabelTypewriterAnimator.completeTypewritingAnimation()
descriptionLabelTypewriterAnimator.completeTypewritingAnimation()
programmaticLabelTypewriterAnimator.completeTypewritingAnimation()
}
}
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- GhostTypewriter (2.0.1)
- GhostTypewriter (2.1.0)

DEPENDENCIES:
- GhostTypewriter (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
GhostTypewriter: 1f655ea369860f854668a8f8f7cc63490599ded4
GhostTypewriter: 62540772d227fbfe633bfa728d08fe8af5b4d805

PODFILE CHECKSUM: 1cd016dcc7aa7f7022cb854ac9b4b50f62048cb3

COCOAPODS: 1.9.3
COCOAPODS: 1.11.2
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/GhostTypewriter.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading