MessageInputBar

open class MessageInputBar: UIView

A powerful InputAccessoryView ideal for messaging applications

  • A delegate to broadcast notifications from the MessageInputBar

    Declaration

    Swift

    open weak var delegate: MessageInputBarDelegate?
  • The background UIView anchored to the bottom, left, and right of the MessageInputBar with a top anchor equal to the bottom of the top InputStackView

    Declaration

    Swift

    open var backgroundView: UIView =
  • A content UIView that holds the left/right/bottom InputStackViews and InputTextView. Anchored to the bottom of the topStackView and inset by the padding UIEdgeInsets

    Declaration

    Swift

    open var contentView: UIView =
  • A UIVisualEffectView that adds a blur effect to make the view appear transparent.

    Important Notes

    1. The blurView is initially not added to the backgroundView to improve performance when not needed. When isTranslucent is set to TRUE for the first time the blurView is added and anchored to the backgroundViews edge anchors

    Declaration

    Swift

    open var blurView: UIVisualEffectView =
  • Determines if the MessageInputBar should have a translucent effect

    Declaration

    Swift

    open var isTranslucent: Bool = false
  • A SeparatorLine that is anchored at the top of the MessageInputBar with a height of 1

    Declaration

    Swift

    open let separatorLine = SeparatorLine()
  • The InputStackView at the InputStackView.top position

    Important Notes

    1. It’s axis is initially set to .vertical
    2. It’s alignment is initially set to .fill

    Declaration

    Swift

    open let topStackView: InputStackView =
  • The InputStackView at the InputStackView.left position

    Important Notes

    1. It’s axis is initially set to .horizontal

    Declaration

    Swift

    open let leftStackView = InputStackView(axis: .horizontal, spacing: 0)
  • The InputStackView at the InputStackView.right position

    Important Notes

    1. It’s axis is initially set to .horizontal

    Declaration

    Swift

    open let rightStackView = InputStackView(axis: .horizontal, spacing: 0)
  • The InputStackView at the InputStackView.bottom position

    Important Notes

    1. It’s axis is initially set to .horizontal
    2. It’s spacing is initially set to 15

    Declaration

    Swift

    open let bottomStackView = InputStackView(axis: .horizontal, spacing: 15)
  • The InputTextView a user can input a message in

    Declaration

    Swift

    open lazy var inputTextView: InputTextView =
  • A InputBarButtonItem used as the send button and initially placed in the rightStackView

    Declaration

    Swift

    open var sendButton: InputBarButtonItem =
  • A boolean that determines whether the sendButton’s isEnabled state should be managed automatically.

    Declaration

    Swift

    open var shouldManageSendButtonEnabledState = true
  • The anchor constants that inset the contentView

    V:|...[InputStackView.top]-(padding.top)-[contentView]-(padding.bottom)-|
    
    H:|-(padding.left)-[contentView]-(padding.right)-|
    

    Declaration

    Swift

    open var padding: UIEdgeInsets = UIEdgeInsets(top: 6, left: 12, bottom: 6, right: 12)
  • The anchor constants used by the top InputStackView

    Important Notes

    1. The topStackViewPadding.bottom property is not used. Use padding.top to add separation
    V:|-(topStackViewPadding.top)-[InputStackView.top]-(padding.top)-[InputTextView]-...|
    
    H:|-(topStackViewPadding.left)-[InputStackView.top]-(topStackViewPadding.right)-|
    

    Declaration

    Swift

    open var topStackViewPadding: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  • The anchor constants used by the InputStackView

    V:|...-(padding.top)-(textViewPadding.top)-[InputTextView]-(textViewPadding.bottom)-[InputStackView.bottom]-...|
    
    H:|...-[InputStackView.left]-(textViewPadding.left)-[InputTextView]-(textViewPadding.right)-[InputStackView.right]-...|
    

    Declaration

    Swift

    open var textViewPadding: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)
  • Returns the most recent size calculated by calculateIntrinsicContentSize()

    Declaration

    Swift

    open override var intrinsicContentSize: CGSize
  • The intrinsicContentSize can change a lot so the delegate method inputBar(self, didChangeIntrinsicContentTo: size) only needs to be called when it’s different

    Declaration

    Swift

    public private(set) var previousIntrinsicContentSize: CGSize?
  • A boolean that indicates if the maxTextViewHeight has been met. Keeping track of this improves the performance

    Declaration

    Swift

    public private(set) var isOverMaxTextViewHeight = false
  • A boolean that determines if the maxTextViewHeight should be auto updated on device rotation

    Declaration

    Swift

    open var shouldAutoUpdateMaxTextViewHeight = true
  • The maximum height that the InputTextView can reach

    Declaration

    Swift

    open var maxTextViewHeight: CGFloat = 0
  • The height that will fit the current text in the InputTextView based on its current bounds

    Declaration

    Swift

    public var requiredInputTextViewHeight: CGFloat
  • The fixed widthAnchor constant of the leftStackView

    Declaration

    Swift

    public private(set) var leftStackViewWidthConstant: CGFloat = 0
  • The fixed widthAnchor constant of the rightStackView

    Declaration

    Swift

    public private(set) var rightStackViewWidthConstant: CGFloat = 52
  • The InputBarItems held in the leftStackView

    Declaration

    Swift

    public private(set) var leftStackViewItems: [InputBarButtonItem] = []
  • The InputBarItems held in the rightStackView

    Declaration

    Swift

    public private(set) var rightStackViewItems: [InputBarButtonItem] = []
  • The InputBarItems held in the bottomStackView

    Declaration

    Swift

    public private(set) var bottomStackViewItems: [InputBarButtonItem] = []
  • The InputBarItems held in the topStackView

    Declaration

    Swift

    public private(set) var topStackViewItems: [InputBarButtonItem] = []
  • The InputBarItems held to make use of their hooks but they are not automatically added to a UIStackView

    Declaration

    Swift

    open var nonStackViewItems: [InputBarButtonItem] = []
  • Returns a flatMap of all the items in each of the UIStackViews

    Declaration

    Swift

    public var items: [InputBarButtonItem]
  • Undocumented

    Declaration

    Swift

    public convenience init()
  • Undocumented

    Declaration

    Swift

    public override init(frame: CGRect)
  • Undocumented

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)
  • Undocumented

    Declaration

    Swift

    open override func didMoveToWindow()
  • Sets up the default properties

    Declaration

    Swift

    open func setup()
  • Calculates the correct intrinsicContentSize of the MessageInputBar. This takes into account the various padding edge insets, InputTextView’s height and top/bottom InputStackView’s heights.

    Declaration

    Swift

    open func calculateIntrinsicContentSize() -> CGSize

    Return Value

    The required intrinsicContentSize

  • Returns the max height the InputTextView can grow to based on the UIScreen

    Declaration

    Swift

    open func calculateMaxTextViewHeight() -> CGFloat

    Return Value

    Max Height

  • Layout the given InputStackView’s

    Declaration

    Swift

    public func layoutStackViews(_ positions: [InputStackView.Position] = [.left, .right, .bottom, .top])

    Parameters

    positions

    The UIStackView’s to layout

  • Removes all of the arranged subviews from the UIStackView and adds the given items. Sets the messageInputBar property of the InputBarButtonItem

    Declaration

    Swift

    open func setStackViewItems(_ items: [InputBarButtonItem], forStack position: InputStackView.Position, animated: Bool)

    Parameters

    items

    New UIStackView arranged views

    position

    The targeted UIStackView

    animated

    If the layout should be animated

  • Sets the leftStackViewWidthConstant

    Declaration

    Swift

    open func setLeftStackViewWidthConstant(to newValue: CGFloat, animated: Bool)

    Parameters

    newValue

    New widthAnchor constant

    animated

    If the layout should be animated

  • Sets the rightStackViewWidthConstant

    Declaration

    Swift

    open func setRightStackViewWidthConstant(to newValue: CGFloat, animated: Bool)

    Parameters

    newValue

    New widthAnchor constant

    animated

    If the layout should be animated

  • Invalidates the intrinsicContentSize

    Declaration

    Swift

    open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?)
  • Enables/Disables the sendButton based on the InputTextView’s text being empty Calls each items textViewDidChangeAction method Calls the delegates textViewTextDidChangeTo method Invalidates the intrinsicContentSize

    Declaration

    Swift

    open func textViewDidChange()
  • Calls each items keyboardEditingBeginsAction method Invalidates the intrinsicContentSize so that the keyboard does not overlap the view

    Declaration

    Swift

    open func textViewDidBeginEditing()
  • Calls each items keyboardEditingEndsAction method

    Declaration

    Swift

    open func textViewDidEndEditing()
  • Calls the delegates didPressSendButtonWith method Assumes that the InputTextView’s text has been set to empty and calls inputTextViewDidChange() Invalidates each of the inputManagers

    Declaration

    Swift

    open func didSelectSendButton()