Skip to content

Commit

Permalink
support UIMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
xnth97 committed Jan 13, 2021
1 parent 8deab3e commit 20b8477
Show file tree
Hide file tree
Showing 18 changed files with 346 additions and 308 deletions.
24 changes: 23 additions & 1 deletion Example/AccessoryKit/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ViewController: UIViewController {
KeyboardAccessoryButton(type: .delete, tapHandler: {}),
KeyboardAccessoryButton(type: .item, tapHandler: {}),
KeyboardAccessoryButton(type: .quote, tapHandler: {}),
KeyboardAccessoryButton(type: .link, tapHandler: {}),
KeyboardAccessoryButton(type: .link, menu: createInsertMenu()),
KeyboardAccessoryButton(type: .image, tapHandler: {}),
]
accessoryView = KeyboardAccessoryView(
Expand Down Expand Up @@ -73,6 +73,28 @@ class ViewController: UIViewController {
accessoryView.setEnabled(textView.undoManager?.canRedo ?? false, at: 2)
}

private func createInsertMenu() -> UIMenu {
return UIMenu(
title: "",
image: nil,
identifier: nil,
options: .displayInline,
children: [
UIAction(
title: "Insert link",
image: UIImage(systemName: "link"),
handler: { _ in }),
UIAction(
title: "Insert image",
image: UIImage(systemName: "photo"),
handler: { _ in }),
UIAction(
title: "Insert math formula",
image: UIImage(systemName: "function"),
handler: { _ in }),
])
}

}

extension ViewController: KeyboardAccessoryViewDelegate {
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- AccessoryKit (0.5.0)
- AccessoryKit (0.5.2)

DEPENDENCIES:
- AccessoryKit (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
AccessoryKit: 67e36b8d959f148e8fa3fe424137acbefe16bb9b
AccessoryKit: 9bf5430dd96b6554119e3643e3134e5ab5e85f22

PODFILE CHECKSUM: 71ba08049996c0cee05530889ad335543ac96aac

COCOAPODS: 1.9.3
COCOAPODS: 1.10.1
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/AccessoryKit.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

426 changes: 212 additions & 214 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The main features are:
* Supports Auto Layout and Safe Area.
* Supports dark mode.
* Provides built-in pre-defined buttons with SF Symbol.
* Supports presenting `UIMenu` on input accessory view.

## Usage

Expand All @@ -43,10 +44,14 @@ To run the example project, clone the repo, and run `pod install` from the Examp
```swift
// Create view model array of key buttons
let keyButtons: [KeyboardAccessoryButton] = [
// Create button with built-in type and tap handler block
KeyboardAccessoryButton(type: .undo, tapHandler: { [weak self] in
self?.undo()
}),
// Create button with UIImage
KeyboardAccessoryButton(image: UIImage(named: "img"), tapHandler: {}),
// Create button with UIMenu
KeyboardAccessoryButton(type: .link, menu: createInsertMenu()),
]

// Initialize `KeyboardAccessoryView`
Expand All @@ -70,10 +75,12 @@ accessoryView.setEnabled(false, at: 1)

## TODO

- [ ] Expose more APIs customization
- [ ] Expose more APIs for customization
- [x] Tint color
- [ ] Tweak UI
- [x] Use SF Symbol
- [x] UIMenu support
- [ ] UIAction support
- [x] SPM support

## License
Expand Down
Binary file modified Screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 20b8477

Please sign in to comment.