-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Composer: add clear command that bypasses the event count #46796
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
Composer: add clear command that bypasses the event count #46796
Conversation
…ount"" This reverts commit dc08606.
|
Reviewing today... |
Reviewer Checklist
Screenshots/VideosAndroid: Native01_Android_Native.mp4Android: mWeb Chrome02_Android_Chrome.mp4iOS: Native03_iOS_Native.mp4iOS: mWeb Safari04_iOS_Safari.mp4MacOS: Chrome / Safari05_MacOS_Chrome.mp4MacOS: Desktop06_MacOS_Desktop.mp4 |
Ollyws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both issues are fixed and the rest LGTM.
…er-not-clearing-on-send
|
All fixed @MariaHCD ! |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
FYI I believe this was deployed to prod yesterday, from this checklist - #47219 |

Details
This PR fixes an issue where the composer's text input wouldn't show the value the user expects (ie. it wouldn't immediately clear). The following use case now works:
Its the third attempt after these PRs got reverted:
which got reverted due to:
(I added the reproduction of this bug as test case)
Solution explained
This PR fixes the problem by adding an explicit
clearview command to the native text input view managers for clearing the text input.Usually when calling
testInputRef.clear()or setting the value prop to""it internally calls a view command calledsetTextAndSelection("", 0, 0).setTextAndSelectionis using an event count mechanism. It drops events from JS that have an outdated event count.The problem is that when we type text, click send, it can happen the user types more text before the
setTextAndSelection("", 0, 0)event reached the native side. Once it arrives it is already outdated and is simply dropped.Our explicit
clearview command always takes the latest event count on the native side (and actually also increments it, so any further updates that might happened in between get dropped).I recommend watching this recording with the solution in place. You can see how the JS thread is lacking behind as we rapidly send new messages:
ios-native.mov
The clearing now is guaranteed to happen immediately after pressing the enabled send button.
For sending, we don't rely on the
valuestate which could be outdated when the JS thread catches up and is ready to process sending, but on thetextparameter we receive in newly addedonClearcallback.This mechanism ensures that the full typed message gets send.
Code changes explained
shouldClear: booleanprop. Now the composer is just cleared using a ref method (this greatly simplified the clearing flow)<TextInput />now has an explicit view command calledclear()<TextInput />now accepts aonClearprop.textparameter, which is the value of the text that was cleared.clear()onClearcallback we take the text and send the message with that textprepareCommentAndResetComposermethod. Before we would imperatively call this method to signal we want to clear the composer. Now, we just call the view commandclearand wait for theonClearcallback to get us the comment value we need to send.Upstream PR at facebook/react-native
I discussed this with multiple people and figured the best way is to first start a discussion on the react-native repo. I suspect that such a change can take a long while until it gets merged to react-native in some way:
It might also be that meta doesn't want to do any of these changes. In this case we already discussed on slack that we might want to look into writing our own expensify text input component that extends react-native's.
There exists an issue for that in react-native:
Fixed Issues
$ #37896
PROPOSAL:
Tests
Note: For web there is a bug on
mainthat prevents pressing the send button. Make sure to setUSE_REACT_STRICT_MODE: falsein theCONFIG.ts12121212fast3434343456565656@to trigger the mention suggestionsNote: This changed code around the composer. Please test every composer action you can think of (including emojis, mentions, markdown, etc.)
Offline tests
n/a
QA Steps
Same as testing
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android-native.mov
Android: mWeb Chrome
mWeb-android.mov
iOS: Native
ios-native.mov
iOS: mWeb Safari
mWeb-ios.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov