Skip to content

Commit 903df92

Browse files
committed
v1.0
1 parent 5888aa4 commit 903df92

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.swiftpm/
33
Example/AccessoryKit.xcodeproj/xcuserdata/
44
Example/AccessoryKit.xcworkspace/xcuserdata
5-
Example/Pods/Pods.xcodeproj/xcuserdata
5+
Example/Pods/Pods.xcodeproj/xcuserdata
6+
.build

README.md

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A customizable, expandable, and easy-to-use input accessory view component for i
1414

1515
The main features are:
1616

17+
* Responsively uses `UITextInputAssistantItem` on iPad and `UITextInputView` on iPhone.
1718
* Scrollable input accessory view with blurry background and customizable buttons.
1819
* Supports Auto Layout and Safe Area.
1920
* Supports dark mode.
@@ -24,8 +25,8 @@ The main features are:
2425

2526
### Requirements
2627

27-
* iOS 13.0+
28-
* Swift 5.3+
28+
* iOS 14.0+
29+
* Swift 5.5+
2930

3031
### Installation
3132

@@ -44,48 +45,29 @@ To run the example project, clone the repo, and run `pod install` from the Examp
4445
```swift
4546
// Create view model array of key buttons
4647
let keyButtons: [KeyboardAccessoryButton] = [
47-
// Create button with built-in type and tap handler block
48-
KeyboardAccessoryButton(type: .undo) { [weak self] in
48+
// Create button with built-in type and tap handler block that will be placed on
49+
// the leading side of keyboard on iPad
50+
KeyboardAccessoryButton(type: .undo, position: .leading) { [weak self] in
4951
self?.undo()
5052
},
51-
// Create button with UIImage
52-
KeyboardAccessoryButton(image: UIImage(named: "img"), tapHandler: {}),
53+
// Create button with UIImage that will be collapsed in an overflow menu on iPad
54+
KeyboardAccessoryButton(image: UIImage(named: "img"), position: .overflow),
5355
// Create button with title
54-
KeyboardAccessoryButton(title: "Button", tapHandler: {}),
56+
KeyboardAccessoryButton(title: "Button",
5557
// Create button with UIMenu
5658
KeyboardAccessoryButton(type: .link, menu: createInsertMenu()),
5759
]
5860

59-
// Initialize `KeyboardAccessoryView`
60-
let accessoryView = KeyboardAccessoryView(
61-
frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 0),
61+
// Initialize and retain `KeyboardAccessoryManager`
62+
self.accessoryManager = KeyboardAccessoryView(
6263
keyButtons: keyButtons,
6364
showDismissKeyboardKey: true,
6465
delegate: self)
6566

66-
// Assign the accessory view instance to `UITextView`
67-
textView.inputAccessoryView = accessoryView
68-
69-
// Set tint color for the whole view
70-
accessoryView.tintColor = .systemPink
71-
// ...or at a given index
72-
accessoryView.setTintColor(.systemGreen, at: 5)
73-
74-
// Set enabled at a given index
75-
accessoryView.setEnabled(false, at: 1)
67+
// Configures the `UITextView` with `KeyboardAccessoryManager`
68+
self.accessoryManager.configure(textView: textView)
7669
```
7770

78-
## TODO
79-
80-
- [x] Support text title
81-
- [ ] Expose more APIs for customization
82-
- [x] Tint color
83-
- [ ] Tweak UI
84-
- [x] Use SF Symbol
85-
- [x] UIMenu support
86-
- [ ] UIAction support
87-
- [x] SPM support
88-
8971
## License
9072

9173
AccessoryKit is available under the MIT license. See the [LICENSE](LICENSE) file for more info.

Sources/AccessoryKit/KeyboardAccessoryManager.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public class KeyboardAccessoryManager {
2626

2727
// MARK: - Initializer
2828

29+
/// Initializes an instance of `KeyboardAccessoryManager`.
30+
/// - Parameters:
31+
/// - keyButtons: An array of `KeyboardAccessoryButton` model to construct the keys.
32+
/// - keyWidth: The width of each key inside input accessory view.
33+
/// - keyHeight: The height of each key inside input accessory view.
34+
/// - keyCornerRadius: The corner radius of each key inside input accessory view.
35+
/// - keyMargin: The margin between keys inside input accessory view.
36+
/// - showDismissKeyboardKey: If show the dismiss keyboard key on the right of scrollable area.
37+
/// - delegate: Delegate object that implements `KeyboardAccessoryViewDelegate`.
2938
public init(keyButtons: [KeyboardAccessoryButton] = [],
3039
keyWidth: CGFloat = KeyboardAccessoryView.defaultKeyWidth,
3140
keyHeight: CGFloat = KeyboardAccessoryView.defaultKeyHeight,
@@ -44,6 +53,10 @@ public class KeyboardAccessoryManager {
4453

4554
// MARK: - Public APIs
4655

56+
/// Configures a `UITextView` with accessory manager instance. Uses `UITextInputView` on iPhone
57+
/// (a toolbar above virtual keyboard) and `UITextInputAssistantItem` on iPad (embedded inside
58+
/// the floating keyboard toolbar).
59+
/// - Parameter textView: The text view instance to be configured.
4760
public func configure(textView: UITextView) {
4861
if Self.isIPad {
4962
configure(inputAssistantItem: textView.inputAssistantItem)
@@ -52,6 +65,8 @@ public class KeyboardAccessoryManager {
5265
}
5366
}
5467

68+
/// Creates an instance of toolbar view that can be assigned to the text view's `inputAccessoryView`.
69+
/// - Returns: The keyboard accessory view instance.
5570
public func makeInputView() -> KeyboardAccessoryView {
5671
return KeyboardAccessoryView(
5772
keyWidth: keyWidth,
@@ -63,6 +78,8 @@ public class KeyboardAccessoryManager {
6378
delegate: delegate)
6479
}
6580

81+
/// Configures the `UITextInputAssistantItem` with given accessory manager.
82+
/// - Parameter inputAssistantItem: The `UITextInputAssistantItem` to be configured.
6683
public func configure(inputAssistantItem: UITextInputAssistantItem) {
6784
var leadingButtons: [UIBarButtonItem] = []
6885
var trailingButtons: [UIBarButtonItem] = []

0 commit comments

Comments
 (0)