@@ -22,6 +22,7 @@ public class KeyboardAccessoryManager {
2222 private let keyHeight : CGFloat
2323 private let keyCornerRadius : CGFloat
2424 private let showDismissKeyboardKey : Bool
25+ private let preferInputAssistantItem : Bool
2526
2627 private weak var delegate : KeyboardAccessoryViewDelegate ?
2728 private var identifiedActionItems : [ String : Any ] = [ : ]
@@ -36,20 +37,23 @@ public class KeyboardAccessoryManager {
3637 /// - keyCornerRadius: The corner radius of each key inside input accessory view.
3738 /// - keyMargin: The margin between keys inside input accessory view.
3839 /// - showDismissKeyboardKey: If show the dismiss keyboard key on the right of scrollable area.
40+ /// - preferInputAssistantItem: Prefer `UITextInputAssistantItem` on iPads.
3941 /// - delegate: Delegate object that implements `KeyboardAccessoryViewDelegate`.
4042 public init ( keyButtonGroups: [ KeyboardAccessoryButtonGroup ] = [ ] ,
4143 keyWidth: CGFloat = KeyboardAccessoryView . defaultKeyWidth,
4244 keyHeight: CGFloat = KeyboardAccessoryView . defaultKeyHeight,
4345 keyCornerRadius: CGFloat = KeyboardAccessoryView . defaultKeyCornerRadius,
4446 keyMargin: CGFloat = KeyboardAccessoryView . defaultKeyMargin,
4547 showDismissKeyboardKey: Bool = true ,
48+ preferInputAssistantItem: Bool = true ,
4649 delegate: KeyboardAccessoryViewDelegate ? = nil ) {
4750 self . keyButtonGroups = keyButtonGroups
4851 self . keyMargin = keyMargin
4952 self . keyWidth = keyWidth
5053 self . keyHeight = keyHeight
5154 self . keyCornerRadius = keyCornerRadius
5255 self . showDismissKeyboardKey = showDismissKeyboardKey
56+ self . preferInputAssistantItem = preferInputAssistantItem
5357 self . delegate = delegate
5458 }
5559
@@ -60,7 +64,7 @@ public class KeyboardAccessoryManager {
6064 /// the floating keyboard toolbar).
6165 /// - Parameter textView: The text view instance to be configured.
6266 public func configure( textView: UITextView ) {
63- if Self . isIPad {
67+ if canUseInputAssistantItem {
6468 configure ( inputAssistantItem: textView. inputAssistantItem)
6569 } else {
6670 textView. inputAccessoryView = inputAccessoryView
@@ -72,7 +76,7 @@ public class KeyboardAccessoryManager {
7276 /// the floating keyboard toolbar).
7377 /// - Parameter textField: The text field instance to be cofigured.
7478 public func configure( textField: UITextField ) {
75- if Self . isIPad {
79+ if canUseInputAssistantItem {
7680 configure ( inputAssistantItem: textField. inputAssistantItem)
7781 } else {
7882 textField. inputAccessoryView = inputAccessoryView
@@ -181,7 +185,7 @@ public class KeyboardAccessoryManager {
181185 /// - enabled: Boolean value indicating whether the key is enabled.
182186 /// - identifier: Identifier of menu item.
183187 public func setEnabled( _ enabled: Bool , for identifier: String ) {
184- if Self . isIPad {
188+ if canUseInputAssistantItem {
185189 if let item = identifiedActionItems [ identifier] {
186190 switch item {
187191 case is UIAction :
@@ -212,4 +216,8 @@ public class KeyboardAccessoryManager {
212216 return UIDevice . current. userInterfaceIdiom == . pad
213217 }
214218
219+ private var canUseInputAssistantItem : Bool {
220+ preferInputAssistantItem && Self . isIPad
221+ }
222+
215223}
0 commit comments