A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
Clone or download
Latest commit 8eb0665 Sep 29, 2018

README.md

InputBarAccessoryView

CocoaPods Donate

Features

  • A growing UITextView with optional fixed height
  • Image paste support
  • RxSwift inspired reactive components that respond to given events
  • Top/Bottom/Left/Right UIStackViews that act as toolbars to place buttons
  • Drop in autocomplete for any given prefix
  • Autocomplete attributed text highlighting
  • Drop in attachment view for file/photo management
  • Plugin support for your own InputPlugins
  • iPhone X/Xs/Xs Max/Xr Support
  • RTL Support

See Also

iMessage style TypingIndicator for chat apps

Installation via CocoaPods

pod 'InputBarAccessoryView'

Installation via Carthage

github "nathantannar4/InputBarAccessoryView"

Requirements

iOS 9.0+ Swift 4+ XCode 9.0+

Only use release 4.0.0+ for Swift 4.2 and above

Documentation

Getting Started

See the Example project to see how you can make the iMessage, Slack, Facebook and GitHawk input bars!

Demo

Screenshots

Featured In

Add your app to the list of apps using this library and make a pull request.

Layout

The layout of the InputBarAccessoryView is made of of 4 InputStackView's and an InputTextView. The padding of the subviews can be easily adjusted by changing the padding and textViewPadding properties. The constraints will automatically be updated.

It is important to note that each of the InputStackView's to the left and right of the InputTextView are anchored by a width constraint. This way the InputTextView will always fill the space inbetween in addition to providing methods that can easily be called to hide all buttons to the right or left of the InputTextView by setting the width constraint constant to 0. The bottom and top stack views are not height constraint and rely on their intrinsicContentSize

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

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

Reactive Hooks

Each InputBarButtonItem has properties that can hold actions that will be executed during various hooks such as the button being touched, the UITextViewtext changing and more! Thanks to these easy hooks with a few lines of code the items can be easily resized and animated similar to that of the Facebook messenger app.

// MARK: - Hooks
    
public typealias InputBarButtonItemAction = ((InputBarButtonItem) -> Void)    
    
private var onTouchUpInsideAction: InputBarButtonItemAction?
private var onKeyboardEditingBeginsAction: InputBarButtonItemAction?
private var onKeyboardEditingEndsAction: InputBarButtonItemAction?
private var onKeyboardSwipeGestureAction: ((InputBarButtonItem, UISwipeGestureRecognizer) -> Void)?
private var onTextViewDidChangeAction: ((InputBarButtonItem, InputTextView) -> Void)?
private var onSelectedAction: InputBarButtonItemAction?
private var onDeselectedAction: InputBarButtonItemAction?
private var onEnabledAction: InputBarButtonItemAction?
private var onDisabledAction: InputBarButtonItemAction?

Changelog

  • 4.0.3 - Fix issue where native autocomplete in interfears with AutocompleteManager
  • 4.0.2 - Fix layout issue effecting older devices when pasting large amounts of text
  • 4.0.1 - Fix window constraint for iPhone Xs, Xs Max and XR
  • 4.0.0 - Update to Swift 4.2
  • 3.1.0 - Added functionality to register(delimiterSet set: CharacterSet) and unregister(delimiterSet set: CharacterSet), these sets are used to terminate an AutocompleteSession - Added maxSpaceCountDuringCompletion to allow for autocomplete strings that have spaces, such as "@Nathan Tannar"
  • 3.0.1 - Inserting text in the middle an autocompleted substring will now invalidate the autocomplete - Deleting characters in the middle of an autocompleted substring will delete the entire autocompleted substring
  • 3.0.0 - Added a context: [String: Any]? property to AutocompleteCompletion for more advanced use - Added NSAttributedString.Key.autocompleted to easily parse attributed strings for the substrings that were completed - Added NSAttributedString.Key.autocompletedContext where the context of AutocompleteCompletion is stored for post processing
  • 2.2.2 - Removed experimental TypingIndicator see more refined version here - Added a KeyboardManager to support adding an InputBarAccessoryView as a subview of a UIViewController. This better supports view controller containers such as the UISplitViewController
  • 2.2.1 - RTL Support (Made AutocompleteManager.paragraphStyle open)
  • 2.2.0 - Make AutocompleteSession a class so that its completion can be updated
  • 2.1.0 - AutocompleteManager table view datasource methods are now marked as open - AutocompleteManager changed to manage UITextViews rather than only InputTextViews - AutocompleteSession bug fixes - Example updated for asynchronous completion lookups with AutocompleteManager
  • 2.0.0 - API Stability - Bug Fixes - InputManager renamed to InputPlugin - Added shouldManageSendButtonEnabledState to InputBarAccessoryView
  • 1.5.4 - Bug Fixes
  • 1.5.3 - [WIP] TypingIndicator InputItem view added, see example - shouldForceTextViewMaxHeight property added
  • 1.5.2 - Better autocomplete detection
  • 1.5.1 - Optimize AutocompleteManager & AttachmentManager
  • 1.5.0 - Stability and bug fixes
  • 1.4.0 - iPhone X Fixes - IntrinsicContentSize caching to increase performance - Auto Manage maxTextViewHeight
  • 1.3.0 - iPhone X Fixes
  • 1.2.0 - Better XCode docs - InputItem is now a protocol that you can give to the InputBarAccessoryView - InputPlugin is now a protocol that you can conform to make a plugin - AutocompleteManager and AttactchmentManager are no longer members of InputBarAccessoryView by default. You will need to create them and assign them to the InputPlugin property of the InputBarAccessoryView
  • 1.1.2 - Fixed issue where adjusting the InputTextView's placeholder text alignment didn't work - Fixed iPhone X support where the home indicator overlapped the InputTextView
  • 1.1.1 - AutocompleteManager bug fixes and customization improvements
  • 1.1.0 - AttactchmentManager (Beta)
  • 1.0.0
    • A more refined AutocompleteManager
    • Auto-layout bug fixes

pre-release versions not documented

Find a bug? Open an issue!

Author

Nathan Tannar - https://nathantannar.me

License

Distributed under the MIT license. See LICENSE for more information.