-
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
Fix android copy paste menu doens't show up in compose box #7717
Conversation
if (this.comment.length === 0 && newComment.length !== 0) { | ||
if (this.state.isCommentEmpty) { | ||
this.setState({isCommentEmpty: false}); | ||
} | ||
Report.setReportWithDraft(this.props.reportID.toString(), true); | ||
} | ||
|
||
// The draft has been deleted. | ||
if (newComment.length === 0) { | ||
if (!this.state.isCommentEmpty) { | ||
this.setState({isCommentEmpty: true}); | ||
} |
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.
I didn't understand this part. Also, I would like to ask that your original solution is very different from your proposal. Why so?
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.
Because I realize updateCommnet
is handler for onChangeText
and put setNativePropse(text: )
in there isn't doing anything because when user type a character setNativeProps is being called even though the textInput is already changed by user type (you don't need setNativeProps
there).
As for setState
, each time user type a character setState
is being called then ReportActionCompose
is being rendered. I am guarding setState
of isCommentEmpty
so it is not being called unnecessarily.
Here I am attaching performance improvement, the first compose box is build using developement
build but it is faster than second compose box that is current production release.
ft.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.
Ok. I think we can refactor this into a small function so that it does not look confusing.
setCommentEmpty(isEmpty){
if(this.state.isCommentEmpty === isEmpty}{
return;
}
this.setState({isCommentEmpty: isEmpty});
}
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.
All right.
* @param {Object} selection: {start: number, end: number} | ||
*/ | ||
setTextAndSelectionOfTextInput(newText, selection) { | ||
if (Platform.OS === 'web') { |
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.
We don't use this. Check this.
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.
Alright, I will try other way.
// react-native-web | ||
// because setNativeProps in react-native-web is slow and doesn't have good support | ||
this.textInput.value = newText; | ||
this.textInput.setSelectionRange(selection.start, selection.end); | ||
} else { | ||
this.textInput.setNativeProps({text: newText, selection}); | ||
|
||
// Relasing selection handling to system | ||
setTimeout(() => this.textInput.setNativeProps({selection: {start: undefined, end: undefined}}), 0); | ||
} |
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.
Let's discuss this first. I have a couple of questions.
- why
because setNativeProps in react-native-web is slow and doesn't have good support
? Any reasons to support your comment. - Use of
setTimeout
. Why is this needed?
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.
It is setTimeout
0, you can read more about it here:
https://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful
For this code it is to ensure that the previous setNativeProps
is completed/done then do second setNativeProps
.
As for setNativeProps
for react-native-web, please wait.
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.
And this is very confusing that you are first settings the selection and then releasing it.
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.
If we don't do that, the selection will stay or come back at that position. Maybe will adds some comments.
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.
There is an issue with IOS. Where after adding the emoji the cursor is moved to the start of the text.
Please test it on IOS and Destop and add videos for those.
Add dekstop and ios videos, and new commit to fix IOS issue. |
I am able to find another solution for IOS without second |
@stitesExpensify for update, the |
I have raised some concerns on the slack. I will revisit this in some days. |
src/libs/TextInputUtils/index.ios.js
Outdated
* @param {String} text | ||
* @param {Object} selection: {start: number, end: number} | ||
*/ | ||
function setTextAndSelection(textInputElement, text, selection) { |
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.
@stitesExpensify This function is implemented differently on Android|IOS|Web. What do you think about this imlementation?
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.
I think I'm missing some context. Why does this need to be implemented in 3 different ways @K4tsuki ?
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.
@stitesExpensify for the web, setNativeProps for selection
doesn't work, because to set the selection of text input in web the property name is selectionStart
and selectionEnd
. So it has different name than native selection
property.
For IOS, at first I am using android code, but there is a bug, like what @parasharrajat mention above.
There is an issue with IOS. Where after adding the emoji the cursor is moved to the start of the text.
The native behavior of setting selection using setNativeProps
is different in IOS and android, so I am just adjusting the code based on native behavior of android and IOS.
Also the setTimeouts can be replaced by Promise-resolve.
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.
@stitesExpensify Hope you had a nice vacation. Please share your thoughts on the PR. I have raised some review comments that need your attention. Thanks.
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.
Issue (Web): NumberLines is not updated which means the necessary events are not fired when we update the value via setTextAndSelection
.
Steps:
- Write a multiline comment for about 6 lines.
- Select the text on lines 3-5.
- add an emoji.
- Notice that emoji is placed fine but there are extra lines on the text input.
- But when we start typing the lines are recalc.
Lines should update when we update the value on input.
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.
Ok. The solution started to become messy and hacky. I will try to do some digging first. But We are just trying to patch in code to fix issues that are going to introduce more issues.
I would not suggest going too deep with platform-specific code.
As events are not firing, it means that we are doing it all wrong. Although we can put in all the vanilla js in react we should avoid it. Instead, do things react way.
Let me know if you have other ideas as well. I would hear them out first.
@parasharrajat What is the ideal solution? Should I don't use platform specific code at all for this issue? and Should I don't use |
@stitesExpensify What is the ideal solution here? Could I use my code inside Also, Are |
I will give it a shot and see if something else can be done here. It is fine to use platform-specific code but this should only be used when there are no other choices. Apart from it, the problem is not that we are using platform-specific code instead of the way it is used. |
Closing this since K4tsuki is no longer a contributor |
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA Katsuki seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
Details
Fix copy paste context menu won't show up in android.
Change
TextInput
of compose box into uncontrolledTextInput
that will improve performance ofTextInput
Fixed Issues
$ #6876
Tests
QA Steps
Tested On
Screenshots
Web
web.mp4
Mobile Web
m_web.mp4
Desktop
desktop_compose.mp4
iOS
ios_compose.mp4
Android
android_cp.mp4