AutocompleteManagerDelegate.swift 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // AutocompleteManagerDelegate.swift
  3. // InputBarAccessoryView
  4. //
  5. // Copyright © 2017-2019 Nathan Tannar.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in all
  15. // copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. // SOFTWARE.
  24. //
  25. // Created by Nathan Tannar on 10/4/17.
  26. //
  27. import UIKit
  28. /// AutocompleteManagerDelegate is a protocol that more precisely define AutocompleteManager logic
  29. public protocol AutocompleteManagerDelegate: AnyObject {
  30. /// Can be used to determine if the AutocompleteManager should be inserted into an InputStackView
  31. ///
  32. /// - Parameters:
  33. /// - manager: The AutocompleteManager
  34. /// - shouldBecomeVisible: If the AutocompleteManager should be presented or dismissed
  35. func autocompleteManager(_ manager: AutocompleteManager, shouldBecomeVisible: Bool)
  36. /// Determines if a prefix character should be registered to initialize the auto-complete selection table
  37. ///
  38. /// - Parameters:
  39. /// - manager: The AutocompleteManager
  40. /// - prefix: The prefix `Character` could be registered
  41. /// - range: The `NSRange` of the prefix in the UITextView managed by the AutocompleteManager
  42. /// - Returns: If the prefix should be registered. Default is TRUE
  43. func autocompleteManager(_ manager: AutocompleteManager, shouldRegister prefix: String, at range: NSRange) -> Bool
  44. /// Determines if a prefix character should be unregistered to de-initialize the auto-complete selection table
  45. ///
  46. /// - Parameters:
  47. /// - manager: The AutocompleteManager
  48. /// - prefix: The prefix character could be unregistered
  49. /// - range: The range of the prefix in the UITextView managed by the AutocompleteManager
  50. /// - Returns: If the prefix should be unregistered. Default is TRUE
  51. func autocompleteManager(_ manager: AutocompleteManager, shouldUnregister prefix: String) -> Bool
  52. /// Determines if a prefix character can should be autocompleted
  53. ///
  54. /// - Parameters:
  55. /// - manager: The AutocompleteManager
  56. /// - prefix: The prefix character that is currently registered
  57. /// - text: The text to autocomplete with
  58. /// - Returns: If the prefix can be autocompleted. Default is TRUE
  59. func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool
  60. }
  61. public extension AutocompleteManagerDelegate {
  62. func autocompleteManager(_ manager: AutocompleteManager, shouldRegister prefix: String, at range: NSRange) -> Bool {
  63. return true
  64. }
  65. func autocompleteManager(_ manager: AutocompleteManager, shouldUnregister prefix: String) -> Bool {
  66. return true
  67. }
  68. func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool {
  69. return true
  70. }
  71. }