Skip to content

Commit 9ebd270

Browse files
Merge pull request #6 from thisIsTheFoxe/update/ios14
Updated version for iOS 14 & Swift 5.3
2 parents 8177d02 + 3dd1df9 commit 9ebd270

File tree

15 files changed

+231
-179
lines changed

15 files changed

+231
-179
lines changed

.github/workflows/lint.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Lints the project using SwiftLint
2+
name: SwiftLint
3+
4+
on: [push]
5+
6+
jobs:
7+
Lint:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: GitHub Action for SwiftLint
14+
uses: norio-nomura/action-swiftlint@3.1.0

.github/workflows/sonar.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/swift.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push]
55
jobs:
66
build:
77

8-
runs-on: macos
8+
runs-on: macos-latest
99

1010
# build also for iOS, not possible (yet)? .-.
1111

@@ -22,6 +22,6 @@ jobs:
2222
-ignore-filename-regex="(.build/|Tests/)" \
2323
.build/debug/SimpleKeyboardPackageTests.xctest/Contents/MacOS/SimpleKeyboardPackageTests > ./coverage.lcov
2424
- name: Codecov
25-
uses: codecov/codecov-action@v1.0.5
25+
uses: codecov/codecov-action@v1
2626
with:
2727
token: ${{ secrets.CODECOV_TOKEN }}

Package.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "SimpleKeyboard",
8+
defaultLocalization: "en",
89
//to be fair, watchOS support is pretty stupid, if you need it please open an issue...
910
platforms: [.iOS(SupportedPlatform.IOSVersion.v13), .macOS(SupportedPlatform.MacOSVersion.v10_15)],
1011
products: [
1112
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1213
.library(
1314
name: "SimpleKeyboard",
14-
targets: ["SimpleKeyboard"]),
15+
targets: ["SimpleKeyboard"])
1516
],
1617
dependencies: [
17-
// Dependencies declare other packages that this package depends on.
1818
// .package(url: /* package url */, from: "1.0.0"),
1919
],
2020
targets: [
21-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
22-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
21+
// Targets can depend on other targets.
2322
.target(
2423
name: "SimpleKeyboard",
2524
dependencies: []),
2625
.testTarget(
2726
name: "SimpleKeyboardTests",
28-
dependencies: ["SimpleKeyboard"]),
27+
dependencies: ["SimpleKeyboard"])
2928
]
3029
)

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# SimpleKeyboard
22

3+
[![Swift](https://github.com/thisIsTheFoxe/SimpleKeyboard/workflows/Swift/badge.svg)](https://github.com/thisIsTheFoxe/SimpleKeyboard/actions?query=workflow%3ASwift)
4+
[![SwiftLint](https://github.com/thisIsTheFoxe/SimpleKeyboard/workflows/SwiftLint/badge.svg)](https://github.com/thisIsTheFoxe/SimpleKeyboard/actions?query=workflow%3ASwiftLint)
35
[![codecov](https://codecov.io/gh/thisIsTheFoxe/SimpleKeyboard/branch/master/graph/badge.svg)](https://codecov.io/gh/thisIsTheFoxe/SimpleKeyboard)
4-
![](https://github.com/thisisthefoxe/SimpleKeyboard/workflows/Swift/badge.svg)
5-
![](https://github.com/thisisthefoxe/SimpleKeyboard/workflows/Sonarcloud/badge.svg)
6-
7-
6+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=thisIsTheFoxe_SimpleKeyboard&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=thisIsTheFoxe_SimpleKeyboard)
87

98
The idea of this package came from a keyboard-extension and the fact that - AFAIK - one can't open another keyboard within a keyboard-extension. So the goal was to have a ViewController, that simply displays the keyboard and changes a `text` variable.
109

@@ -19,12 +18,12 @@ Or one can choose to only display the keyboard with a the text input coming from
1918
### Use SimpleKeyboard with UIKit
2019
Here is an example implementation from one of my projects:
2120
```swift
22-
class MyViewController: UIViewController{
21+
class MyViewController: UIViewController {
2322
@IBOutlet var textField: UITextField!
2423

2524
//..........
2625

27-
func presentKeyboard(){
26+
func presentKeyboard() {
2827
let keyboardSettings = KeyboardSettings(language: .english, textInput: self.textField)
2928
let keyboardVC = MyKeyboardMaker(settings: keyboardSettings).makeViewController()
3029
self.contentController.pushViewController(keyboardVC, animated: true)
@@ -34,11 +33,11 @@ class MyViewController: UIViewController{
3433
```
3534

3635
```swift
37-
struct MyKeyboardMaker{
36+
struct MyKeyboardMaker {
3837

3938
@ObservedObject var settings: KeyboardSettings
4039

41-
func makeViewController()-> UIHostingController<SimpleStandardKeyboard>{
40+
func makeViewController() -> UIHostingController<SimpleStandardKeyboard> {
4241
UIHostingController(rootView: SimpleStandardKeyboard(settings: $settings)
4342
}
4443
}

Sources/SimpleKeyboard/Models/KeyboardSettings.swift

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,84 @@
88
import Combine
99
import SwiftUI
1010

11-
1211
public protocol SimpleKeyboardInput {
13-
var currentText: String { get }
12+
var currentText: String { get }
1413
mutating func replaceAll(with text: String)
1514
}
1615

1716
extension Binding: SimpleKeyboardInput where Value == String {
1817
public var currentText: String {
1918
self.wrappedValue
2019
}
21-
22-
public mutating func replaceAll(with text: String){
20+
21+
public mutating func replaceAll(with text: String) {
2322
self.wrappedValue = text
24-
print("mutating func replaceALl = "+self.wrappedValue)
2523
}
2624
}
2725

28-
#if canImport(AppKit)
26+
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
2927
import AppKit
30-
extension NSTextField: SimpleKeyboardInput{
28+
extension NSTextField: SimpleKeyboardInput {
3129
public var currentText: String {
3230
self.stringValue
3331
}
34-
35-
public func replaceAll(with text: String){
32+
33+
public func replaceAll(with text: String) {
3634
stringValue = text
3735
}
3836
}
3937
#endif
4038

4139
#if canImport(UIKit)
4240
import UIKit
43-
extension UITextField : SimpleKeyboardInput{
41+
42+
extension UITextField: SimpleKeyboardInput {
4443
public var currentText: String {
4544
self.text ?? ""
4645
}
47-
48-
public func replaceAll(with text: String){
46+
47+
public func replaceAll(with text: String) {
4948
self.text = text
5049
}
5150
}
5251
#endif
5352

5453
public class KeyboardSettings: ObservableObject {
5554
public var text: String = "" {
56-
didSet{
55+
didSet {
5756
textInput?.replaceAll(with: text)
5857
}
5958
}
60-
59+
6160
var language: Language
62-
61+
6362
public var textInput: SimpleKeyboardInput?
64-
public var action: (()->())?
65-
66-
// self._isShown = isShown
63+
public var action: (() -> Void)?
64+
6765
var showNumbers: Bool
6866
var showSpace: Bool
69-
67+
7068
///`nil` mean there is no need to switch, so there will be no shift-key
71-
var isUpperCase: Bool?{
72-
willSet{
73-
print("ay!")
69+
var isUpperCase: Bool? {
70+
willSet {
7471
objectWillChange.send()
7572
}
7673
}
7774

78-
///`textInput` should be `nil` when working directly with SwiftUI, in that case you would privide your 'bound' value directly to the keyboard
79-
public init(language: Language, textInput: SimpleKeyboardInput?, showNumbers: Bool = false, showSpace: Bool = false, isUpperCase: Bool? = nil, action: (()->())? = nil){
75+
///`textInput` should be `nil` when working directly with SwiftUI,
76+
///in that case you would bind your input directly to the `textInput` of the Keyboard
77+
public init(language: Language, textInput: SimpleKeyboardInput?, showNumbers: Bool = false,
78+
showSpace: Bool = false, isUpperCase: Bool? = nil, action: (() -> Void)? = nil) {
8079
self.textInput = textInput
8180
self.language = language
8281
self.action = action
8382
self.showNumbers = showNumbers
8483
self.showSpace = showSpace
8584
self.isUpperCase = isUpperCase
8685
}
87-
88-
func changeTextInput(to newInput: SimpleKeyboardInput){
86+
87+
func changeTextInput(to newInput: SimpleKeyboardInput) {
8988
self.textInput = newInput
9089
self.text = newInput.currentText
91-
print("changed Input")
9290
}
9391
}

Sources/SimpleKeyboard/Models/Language.swift

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,34 @@
77

88
import Foundation
99
public enum Language: CaseIterable {
10-
static func numbers(areUppercased: Bool) -> [String]{
11-
return areUppercased ? ["!", "?", ".", "%", "+", "-", "_", "=", "@", "#"] : ["1","2","3","4","5","6","7","8","9","0"]
10+
static func numbers(areUppercased: Bool) -> [String] {
11+
return areUppercased ? ["!", "?", ".", "%", "+", "-", "_", "=", "@", "#"] :
12+
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
1213
}
14+
1315
case english, german
14-
16+
1517
func rows(areUppercased: Bool) -> [[String]] {
16-
var r = [[String]]()
17-
switch self{
18+
var result = [[String]]()
19+
switch self {
1820
case .english:
19-
r = [["q","w","e","r","t","y","u","i","o","p"],["a","s","d","f","g","h","j","k","l"],["z","x","c","v","b","n","m"]]
21+
result = [
22+
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
23+
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
24+
["z", "x", "c", "v", "b", "n", "m"]
25+
]
2026
case .german:
21-
r = [["q","w","e","r","t","z","u","i","o","p"],["a","s","d","f","g","h","j","k","l"],["y","x","c","v","b","n","m"]]
27+
result = [
28+
["q", "w", "e", "r", "t", "z", "u", "i", "o", "p"],
29+
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
30+
["y", "x", "c", "v", "b", "n", "m"]
31+
]
2232
}
33+
2334
if areUppercased {
24-
r = r.map{ $0.map { $0.uppercased() } }
35+
result = result.map { $0.map { $0.uppercased() } }
2536
}
26-
return r
37+
38+
return result
2739
}
2840
}

Sources/SimpleKeyboard/Views/KeyButton.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import SwiftUI
99

1010
struct ShiftKeyButton: View {
1111
@Binding var isUpperCase: Bool!
12-
12+
1313
var body: some View {
1414
AnyView(Button(action: { self.isUpperCase?.toggle() }) { () -> AnyView in
15-
#if os(macOS)
16-
return AnyView(Text(isUpperCase! ? "Up": "lw"))
15+
#if !targetEnvironment(macCatalyst)
16+
return AnyView(Text(isUpperCase! ? "Up": "lw"/*, bundle: .module*/))
1717
#else
1818
return AnyView(Image(systemName: isUpperCase ? "shift.fill" : "shift").imageScale(.large))
1919
#endif
2020
})
21-
.foregroundColor(.primary)
21+
.foregroundColor(.primary)
2222
.font(Font.headline.weight(.semibold))
2323
.padding()
2424
.background(Color.gray.opacity(0.5))
@@ -29,8 +29,8 @@ struct ShiftKeyButton: View {
2929
struct KeyButton: View {
3030
@Binding var text: String
3131
var letter: String
32-
33-
var body: some View{
32+
33+
var body: some View {
3434
Button(action: { self.text.append(self.letter) }) {
3535
Text(letter)
3636
.foregroundColor(.primary)
@@ -45,10 +45,10 @@ struct KeyButton: View {
4545

4646
struct SpaceKeyButton: View {
4747
@Binding var text: String
48-
49-
var body: some View{
48+
49+
var body: some View {
5050
Button(action: { self.text.append(" ") }) {
51-
Text("space").padding().padding(.horizontal, 75)
51+
Text("space"/*, bundle: .module*/).padding().padding(.horizontal, 75)
5252
.foregroundColor(.primary)
5353
.background(Color.gray.opacity(0.5)).cornerRadius(7)
5454
}
@@ -57,20 +57,20 @@ struct SpaceKeyButton: View {
5757

5858
struct DeleteKeyButton: View {
5959
@Binding var text: String
60-
61-
var body: some View{
60+
61+
var body: some View {
6262
AnyView(Button(action: {
6363
guard !self.text.isEmpty else { return }
6464
_ = self.text.removeLast()
65-
}) { () -> AnyView in
66-
#if os(macOS)
65+
}) { () -> AnyView in
66+
#if !targetEnvironment(macCatalyst)
6767
return AnyView(Text(""))
6868
#else
6969
return AnyView(Image(systemName: "delete.left")
7070
.foregroundColor(.primary)
7171
.imageScale(.large)
7272
.font(Font.headline.weight(.semibold))
73-
.padding()
73+
.padding(10)
7474
.background(Color.gray.opacity(0.5)).cornerRadius(7))
7575
#endif
7676
})
@@ -79,9 +79,9 @@ struct DeleteKeyButton: View {
7979

8080
struct ActionKeyButton: View {
8181
@State var icon: Icon
82-
var action: ()->()
83-
84-
var body: some View{
82+
var action: () -> Void
83+
84+
var body: some View {
8585
Button(action: self.action) {
8686
icon.view.padding()
8787
.foregroundColor(.white)
@@ -92,17 +92,17 @@ struct ActionKeyButton: View {
9292

9393
enum Icon {
9494
case done, search, go
95-
96-
var view: some View{
97-
switch self{
98-
case .done: return AnyView(Text("Done!"))
95+
96+
var view: some View {
97+
switch self {
98+
case .done: return AnyView(Text("Done!"/* , bundle: .module*/))
9999
case .search:
100-
#if os(macOS)
101-
return AnyView(Text("Search"))
100+
#if !targetEnvironment(macCatalyst)
101+
return AnyView(Text("Search"/*, bundle: .module*/))
102102
#else
103103
return AnyView(Image(systemName: "magnifyingglass"))
104104
#endif
105-
case .go: return AnyView(Text("Go!"))
105+
case .go: return AnyView(Text("Go!"/*, bundle: .module*/))
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)