-
Notifications
You must be signed in to change notification settings - Fork 3k
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
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 |
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
clear
view 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)
.setTextAndSelection
is 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
clear
view 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
value
state which could be outdated when the JS thread catches up and is ready to process sending, but on thetext
parameter we receive in newly addedonClear
callback.This mechanism ensures that the full typed message gets send.
Code changes explained
shouldClear: boolean
prop. 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 aonClear
prop.text
parameter, which is the value of the text that was cleared.clear()
onClear
callback we take the text and send the message with that textprepareCommentAndResetComposer
method. Before we would imperatively call this method to signal we want to clear the composer. Now, we just call the view commandclear
and wait for theonClear
callback 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
main
that prevents pressing the send button. Make sure to setUSE_REACT_STRICT_MODE: false
in theCONFIG.ts
12121212
fast34343434
56565656
@
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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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