Code Monkey home page Code Monkey logo

messageinputbar's Introduction

Carthage compatible Swift CocoaPods Xcode MIT Contributions Welcome

Installation

CocoaPods Recommended

pod 'MessageInputBar'

To integrate MessageKit using Carthage, add the following to your Cartfile:

github "MessageKit/MessageInputBar"

Requirements

  • iOS 9 or later
  • Swift 4 or later

Version 0.4.0 onwards is only Swift 4.2 compatible

Contributing

Great! Look over these things first.

  • Please read our Code of Conduct
  • Check the Contributing Guide Lines.
  • Come join us on Slack and ๐Ÿ—ฃ don't be a stranger.
  • Check out the current issues and see if you can tackle any of those.
  • Download the project and check out the current code base. Suggest any improvements by opening a new issue.
  • Check out the What's Next section ๐Ÿ‘‡ to see where we are headed.
  • Check StackOverflow
  • Install SwiftLint too keep yourself in :neckbeard: style.
  • Be kind and helpful.

What's Next?

Check out the Releases to see what we are working on next.

Contact

Have a question or an issue about MessageKit? Create an issue!

Interested in contributing to MessageKit? Click here to join our Slack.

Apps using this library

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

Please provide attribution, it is greatly appreciated.

MessageKit Core Team

Thanks

Many thanks to the contributors of this project.

License

MessageInputBar is released under the MIT License.

messageinputbar's People

Contributors

btomtom5 avatar nathantannar4 avatar tkeithblack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

messageinputbar's Issues

handleInput() takes in an object of class `AnyObject` but should take in an object of class `Any` in order to support URLs

In the AttachmentManager class

this method:

open func handleInput(of object: AnyObject) -> Bool {
        let attachment: Attachment
        if let image = object as? UIImage {
            attachment = .image(image)
        } else if let url = object as? URL {
            attachment = .url(url)
        } else if let data = object as? Data {
            attachment = .data(data)
        } else {
            return false
        }
        
        insertAttachment(attachment, at: attachments.count)
        return true
    }

the problem with this is if you try and input a URL from a video such as:

`@objc func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
    if let editedImage = info[.editedImage] as? UIImage {
        inputPlugins.forEach { _ = $0.handleInput(of: editedImage) }
    } else if let originImage = info[.originalImage] as? UIImage {
        inputPlugins.forEach { _ = $0.handleInput(of: originImage) }
    } else if let videoURL = info[.mediaURL] as? URL {
        inputPlugins.forEach  { _ = $0.handleInput(of: videoURL) }
    }
    getRootViewController()?.presentedViewController?.dismiss(animated: true, completion: nil)
    inputAccessoryView?.isHidden = false
}

`

you will get an error: "Argument type 'URL' expected to be an instance of a class or class-constrained type"

It seems that the issue lies in the definition of the method handleInput. The method is expecting an argument of type AnyObject, but URL is not a subclass of AnyObject, it's a struct. To resolve the issue, you need to change the definition of handleInput to accept a value of type Any instead:

so that method should look like this:

open func handleInput(of object: Any) -> Bool {
    let attachment: Attachment
    if let image = object as? UIImage {
        attachment = .image(image)
    } else if let url = object as? URL {
        attachment = .url(url)
    } else if let data = object as? Data {
        attachment = .data(data)
    } else {
        return false
    }
    
    insertAttachment(attachment, at: attachments.count)
    return true
}

Swift 4.2

It looks like MessageKit has been updated to use Swift 4.2, but this library has not. Any ETA for when we can get complete Swift 4.2 support in MessageKit?

InputTextView is broken when used with AutocompleteManager due to UITextView typing

What happened?

I created an AttachmentManager below and passed it my InputTextView.

let inputBar = MessageInputBar()
let manager = AttachmentManager(for: inputBar.inputTextView)

However, the property textView of AttachmentManager of is typed as UITextView. So the library's internals doesn't know any of the overriden methods of UITextView in the InputTextView class. This causes things like my placeholder text to never clear.

What did I expect to happen?

I expected that AttachmentManager respects the changes inInputTextView

Blame is #8 (review)

Swift version: 4.0
MessageInputBar version: 0.2.2
Xcode version: 9.4
Installation Method: Carthage

messageInputBar.delegate = self does not work

I am trying to trying to implement a chat feature in my app but it is not going so well.
I was trying to check if the send button was working correctly by printing out "button is pushed", but it didn't get printed.
I realized messageInputBar.delegate = self was not in the code and I thought that was the problem and as I put in the line of code an error below popped up. I don't know how to fix this and it would be a great help if you could give me an advice on what I should do.
Cannot assign value of type 'MessageKitChatViewController' to type 'InputBarAccessoryViewDelegate?' Add missing conformance to 'InputBarAccessoryViewDelegate' to class 'MessageKitChatViewController'

`import UIKit
import MessageKit
import MessageInputBar
import FirebaseFirestore
import FirebaseAuth
import FirebaseStorage
import Nuke

struct Sender: SenderType{
var senderId: String
var displayName: String
}

struct MessageKitMessage: MessageType{
var sender: SenderType
var messageId: String
var sentDate: Date
var kind: MessageKind
}

class MessageKitChatViewController: MessagesViewController, MessagesDataSource, MessagesLayoutDelegate, MessagesDisplayDelegate, MessageInputBarDelegate{

var senderUser = Auth.auth().currentUser!
var messages = [MessageType]()

let currentUser = Sender(senderId: Auth.auth().currentUser!.uid , displayName: Auth.auth().currentUser!.displayName ??  "Name not found")



override func viewDidLoad() {
    super.viewDidLoad()
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messageInputBar.delegate = self
}

func currentSender() -> SenderType {
    return currentUser
}

func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
    return messages[indexPath.section]
}

func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
    return messages.count
}


func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {

// let message = MessageKitMessage(sender: currentUser, messageId: UUID().uuidString, sentDate: Timestamp().dateValue(), kind: .text(text))
print("button is pushed")
}

}

`

Crash when attaching multiple images to MessageInputBar

I encountered a crash when crash when inserting text followed by multiple pictures into the MessageInputBar.

The crash occurs in parseForComponents() located in InputTextView.swift.

The following line was the culprit:

let textRange = NSMakeRange(curLocation, range.location)
This worked fine on the first image, but subsequent images crashed because the length should be range.location-curLocation as below:

let textRange = NSMakeRange(curLocation, range.location-curLocation)
With this change it is now working.

KeithB

AttachmentManager tintcolor is readonly, provide a setter for it

in order to customize the attachment manger we need to make the tintColor property assignable. Right now the backgorund color for the delete button will always be blue.

if we want to change it such as:

let manager = AttachmentManager()
manager.tintColor = UIColor.green

we get an error: Cannot assign to property: 'tintColor' is a get-only property"

a solution could look like:

open var tintColor: UIColor {
    get {
        if #available(iOS 13, *) {
            return .link
        } else {
            return .systemBlue
        }
    }
    set {
        // Implementation to set the value of tintColor
    }
}

Keyboard handlers within message kit

I have a chat view embedded with in my app hooked up to firebase. Works great. Thank you.

The issue I am having is the client wants the input for the chat to be about mid screen.

I have hidden the input bar accessory because there seems to be no way to embed it in the mid screen view with the chat. It that is possible let me know.

Currently when the keyboard appears for my text field it covers the text field.

Is there anyway to turn off the keyboard handlers in MessageKit. I have my own and the are working it just the ones in MessageKit are taking precedence.

The attached is a mock of the issue. Actual app under NDA... but the its the same issue

Simulator Screen Shot - iPhone 11 Pro Max - 2020-03-04 at 06 18 25
Simulator Screen Shot - iPhone 11 Pro Max - 2020-03-04 at 06 18 34

Autocomplete height reacts but stays blank

Hello, I know that a similar issue has been raised #7 but it has highlighted a different problem that I am experiencing. When completing it with the prefix "#" the table appears but is blank.
Screen Shot 2022-01-23 at 7 41 07 PM

here are the concerned chunk of code :

class types:

class Chat:MessagesViewController, MessagesDataSource, MessagesLayoutDelegate, MessagesDisplayDelegate,InputBarAccessoryViewDelegate,AutocompleteManagerDataSource, AutocompleteManagerDelegate

autocomplete variable:

    open lazy var autocompleteManager: AutocompleteManager = { [unowned self] in
          let manager = AutocompleteManager(for: self.messageInputBar.inputTextView)
          manager.delegate = self
          manager.dataSource = self
          return manager
      }()

viewdidload for autocomplete:


        autocompleteManager.register(prefix: "#", with: mentionTextAttributes)
        autocompleteManager.maxSpaceCountDuringCompletion = 1

Here are the different methods for autocomplete, all of them are called and we can see what is printed except for one which i guess is the issue:

CALLED:

    func autocompleteManager(_ manager: AutocompleteManager, shouldBecomeVisible: Bool) {
        setAutocompleteManager(active: shouldBecomeVisible)
    }
func setAutocompleteManager(active: Bool) {
            let topStackView = messageInputBar.topStackView
            if active && !topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
                topStackView.insertArrangedSubview(autocompleteManager.tableView, at: topStackView.arrangedSubviews.count)
                topStackView.layoutIfNeeded()
            } else if !active && topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
                topStackView.removeArrangedSubview(autocompleteManager.tableView)
                topStackView.layoutIfNeeded()
            }
        messageInputBar.invalidateIntrinsicContentSize()
        }
    
  ```

func autocompleteManager(_ manager: AutocompleteManager, shouldRegister prefix: String, at range: NSRange) -> Bool {
return true
}


NOT CALLED AND ISSUE:

func autocompleteManager(_ manager: AutocompleteManager, tableView: UITableView, cellForRowAt indexPath: IndexPath, for session: AutocompleteSession) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: AutocompleteCell.reuseIdentifier, for: indexPath) as? AutocompleteCell else {
fatalError("None ")
}
let users = Users
let name = session.completion?.text ?? ""
let user = users.filter { return $0.displayName == name }.first
cell.imageView?.image = UIImage(named: "art.scnassets/imp.png")
cell.textLabel?.attributedText = manager.attributedText(matching: session, fontSize: 15)
return cell
}


Can anyone please advise
Thank you

can not disable autocorrectionType

Hi, i tried to disable autoCorrectionType but not working, can u help?

here is my code:

***viewDidLoad***
// Configure AutocompleteManager
        autocompleteManager.register(prefix: "@", with: [.font: UIFont.boldSystemFont(ofSize: 17),
                                                         .foregroundColor: UIColor.orange])
        autocompleteManager.textView?.theme_keyboardAppearance = [.dark, .light]
        autocompleteManager.textView?.autocorrectionType = .no
        autocompleteManager.textView?.autocapitalizationType = .none
        autocompleteManager.textView?.textContentType = .username
        autocompleteManager.tableView.theme_backgroundColor = ThemeColor.normalViewBgColor
        autocompleteManager.defaultTextAttributes = [.font: UIFont.systemFont(ofSize: 17), .foregroundColor: ThemeUtils.current == .dark ? UIColor.white : UIColor.black]
        autocompleteManager.maxSpaceCountDuringCompletion = 0
        autocompleteManager.delegate = self
        
        // Set plugins
        messageInputBar.inputPlugins = [autocompleteManager]
        messageInputBar.inputTextView.autocorrectionType = .no
        messageInputBar.inputTextView.autocapitalizationType = .none
        messageInputBar.inputTextView.allowsEditingTextAttributes = false
        messageInputBar.inputTextView.textContentType = .username

Can't make message input bar first responder?

I've tried calling:
self.becomeFirstResponder()
self.messageInputBar.becomeFirstResponder()
self.messageInputBar.inputTextView.becomeFirstResponder()

From viewDidLoad, viewWillAppear, and viewDidAppear and I still can't get the keyboard to open automatically for my view controller. For normal text views, calling becomeFirstResponder() should automatically focus them and present the keyboard. What gives? Is there a workaround?

keep getting message input bar delegate ambiguous for type lookup in this context

import UIKit
import MessageKit
import MessageInputBar

class newViewController: MessagesViewController {

var messages: [Message] = []
var member: Member!

override func viewDidLoad() {
    super.viewDidLoad()
    member = Member(name: "bluemoon", color: .blue)
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messagesCollectionView.messageCellDelegate = self as? MessageCellDelegate
    // Do any additional setup after loading the view.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

}

extension newViewController: MessagesDataSource {
func currentSender() -> SenderType {
return Sender(id: member.name, displayName: member.name)

}

func numberOfSections(
    in messagesCollectionView: MessagesCollectionView) -> Int {
    return messages.count
}


func messageForItem(
    at indexPath: IndexPath,
    in messagesCollectionView: MessagesCollectionView) -> MessageType {
    
    return messages[indexPath.section]
}

func messageTopLabelHeight(
    for message: MessageType,
    at indexPath: IndexPath,
    in messagesCollectionView: MessagesCollectionView) -> CGFloat {
    
    return 12
}

func messageTopLabelAttributedText(
    for message: MessageType,
    at indexPath: IndexPath) -> NSAttributedString? {
    
    return NSAttributedString(
        string: message.sender.displayName,
        attributes: [.font: UIFont.systemFont(ofSize: 12)])
}

}

extension newViewController: MessagesLayoutDelegate {
func heightForLocation(message: MessageType,
at indexPath: IndexPath,
with maxWidth: CGFloat,
in messagesCollectionView: MessagesCollectionView) -> CGFloat {

    return 0
}

}

extension newViewController: MessagesDisplayDelegate {
func configureAvatarView(
_ avatarView: AvatarView,
for message: MessageType,
at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) {

    let message = messages[indexPath.section]
    let color = message.member.color
    avatarView.backgroundColor = color
}

}

extension newViewController: MessageInputBarDelegate {
func messageInputBar(
_ inputBar: MessageInputBar,
didPressSendButtonWith text: String) {

    let newMessage = Message(
        member: member,
        text: text,
        messageId: UUID().uuidString)
    
    messages.append(newMessage)
    inputBar.inputTextView.text = ""
    messagesCollectionView.reloadData()
    messagesCollectionView.scrollToBottom(animated: true)
}

}

InputBarAccessoryView showing on top of presentedViewController

MessageKit version(s):
3.0.0-beta-swift5
iOS version(s):
iOS 13
Devices/Simulators affected:
iPhone 11
A well written description of the problem you are experiencing:
The messageInputBar is showing above the presentedViewController when a user puts the app into the background and then returns it to the foreground
Please provide complete steps to reproduce the issue:
NOTE: in iOS 13 Apple introduced a new card style for modal presentations, so perhaps this is related to other changes that came with that.

This only occurs when the inputTextView is currently the first responder while a VC is being presented

  • My presenting VC is a subclass of MessagesViewController and it is calling present(:animated:completion:)
  • The presented VC shows in the iOS modal card style, with the messageInputBar being hidden underneath (as expected)
  • If the user moves the app to the background at this point, and then returns to the app, the messageInputBar is now showing above the presented VC (see attached image)

For UI related issues, please provide a screenshot/GIF/video showing the issue:
Video: https://www.dropbox.com/s/h9c3nf3hpmmu9me/Screen%20Recording%202019-10-18%20at%2012.33.23%20PM.mov?dl=0
Image: https://www.dropbox.com/s/qcjosi8noduspgs/Screenshot%202019-10-18%2012.34.05.png?dl=0

Images pasted into InputTextView have incorrect orientation

I am having difficulty handling image orientations correctly in the InputTextView. Images attached from the Photos library or from the devices camera can appear sideways or upside down in the InputTextView. This is happening in MessageInputBar version 0.4.1.

I am attaching images from a UIImagePickerController with the following code:

extension ConversationViewController: UIImagePickerControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            messageInputBar.inputTextView.pasteImageInTextContainer(with: image)
            dismiss(animated: true, completion: nil)
        }
    }
}

This problem can be reproduced using the ChatExample app in the simulator (iOS 12.1) with the following steps:

  1. From the simulator's Photos app, copy the flowers photo to the clipboard
  2. In the ChatExample app, paste the clipboard contents into the InputTextView

Note that the pasted image is upside down.

image

image

MessageInputBarDelegate Method Keyboard is Shown

Is there a way to detect when the keyboard is shown or better yet when the user taps on the text field? I want to build functionality to where when the user opens the keyboard or taps the text field to start editing, it checks to see if the table view is at the bottom, and if so, it automatically scrolls back down to the bottom.

Currently if you are at the bottom of the table view, and you take the text field, the messages at the bottom disappear until you scroll down again.

AutocompleteManager + MessageKit

Hey Nathan,

I've been able to get the AttachmentManager plugin working on MessageKit 1.0 from MessageInputBar 0.2 using example code written in the InputAccessoryBar 2.1, however, I am unable to successfully get AutoCompleteManager working. The problem that I find is that when I enter in the prefix, @, the table appears but is blank.

screen shot 2018-07-06 at 12 50 29 am

I thought this was peculiar so I then started to print out the users that were being returned in the

'func autocompleteManager(_ manager: AutocompleteManager, autocompleteSourceFor prefix: String) -> [AutocompleteCompletion] ',

and it seems to be a loop that continues to run while the prefix exists (note the scroll indicator on the right. When I started to take the screenshot, it was in the middle of scroll bar). Note, I do not find this behavior in the InputAccessoryBar project. My guess is that this would explain why the table is not being updated as the values continue to be updated too quickly for the table to register. I thought this had to do with the asynccompletions, so I removed those but to no avail.

screen shot 2018-07-06 at 12 52 43 am

Any help in this matter would be appreciated!

Value of type 'InputItem' has no member 'isEnabled'

I want to disable the leftStackViewItem when sending a photo, so I do this self.messageInputBar.leftStackViewItems.forEach { item in item.isEnabled = !self.isSendingPhoto } but I get this error Value of type 'InputItem' has no member 'isEnabled'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.