Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable send Button in custom ChatInputItem #38

Open
ogezue opened this issue Feb 6, 2016 · 3 comments
Open

Enable send Button in custom ChatInputItem #38

ogezue opened this issue Feb 6, 2016 · 3 comments

Comments

@ogezue
Copy link

ogezue commented Feb 6, 2016

I have created my own ChatInputItem where the user can specify a date and a location. After the data has been entered the send button should get active so that I can call my REST-service to create an appointment request.

To achive this I think I need two modifications from you:

  1. A way to enable the send button
  2. Some kind of hook to inform me that the send button was pressed. Then I send the create appointent request to my backend that creates a message for me and the receiver that should be displayed in the chat module (For the receiver the message contains buttons to reply - but this problem is already solved).

Here my AppointmentInputItem:

extension AppointmentInputItem : ChatInputItemProtocol {

    public var presentationMode: ChatInputItemPresentationMode {
        return .CustomView
    }

    public var showsSendButton: Bool {

        return true
    }

    public var inputView: UIView? {

        if let view = self.appointmentInputView{
            return view
        }
        if let customView = NSBundle.mainBundle().loadNibNamed("AppointmentInput", owner: self, options: nil).first as? AppointmentInputView {

            customView.frame = CGRectMake(0, 0, 300, 250)

            return customView
        }
        return nil

    }

    public var tabView: UIView {
        return self.internalTabView
    }


    public func handleInput(input: AnyObject) {}

Another problem that I discovered is that the AppointmentInputItem loses its focus if I launch an UIAlertController to ask for another location. It would be great if this could be prevented too.

@AntonPalich
Copy link
Contributor

Hi @ogezue ,

(1) "Send" button attached to text view. It is enabled when text view has some text inside it. If you want to be able to send something without having text in text view, then you can place controls inside you own inputView. If you want to enable button on your own then you can help use and suggest your solution.

(2) When user press "Send" button ChatInputItem.handleInput() function will be called:

    // ChatInputBar.swift
    func inputBarSendButtonPressed(inputBar: ChatInputBar) {
        if let focusedItem = self.focusedItem {
            focusedItem.handleInput(inputBar.inputText)
        } else if let keyboardItem = self.firstKeyboardInputItem() {
            keyboardItem.handleInput(inputBar.inputText)
        }
    }

You can do whatever you want in your own ChatInputItem protocol implementation:

extension AppointmentInputItem : ChatInputItemProtocol {
    ...
    public func handleInput(input: AnyObject) {
        // do your staff here, "input" object will be text from text view
    }
}

Remember, that you have total control over your code in inputView object. For example, PhotoInputitem sends image without interacting with ChatInputItem protocol

(3) We can't do anything with it. iOS responsible for resigning first responder when UIAlertView appears, but it should return first responder when UIAlertView disappears. I didn't check it, but with UIActionSheet it works well.

@ogezue
Copy link
Author

ogezue commented Feb 9, 2016

Hi @AntonPalich,

thank you very much for your answer. Perhaps you can give me some advice how to implement my InputItem if I show you a screenshot. The problem I'm currently focussing is to enable the send button without a textfield.

simulator screen shot 09 02 2016 10 07 09

@ogezue
Copy link
Author

ogezue commented Feb 17, 2016

Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants