App icon indicating copy to clipboard operation
App copied to clipboard

Compose box is not cleared after sending a message if the user starts typing just after pressing send - iOS / Android

Open isagoico opened this issue 5 years ago • 75 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Log in to e.cash in mobile and navigate to a conversation
  2. Type a message and press send
  3. Immediately after pressing send start typing another message

Expected Result:

Compose box should be cleared after sending the message

Actual Result:

Previous message is still in compose box if the user starts typing just after pressing send

Workaround:

Waiting a bit after pressing send clears the compose box. But this could be a pain for fast typers.

Platform:

Where is this issue occurring?

Web iOS ✔️ Android ✔️ Desktop App Mobile Web

Version Number: 1.0.79-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos:

https://user-images.githubusercontent.com/44479856/126039540-46ce81fa-bf45-4df6-85e2-2d5d6f11577f.mov

Expensify/Expensify Issue URL:

View all open jobs on Upwork


From @aliabbasmalik8 https://expensify.slack.com/archives/C01GTK53T8Q/p1626378713340800 and @joaniew https://expensify.slack.com/archives/C01GTK53T8Q/p1626387085365100

Send message takes some time so last message append with next message. we can clear the compose box after he click on send icon. (@aliabbasmalik8)

i noticed on mobile (iOS) there’s a lag between when i hit ‘send’ and when it actually sends. but i’m the type of typer who will start typing a new message expecting the chat box to clear once the message has been sent. what happens in echat is that the message sends, but if i don’t wait for it to send/clear the msg box and start typing immediately, it keeps the original message, which means i have to either go back and delete it or wait until it sends (who knows how long that takes sometimes. Video attached (wait til the 2nd testing chat) (@joaniew)


IMPORTANT PLEASE READ

Instructions on how to make a proposal for this issue:

  • Read the entire comment thread to be sure you are not proposing a solution that was already discussed
  • Provide a clear explanation of the problem and why it happens
  • Provide a clear explanation of the solution and how to implement it
  • Provide proof that the solution will solve the issue on iOS/Android (ideally a video of native platform - not web)
  • Provide enough detail so that we can implement your solution and verify that it works.

Proposals without this information will be marked as off-topic. Thanks!

isagoico avatar Jul 17 '21 14:07 isagoico

Triggered auto assignment to @robertjchen (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Jul 17 '21 14:07 MelvinBot

I was able to reproduce this behavior in the iOS emulator. Interestingly enough, it doesn't seem to be an issue on the Web-based client.

After unsuccessfully trying some quick JS changes, I think the potential solution might have to involve low-level, native control of the input field behavior. Opening it up for others to try tackling it, perhaps a more suitable JS solution can be found! 👍

robertjchen avatar Jul 29 '21 11:07 robertjchen

Triggered auto assignment to @bfitzexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Jul 29 '21 11:07 MelvinBot

Triggered auto assignment to @marcaaron (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Jul 29 '21 19:07 MelvinBot

the problem seems to be related to state management

muratti32 avatar Jul 29 '21 20:07 muratti32

I can easily fix this; it seems to be the problem because the input field is not controlled. (state management problem) My Upwork profile: https://www.upwork.com/freelancers/~014e072a4daf3ed991 Thanks

sonipranjal avatar Jul 29 '21 21:07 sonipranjal

the problem seems to be related to state management

@muratti32 How so?

I can easily fix this; it seems to be the problem because the input field is not controlled. (state management problem)

@sonipranjal We had a controlled input used in the past. The performance was very bad.

marcaaron avatar Jul 29 '21 21:07 marcaaron

If it helps, here's where we clear the comment by calling this method with an empty string

https://github.com/Expensify/App/blob/fa355419244df0f583a54ae9e561fab7a9c647bd/src/pages/home/report/ReportActionCompose.js#L419-L420 https://github.com/Expensify/App/blob/fa355419244df0f583a54ae9e561fab7a9c647bd/src/pages/home/report/ReportActionCompose.js#L303-L311

I'm not certain, but if I had to guess there's some conflict between the logic that is doing

setTextInputShouldClear() (which will trigger this.textInput.clear()) and setNativeProps({text: ''})

marcaaron avatar Jul 29 '21 21:07 marcaaron

Proposal

We can try running the submitting after clearing the textField.

setTextInputShouldClear(shouldClear, fn) {
    this.setState({textInputShouldClear: shouldClear}, fn ? fn() : undefined);
  }

submitForm(e) {
    if (e) {
      e.preventDefault();
    }

    const trimmedComment = this.comment.trim();
    // Don't submit empty comments
    if (!trimmedComment) {
      return;
    }
    
    this.updateComment('');
    this.setTextInputShouldClear(true, () => {
      this.props.onSubmit(trimmedComment);
    });

  }

mananjadhav avatar Jul 29 '21 21:07 mananjadhav

We can try running the submitting after clearing the textField.

@mananjadhav Interesting, is there some explanation for why this would help?

marcaaron avatar Jul 29 '21 22:07 marcaaron

we update the submitForm in "src/pages/home/report/ReportActionCompose.js" this.setTextInputShouldClear(true); is use the first line in submitForm

arpitdeveloper avatar Jul 30 '21 05:07 arpitdeveloper

@marcaaron, @bfitzexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

MelvinBot avatar Aug 02 '21 19:08 MelvinBot

I would try to clear input first and then trigger the send message functionality. clearing input is a state update so it should not affect the sending message time. and yes updating the state is the only solution I see here, there can be problem with re-rendering and we can optimise the component to avoid re-render by making some components Pure or by using useMemo if that is not implemented yet.

harshilJs avatar Aug 03 '21 22:08 harshilJs

once it submit the message from state, we just need to clear/empty state again.

bzaman avatar Aug 04 '21 07:08 bzaman

@marcaaron, @bfitzexpensify Eep! 4 days overdue now. Issues have feelings too...

MelvinBot avatar Aug 04 '21 19:08 MelvinBot

Sorry, I still don't think we've got the right proposal yet.

marcaaron avatar Aug 05 '21 00:08 marcaaron

It's been >7 days since posting — reposted under a new job on Upwork with price doubled to $500.

bfitzexpensify avatar Aug 09 '21 13:08 bfitzexpensify

Won't this work?

this.textInput.clear();

rndev707 avatar Aug 09 '21 14:08 rndev707

Won't this work?

this.textInput.clear();

If you check the code, this exists but the issue comes when you click the button and the text simultaneosuly.

mananjadhav avatar Aug 09 '21 14:08 mananjadhav