Skip to content

Instantly share code, notes, and snippets.

@harryf
Created March 2, 2016 19:18
Show Gist options
  • Save harryf/df0cda4af13369246c3c to your computer and use it in GitHub Desktop.
Save harryf/df0cda4af13369246c3c to your computer and use it in GitHub Desktop.
hacks to make tasty-imitiation-keyboard importable from another project
diff --git a/Keyboard/DirectionEnum.swift b/Keyboard/DirectionEnum.swift
index 5371350..3fcd9d4 100644
--- a/Keyboard/DirectionEnum.swift
+++ b/Keyboard/DirectionEnum.swift
@@ -6,13 +6,13 @@
// Copyright (c) 2014 Alexei Baboulevitch ("Archagon"). All rights reserved.
//
-enum Direction: Int, CustomStringConvertible {
+public enum Direction: Int, CustomStringConvertible {
case Left = 0
case Down = 3
case Right = 2
case Up = 1
- var description: String {
+ public var description: String {
get {
switch self {
case Left:
@@ -27,7 +27,7 @@ enum Direction: Int, CustomStringConvertible {
}
}
- func clockwise() -> Direction {
+ public func clockwise() -> Direction {
switch self {
case Left:
return Up
@@ -40,7 +40,7 @@ enum Direction: Int, CustomStringConvertible {
}
}
- func counterclockwise() -> Direction {
+ public func counterclockwise() -> Direction {
switch self {
case Left:
return Down
@@ -53,7 +53,7 @@ enum Direction: Int, CustomStringConvertible {
}
}
- func opposite() -> Direction {
+ public func opposite() -> Direction {
switch self {
case Left:
return Right
@@ -66,7 +66,7 @@ enum Direction: Int, CustomStringConvertible {
}
}
- func horizontal() -> Bool {
+ public func horizontal() -> Bool {
switch self {
case
Left,
diff --git a/Keyboard/ExtraView.swift b/Keyboard/ExtraView.swift
index 794f9e4..b176e27 100644
--- a/Keyboard/ExtraView.swift
+++ b/Keyboard/ExtraView.swift
@@ -8,13 +8,13 @@
import UIKit
-class ExtraView: UIView {
+public class ExtraView: UIView {
var globalColors: GlobalColors.Type?
var darkMode: Bool
var solidColorMode: Bool
- required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool) {
+ required public init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool) {
self.globalColors = globalColors
self.darkMode = darkMode
self.solidColorMode = solidColorMode
@@ -22,7 +22,7 @@ class ExtraView: UIView {
super.init(frame: CGRectZero)
}
- required init?(coder aDecoder: NSCoder) {
+ required public init?(coder aDecoder: NSCoder) {
self.globalColors = nil
self.darkMode = false
self.solidColorMode = false
diff --git a/Keyboard/KeyboardLayout.swift b/Keyboard/KeyboardLayout.swift
index 5e5fb77..de7a03d 100644
--- a/Keyboard/KeyboardLayout.swift
+++ b/Keyboard/KeyboardLayout.swift
@@ -9,7 +9,7 @@
import UIKit
// TODO: need to rename, consolidate, and define terms
-class LayoutConstants: NSObject {
+public class LayoutConstants: NSObject {
class var landscapeRatio: CGFloat { get { return 2 }}
// side edges increase on 6 in portrait
@@ -157,7 +157,7 @@ class LayoutConstants: NSObject {
}
}
-class GlobalColors: NSObject {
+public class GlobalColors: NSObject {
class var lightModeRegularKey: UIColor { get { return UIColor.whiteColor() }}
class var darkModeRegularKey: UIColor { get { return UIColor.whiteColor().colorWithAlphaComponent(CGFloat(0.3)) }}
class var darkModeSolidColorRegularKey: UIColor { get { return UIColor(red: CGFloat(83)/CGFloat(255), green: CGFloat(83)/CGFloat(255), blue: CGFloat(83)/CGFloat(255), alpha: 1) }}
@@ -246,7 +246,7 @@ extension CGSize: Hashable {
}
// handles the layout for the keyboard, including key spacing and arrangement
-class KeyboardLayout: NSObject, KeyboardKeyProtocol {
+public class KeyboardLayout: NSObject, KeyboardKeyProtocol {
class var shouldPoolKeys: Bool { get { return true }}
@@ -267,7 +267,7 @@ class KeyboardLayout: NSObject, KeyboardKeyProtocol {
var solidColorMode: Bool
var initialized: Bool
- required init(model: Keyboard, superview: UIView, layoutConstants: LayoutConstants.Type, globalColors: GlobalColors.Type, darkMode: Bool, solidColorMode: Bool) {
+ public required init(model: Keyboard, superview: UIView, layoutConstants: LayoutConstants.Type, globalColors: GlobalColors.Type, darkMode: Bool, solidColorMode: Bool) {
self.layoutConstants = layoutConstants
self.globalColors = globalColors
diff --git a/Keyboard/KeyboardModel.swift b/Keyboard/KeyboardModel.swift
index 76ba19b..66a83af 100644
--- a/Keyboard/KeyboardModel.swift
+++ b/Keyboard/KeyboardModel.swift
@@ -27,7 +27,7 @@ enum ShiftState {
}
}
-class Keyboard {
+public class Keyboard {
var pages: [Page]
init() {
@@ -63,7 +63,7 @@ class Page {
}
}
-class Key: Hashable {
+public class Key: Hashable {
enum KeyType {
case Character
case SpecialCharacter
@@ -127,7 +127,7 @@ class Key: Hashable {
}
// TODO: this is kind of a hack
- var hashValue: Int
+ public var hashValue: Int
init(_ type: KeyType) {
self.type = type
@@ -203,6 +203,6 @@ class Key: Hashable {
}
}
-func ==(lhs: Key, rhs: Key) -> Bool {
+public func ==(lhs: Key, rhs: Key) -> Bool {
return lhs.hashValue == rhs.hashValue
}
diff --git a/Keyboard/KeyboardViewController.swift b/Keyboard/KeyboardViewController.swift
index c163634..0f372ef 100644
--- a/Keyboard/KeyboardViewController.swift
+++ b/Keyboard/KeyboardViewController.swift
@@ -20,7 +20,7 @@ let kPeriodShortcut = "kPeriodShortcut"
let kKeyboardClicks = "kKeyboardClicks"
let kSmallLowercase = "kSmallLowercase"
-class KeyboardViewController: UIInputViewController {
+public class KeyboardViewController: UIInputViewController {
let backspaceDelay: NSTimeInterval = 0.5
let backspaceRepeat: NSTimeInterval = 0.07
@@ -89,11 +89,11 @@ class KeyboardViewController: UIInputViewController {
}
// TODO: why does the app crash if this isn't here?
- convenience init() {
+ public convenience init() {
self.init(nibName: nil, bundle: nil)
}
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
+ public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
NSUserDefaults.standardUserDefaults().registerDefaults([
kAutoCapitalization: true,
kPeriodShortcut: true,
@@ -114,7 +114,7 @@ class KeyboardViewController: UIInputViewController {
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("defaultsChanged:"), name: NSUserDefaultsDidChangeNotification, object: nil)
}
- required init?(coder: NSCoder) {
+ public required init?(coder: NSCoder) {
fatalError("NSCoding not supported")
}
@@ -203,7 +203,7 @@ class KeyboardViewController: UIInputViewController {
}
var lastLayoutBounds: CGRect?
- override func viewDidLayoutSubviews() {
+ public override func viewDidLayoutSubviews() {
if view.bounds == CGRectZero {
return
}
@@ -231,7 +231,7 @@ class KeyboardViewController: UIInputViewController {
self.forwardingView.frame.origin = newOrigin
}
- override func loadView() {
+ public override func loadView() {
super.loadView()
if let aBanner = self.createBanner() {
@@ -241,12 +241,12 @@ class KeyboardViewController: UIInputViewController {
}
}
- override func viewWillAppear(animated: Bool) {
+ public override func viewWillAppear(animated: Bool) {
self.bannerView?.hidden = false
self.keyboardHeight = self.heightForOrientation(self.interfaceOrientation, withTopBanner: true)
}
- override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
+ public override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
self.forwardingView.resetTrackedViews()
self.shiftStartingState = nil
self.shiftWasMultitapped = false
@@ -261,7 +261,7 @@ class KeyboardViewController: UIInputViewController {
self.keyboardHeight = self.heightForOrientation(toInterfaceOrientation, withTopBanner: true)
}
- override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
+ public override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
// optimization: ensures quick mode and shift transitions
if let keyPool = self.layout?.keyPool {
for view in keyPool {
@@ -384,13 +384,13 @@ class KeyboardViewController: UIInputViewController {
// POPUP DELAY END //
/////////////////////
- override func didReceiveMemoryWarning() {
+ public override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
// TODO: this is currently not working as intended; only called when selection changed -- iOS bug
- override func textDidChange(textInput: UITextInput?) {
+ public override func textDidChange(textInput: UITextInput?) {
self.contextChanged()
}
@@ -805,23 +805,23 @@ class KeyboardViewController: UIInputViewController {
// MOST COMMONLY EXTENDABLE METHODS //
//////////////////////////////////////
- class var layoutClass: KeyboardLayout.Type { get { return KeyboardLayout.self }}
- class var layoutConstants: LayoutConstants.Type { get { return LayoutConstants.self }}
- class var globalColors: GlobalColors.Type { get { return GlobalColors.self }}
+ public class var layoutClass: KeyboardLayout.Type { get { return KeyboardLayout.self }}
+ public class var layoutConstants: LayoutConstants.Type { get { return LayoutConstants.self }}
+ public class var globalColors: GlobalColors.Type { get { return GlobalColors.self }}
- func keyPressed(key: Key) {
+ public func keyPressed(key: Key) {
self.textDocumentProxy.insertText(key.outputForCase(self.shiftState.uppercase()))
}
// a banner that sits in the empty space on top of the keyboard
- func createBanner() -> ExtraView? {
+ public func createBanner() -> ExtraView? {
// note that dark mode is not yet valid here, so we just put false for clarity
//return ExtraView(globalColors: self.dynamicType.globalColors, darkMode: false, solidColorMode: self.solidColorMode())
return nil
}
// a settings view that replaces the keyboard when the settings button is pressed
- func createSettings() -> ExtraView? {
+ public func createSettings() -> ExtraView? {
// note that dark mode is not yet valid here, so we just put false for clarity
let settingsView = DefaultSettings(globalColors: self.dynamicType.globalColors, darkMode: false, solidColorMode: self.solidColorMode())
settingsView.backButton?.addTarget(self, action: Selector("toggleSettings"), forControlEvents: UIControlEvents.TouchUpInside)
diff --git a/KeyboardFramework/KeyboardFramework.h b/KeyboardFramework/KeyboardFramework.h
index b2e7e88..89ff241 100644
--- a/KeyboardFramework/KeyboardFramework.h
+++ b/KeyboardFramework/KeyboardFramework.h
@@ -15,5 +15,5 @@ FOUNDATION_EXPORT double KeyboardFrameworkVersionNumber;
FOUNDATION_EXPORT const unsigned char KeyboardFrameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <KeyboardFramework/PublicHeader.h>
-#import <KeyboardFramework/UIImage+ImageEffects.h>
+//#import <KeyboardFramework/KeyboardViewController-Swift.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment