Skip to content

Commit 7964767

Browse files
committed
Add a new join primary button type
1 parent 4645f7d commit 7964767

File tree

6 files changed

+130
-36
lines changed

6 files changed

+130
-36
lines changed

Demo/Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
"version": null
4747
}
4848
},
49+
{
50+
"package": "SwiftDocCPlugin",
51+
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
52+
"state": {
53+
"branch": null,
54+
"revision": "3303b164430d9a7055ba484c8ead67a52f7b74f6",
55+
"version": "1.0.0"
56+
}
57+
},
4958
{
5059
"package": "SwiftUIKit",
5160
"repositoryURL": "https://github.com/danielsaidi/SwiftUIKit",

RELEASE_NOTES.md

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Breaking changes can still occur in minor versions and patches, though, if the a
1010

1111

1212

13+
## 6.0.3
14+
15+
This version adds more primary button types.
16+
17+
### ✨ New Features
18+
19+
* `KeyboardAction.PrimaryType` has new `join` and `custom` cases.
20+
* `KeyboardAction.PrimaryType` now maps unrepresented `UIReturnKeyType` types to the new `custom` type.
21+
22+
23+
24+
1325
## 6.0.2
1426

1527
This version fixes bugs in the Kurdish Sorani keyboard.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// KeyboardAction+PrimaryType.swift
3+
// KeyboardKit
4+
//
5+
// Created by Daniel Saidi on 202-06-23.
6+
// Copyright © 2022 Daniel Saidi. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
public extension KeyboardAction {
12+
13+
/**
14+
This enum can be used together with ``primary(_:)``.
15+
16+
Primary buttons are color accented buttons that trigger
17+
a submit action in the keyboard, just like ``return``.
18+
*/
19+
enum PrimaryType: CaseIterable, Codable, Equatable, Identifiable {
20+
21+
/// A done key used in e.g. Calendar add location.
22+
case done
23+
24+
/// A go key used in e.g. the Safari address bar.
25+
case go
26+
27+
/// A join key used when e.g. joining a wifi network.
28+
case join
29+
30+
/// A new line key used to force using a line arrow.
31+
case newLine
32+
33+
/// An ok key, which isn't actually used in native.
34+
case ok
35+
36+
/// A "search" key used in e.g. web search.
37+
case search
38+
39+
/// A custom key with a custom title.
40+
case custom(title: String)
41+
42+
/**
43+
The type's unique identifier.
44+
*/
45+
public var id: String {
46+
switch self {
47+
case .done: return "done"
48+
case .go: return "go"
49+
case .join: return "join"
50+
case .newLine: return "newLine"
51+
case .ok: return "ok"
52+
case .search: return "search"
53+
case .custom(let title): return title
54+
}
55+
}
56+
57+
/**
58+
All unique primary button types, excluding custom.
59+
*/
60+
public static var allCases: [KeyboardAction.PrimaryType] {
61+
return [.done, .go, .join, .newLine, .ok, .search]
62+
}
63+
64+
#if canImport(UIKit)
65+
public static func type(for nativeType: UIReturnKeyType) -> PrimaryType {
66+
switch nativeType {
67+
case .default: return .ok
68+
case .go: return .go
69+
case .google: return .custom(title: "Google")
70+
case .join: return .join
71+
case .next: return .custom(title: "next")
72+
case .route: return .custom(title: "route")
73+
case .search: return .search
74+
case .send: return .custom(title: "send")
75+
case .yahoo: return .custom(title: "Google")
76+
case .done: return .done
77+
case .emergencyCall: return .custom(title: "emergencyCall")
78+
case .continue: return .custom(title: "continue")
79+
@unknown default: return .custom(title: "unknown")
80+
}
81+
}
82+
#endif
83+
}
84+
}
85+
86+
public extension KeyboardAction.PrimaryType {
87+
88+
func standardButtonImage(for locale: Locale) -> Image? {
89+
switch self {
90+
case .newLine: return .keyboardNewline(for: locale)
91+
default: return nil
92+
}
93+
}
94+
95+
func standardButtonText(for locale: Locale) -> String? {
96+
switch self {
97+
case .custom(let title): return title
98+
case .done: return KKL10n.done.text(for: locale)
99+
case .go: return KKL10n.go.text(for: locale)
100+
case .join: return "join" // TODO: Localize
101+
case .newLine: return nil
102+
case .ok: return KKL10n.ok.text(for: locale)
103+
case .search: return KKL10n.search.text(for: locale)
104+
}
105+
}
106+
}

Sources/KeyboardKit/Actions/KeyboardAction.swift

-16
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,6 @@ public enum KeyboardAction: Codable, Equatable {
120120

121121
public extension KeyboardAction {
122122

123-
/**
124-
This enum can be used together with ``primary(_:)``.
125-
126-
Primary buttons are color accented buttons that trigger
127-
a submit action in the keyboard, just like ``return``.
128-
*/
129-
enum PrimaryType: String, CaseIterable, Codable, Equatable, Identifiable {
130-
131-
case done, go, newLine, ok, search
132-
133-
/**
134-
The type's unique identifier.
135-
*/
136-
public var id: String { rawValue }
137-
}
138-
139123
/**
140124
Whether or not the action is a character action.
141125

Sources/KeyboardKit/Appearance/KeyboardAction+Button.swift

-20
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,3 @@ private extension KeyboardAction {
7777
}
7878
}
7979
}
80-
81-
private extension KeyboardAction.PrimaryType {
82-
83-
func standardButtonImage(for locale: Locale) -> Image? {
84-
switch self {
85-
case .newLine: return .keyboardNewline(for: locale)
86-
default: return nil
87-
}
88-
}
89-
90-
func standardButtonText(for locale: Locale) -> String? {
91-
switch self {
92-
case .done: return KKL10n.done.text(for: locale)
93-
case .go: return KKL10n.go.text(for: locale)
94-
case .newLine: return nil
95-
case .ok: return KKL10n.ok.text(for: locale)
96-
case .search: return KKL10n.search.text(for: locale)
97-
}
98-
}
99-
}

Sources/KeyboardKit/Gestures/KeyboardGestures.swift

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ private extension KeyboardGestures {
138138

139139
/**
140140
This is a drag gesture that starts after a long press.
141+
142+
This gesture is used to present and dismiss the callout
143+
that presents secondary actions.
141144
*/
142145
func longPressDragGesture(for geo: GeometryProxy) -> some Gesture {
143146
LongPressGesture()

0 commit comments

Comments
 (0)