ChatInputBar.swift 934 B

1234567891011121314151617181920212223242526272829303132
  1. import UIKit
  2. import InputBarAccessoryView
  3. public class ChatInputBar: InputBarAccessoryView {
  4. var hasDraft: Bool = false
  5. var hasQuote: Bool = false
  6. override open func calculateMaxTextViewHeight() -> CGFloat {
  7. let divisor: CGFloat = traitCollection.verticalSizeClass == .regular ? 3 : 5
  8. var subtract: CGFloat = 0
  9. subtract += hasDraft ? 90 : 0
  10. subtract += hasQuote ? 90 : 0
  11. let height = (UIScreen.main.bounds.height / divisor).rounded(.down) - subtract
  12. if height < 40 {
  13. return 40
  14. }
  15. return height
  16. }
  17. public func configure(draft: DraftModel) {
  18. hasDraft = draft.draftAttachment != nil
  19. hasQuote = draft.quoteText != nil
  20. maxTextViewHeight = calculateMaxTextViewHeight()
  21. }
  22. public func cancel() {
  23. hasDraft = false
  24. hasQuote = false
  25. maxTextViewHeight = calculateMaxTextViewHeight()
  26. }
  27. }