Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
joeynelson42 committed Jul 9, 2017
1 parent 781127d commit a0272e3
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 49 deletions.
21 changes: 9 additions & 12 deletions DossyText.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
/* Begin PBXBuildFile section */
F1B4AF691F12708F004A88D5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B4AF681F12708F004A88D5 /* AppDelegate.swift */; };
F1B4AF6B1F12708F004A88D5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B4AF6A1F12708F004A88D5 /* ViewController.swift */; };
F1B4AF6E1F12708F004A88D5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1B4AF6C1F12708F004A88D5 /* Main.storyboard */; };
F1B4AF701F12708F004A88D5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F1B4AF6F1F12708F004A88D5 /* Assets.xcassets */; };
F1B4AF731F12708F004A88D5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1B4AF711F12708F004A88D5 /* LaunchScreen.storyboard */; };
F1B4AF7B1F127197004A88D5 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B4AF7A1F127197004A88D5 /* View.swift */; };
F1B4AF7D1F1271B7004A88D5 /* DossyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B4AF7C1F1271B7004A88D5 /* DossyText.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
F1B4AF651F12708F004A88D5 /* DossyText.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DossyText.app; sourceTree = BUILT_PRODUCTS_DIR; };
F1B4AF681F12708F004A88D5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F1B4AF6A1F12708F004A88D5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
F1B4AF6D1F12708F004A88D5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
F1B4AF6F1F12708F004A88D5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F1B4AF721F12708F004A88D5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F1B4AF741F12708F004A88D5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F1B4AF7A1F127197004A88D5 /* View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
F1B4AF7C1F1271B7004A88D5 /* DossyText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DossyText.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -56,7 +58,8 @@
children = (
F1B4AF681F12708F004A88D5 /* AppDelegate.swift */,
F1B4AF6A1F12708F004A88D5 /* ViewController.swift */,
F1B4AF6C1F12708F004A88D5 /* Main.storyboard */,
F1B4AF7A1F127197004A88D5 /* View.swift */,
F1B4AF7C1F1271B7004A88D5 /* DossyText.swift */,
F1B4AF6F1F12708F004A88D5 /* Assets.xcassets */,
F1B4AF711F12708F004A88D5 /* LaunchScreen.storyboard */,
F1B4AF741F12708F004A88D5 /* Info.plist */,
Expand Down Expand Up @@ -126,7 +129,6 @@
files = (
F1B4AF731F12708F004A88D5 /* LaunchScreen.storyboard in Resources */,
F1B4AF701F12708F004A88D5 /* Assets.xcassets in Resources */,
F1B4AF6E1F12708F004A88D5 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -138,21 +140,15 @@
buildActionMask = 2147483647;
files = (
F1B4AF6B1F12708F004A88D5 /* ViewController.swift in Sources */,
F1B4AF7D1F1271B7004A88D5 /* DossyText.swift in Sources */,
F1B4AF691F12708F004A88D5 /* AppDelegate.swift in Sources */,
F1B4AF7B1F127197004A88D5 /* View.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
F1B4AF6C1F12708F004A88D5 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
F1B4AF6D1F12708F004A88D5 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
F1B4AF711F12708F004A88D5 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -302,6 +298,7 @@
F1B4AF791F12708F004A88D5 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F1B4AF641F12708F004A88D5"
BuildableName = "DossyText.app"
BlueprintName = "DossyText"
ReferencedContainer = "container:DossyText.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand All @@ -13,6 +29,15 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F1B4AF641F12708F004A88D5"
BuildableName = "DossyText.app"
BlueprintName = "DossyText"
ReferencedContainer = "container:DossyText.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -26,6 +51,16 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F1B4AF641F12708F004A88D5"
BuildableName = "DossyText.app"
BlueprintName = "DossyText"
ReferencedContainer = "container:DossyText.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -35,6 +70,16 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F1B4AF641F12708F004A88D5"
BuildableName = "DossyText.app"
BlueprintName = "DossyText"
ReferencedContainer = "container:DossyText.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
6 changes: 6 additions & 0 deletions DossyText/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

let vc = ViewController()
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = vc

return true
}

Expand Down
26 changes: 0 additions & 26 deletions DossyText/Base.lproj/Main.storyboard

This file was deleted.

118 changes: 118 additions & 0 deletions DossyText/DossyText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// DossyText.swift
// DossyText
//
// Created by Joey Nelson on 7/9/17.
// Copyright © 2017 NelsonJE. All rights reserved.
//

import UIKit

@objc
public protocol DossyTextLabelDelegate {
@objc optional func DossyTextLabel(_ label: DossyTextLabel, didFinishTypingText text: String)
@objc optional func didFinishBlinking(_ label: DossyTextLabel)
}

open class DossyTextLabel: UILabel {

private enum LabelState {
case typing
case blinking
case idle
}

// MARK: - Properties

//Public
public var delegate: DossyTextLabelDelegate?
public var blinksWhileIdle: Bool = true
public var millisecondsPerLetter = 70

// Private
private var state: LabelState = .idle
private var mostRecentAddition: String = ""
private var currentText: String = ""
private var fullText: String = ""
private var blinkingText: String = ""
private var blinking = false
private var timer: Timer!

// MARK: - Blinking
public func blinkIndefinitely() {
state = .blinking

blink()

blinking = true
}

public func blink(forInterval interval: TimeInterval) {
blinkIndefinitely()
timer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(stopBlinking), userInfo: nil, repeats: false)
}

private func blink(_ repeats: Bool = true) {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(250)) {
if self.text == self.blinkingText {
self.text = "\(self.blinkingText)"
} else {
self.text = self.blinkingText
}

if self.state == .blinking && repeats {
self.blink()
} else {
self.delegate?.didFinishBlinking?(self)
}
}
}

public func stopBlinking() {
state = .idle
}


// MARK: - Typing
public func type(_ stringToType: String) {
state = .typing
mostRecentAddition = stringToType
fullText = "\(fullText)\(stringToType)"
type()
}

private func type() {
if fullText == currentText {
typingEnded()
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(millisecondsPerLetter)) {
let stripped = self.fullText.replacingOccurrences(of: self.currentText, with: "")
guard let char = stripped.characters.first else { return }
self.currentText = self.currentText + String(describing: char)
self.text = self.currentText
self.type()
}
}

private func typingEnded() {
blinkingText = fullText

if blinksWhileIdle {
blinkIndefinitely()
} else {
state = .idle
}

delegate?.DossyTextLabel?(self, didFinishTypingText: mostRecentAddition)
}

// MARK: - Idling
public func idle(){
stopBlinking()
text = fullText
state = .idle
}
}

2 changes: 1 addition & 1 deletion DossyText/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
63 changes: 63 additions & 0 deletions DossyText/View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// View.swift
// DossyText
//
// Created by Joey Nelson on 7/9/17.
// Copyright © 2017 NelsonJE. All rights reserved.
//

import Foundation
//
// BaseView.swift
//

import UIKit

class View: UIView {

// MARK: - Properties

// MARK: - Subviews
var blink: DossyTextLabel!

// MARK: - Initialization

convenience init() {
self.init(frame: .zero)
configureSubviews()
configureLayout()
}

/// Set view/subviews appearances
fileprivate func configureSubviews() {
backgroundColor = UIColor.fromHex(rgbValue: 0x181818)

blink = DossyTextLabel()
blink.textColor = UIColor.fromHex(rgbValue: 0x1DB954)
blink.numberOfLines = 0
}

/// Add subviews, set layoutMargins, initialize stored constraints, set layout priorities, activate constraints
fileprivate func configureLayout() {

addSubview(blink)
blink.translatesAutoresizingMaskIntoConstraints = false

// Activate NSLayoutAnchors within this closure
NSLayoutConstraint.activate([
blink.topAnchor.constraint(equalTo: topAnchor, constant: 25),
blink.leftAnchor.constraint(equalTo: leftAnchor, constant: 25),
blink.rightAnchor.constraint(equalTo: rightAnchor, constant: -25)
])
}
}

extension UIColor{
class func fromHex(rgbValue:UInt32, alpha:Double=1.0) -> UIColor{
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
let blue = CGFloat(rgbValue & 0xFF)/256.0

return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}
}
Loading

0 comments on commit a0272e3

Please sign in to comment.