App
App copied to clipboard
[HOLD for payment 2024-01-04] [$500] Android - Chat - Message gets displayed from right to left
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 1.3.93-0 **Reproducible in staging?:**Y **Reproducible in production?:**Y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: Applause - Internal Team Slack conversation:
Issue found when executing PR https://github.com/Expensify/App/pull/30521
Action Performed:
- Launch App
- Open any chat and paste an RTL text in the compose box, for example " مثال "
- Continue typing some content
Expected Result:
Verify that the content gets displayed from left to right
Actual Result:
The content gets displayed from right to left
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
- [x] Android: Native
- [ ] Android: mWeb Chrome
- [ ] iOS: Native
- [ ] iOS: mWeb Safari
- [ ] MacOS: Chrome / Safari
- [ ] MacOS: Desktop
Screenshots/Videos
Android: Native
https://github.com/Expensify/App/assets/78819774/d7ac6f63-be15-4b10-9a4b-58e66b55d53a
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~01278feafdf81fcb73
- Upwork Job ID: 1718998877593833472
- Last Price Increase: 2023-11-20
- Automatic offers:
- samilabud | Contributor | 27900958
Triggered auto assignment to @johncschuster (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.
Job added to Upwork: https://www.upwork.com/jobs/~01278feafdf81fcb73
Bug0 Triage Checklist (Main S/O)
- [ ] This "bug" occurs on a supported platform (ensure
Platformsin OP are ✅) - [ ] This bug is not a duplicate report (check E/App issues and #expensify-bugs)
- If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
- [ ] This bug is reproducible using the reproduction steps in the OP. S/O
- If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
- If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
- [ ] This issue is filled out as thoroughly and clearly as possible
- Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
- [ ] I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
Triggered auto assignment to Contributor-plus team member for initial proposal review - @allroundexperts (External)
Proposal
Please re-state the problem that we are trying to solve in this issue.
Android - Chat - Message gets displayed from right to left
What is the root cause of that problem?
This issue only happens on few android devices so the root cause is unclear.
What changes do you think we should make in order to solve the problem?
We can set selection ({start: 0}) when inputText onblur. like this answer suggested or we can use I18nManager to solve this issue like:
import { I18nManager } from "react-native";
I18nManager.forceRTL(false);
I18nManager.allowRTL(false);
Result
cc: @HardikChoudhary24
For android it will be working like that it is mentioned in comment. Also this can be seen for other apps like linkedin where the web version is having the desired result and their android app is not showing it in LTR format
Hm... @HardikChoudhary24 I see your comment, but I think this is still a bug. I guess we can keep this open and see if we can get a concrete fix in place?
Sure @allroundexperts but this is something that is not supported in android as per my knowledge. This can be seen in other apps like LinkedIn, discord, and Puma. These are the ones that I have tested and found that they are displaying it in the desired format on web but not on native android.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Chat - Message gets displayed from right to left
What is the root cause of that problem?
The root cause is that Android only converts RTL text to LTR text using Unicode controls and by default, when you start writing in a language that is written in RTL mode it converts the input text to RTL.
What changes do you think we should make in order to solve the problem?
The best solution is to add \u2066 unicode character before starting to write, I suggest verifying (when the user is using Android) if the input value is empty and doing the next in the ComposerWithSuggestions component:
https://github.com/Expensify/App/blob/5d45f0f6c86e97d4ae58ac167b6c162a610b817c/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js.
useEffect(() => {
if (value === '') {
setValue(convertToLTR(value));
}
}, [value]);
The convertToLTR function adds the unicode character needed for this to work in Android.
- For Android: https://github.com/Expensify/App/blob/5d45f0f6c86e97d4ae58ac167b6c162a610b817c/src/libs/convertToLTR/index.android.ts
- For anything else:_ https://github.com/Expensify/App/blob/1dd55f164afdd774b36031d472b5c5916b5a4ef0/src/libs/convertToLTR/index.ts
This way the input in Android never changes to direction = RTL, please see the result:
https://github.com/Expensify/App/assets/5216036/1b3b1a36-a98a-4086-b9f6-7d8e9961719a
@allroundexperts can you take a look at the updated proposal above when you get a moment?
@johncschuster, @allroundexperts Whoops! This issue is 2 days overdue. Let's get this updated quick!
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
@samilabud's proposal seems to work well.
@HardikChoudhary24 did you explore this solution before? If so, do you know if it has some shortcomings? cc @situchan as well since you seem to have been involved in that conversation.
Proposal
Please re-state the problem that we are trying to solve in this issue.
The text is displayed right to left.
What is the root cause of that problem?
The ReactRoot view default textDirection is firstStrong (screenshot1, screenshot2)
https://developer.android.com/reference/android/view/View.html#attr_android:textDirection
firstStrong
Default for the root view. The first strong directional character determines the paragraph direction.
If there is no strong directional character, the paragraph direction is the view\u2019s resolved layout direction.
- The text
مثالadisplays as left-to-right - The text
aمثالdisplays as right-to-left
Testing textDirection: firstStrong and textDirection: ltr on Android
https://developer.android.com/reference/android/view/View.html#attr_android:textDirection
https://github.com/fabriziobertoglio1987/text-input-cursor-flickering-android/blob/31db5796c6abbd17ffaa87de1663c38604d1da33/app/src/main/java/com/example/javaexample/CustomEditText.java#L29-L43
| TextDirection firstStrong | TextDirection ltr |
|---|---|
What changes do you think we should make in order to solve the problem?
Expose textDirection style prop in the React Native API to allow changing the Views (View, TextInput, Text) textDirection.
- Add a JavaScript textDirection style prop to the React Native API:
<View style={{textDirection: "ltr"}}>
<TextInput style={{textDirection: "inherit"}}>The TextInput inherits the style from the parent</TextInput>
<TextInput style={{textDirection: "firstStrong"}}>The TextInput content aligns based on the first character content</TextInput>
</View>
- Set the
textDirectionof the Android View using setTextDirection (android code snippet).
@johncschuster, @allroundexperts Whoops! This issue is 2 days overdue. Let's get this updated quick!
@johncschuster, @allroundexperts Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
@samilabud's proposal seems to work well.
@HardikChoudhary24 did you explore this solution before? If so, do you know if it has some shortcomings? cc @situchan as well since you seem to have been involved in that conversation.
@allroundexperts we are already adding \u2066 before the RTL characters to make them appear as LTR in convertToLTRForComposer function. It is avoided in case of android because the composer does not behave as expected, as seen below.
https://github.com/Expensify/App/assets/126149345/0da6a1dd-42f5-4818-b24d-a0db7febcfb0
@HardikChoudhary24, we are adding the Unicode \u2066 when we send the message, my proposal is to add it before starting to write and when the user is using Android.
Please see how it looks in Android:
https://github.com/Expensify/App/assets/5216036/1b3b1a36-a98a-4086-b9f6-7d8e9961719a
@samilabud Why doesn't the message show up in the chat once you send it in the above video?
@samilabud Why doesn't the message show up in the chat once you send it in the above video?
Oh that's was for my connection (was slow) and here the video should be max 10mb 😅, but I can share another video if you want.
@HardikChoudhary24, we are adding the Unicode
\u2066when we send the message, my proposal is to add it before starting to write and when the user is using Android.Please see how it looks in Android:
Android.chat.messgage.gets.displayed.from.right.to.left.done.mov
Yes that is what we are doing using the convertToLTRForComposer function. We are not adding it when we send the message, we add it as we start to write.
@johncschuster @allroundexperts this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
@johncschuster @allroundexperts this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
@johncschuster @allroundexperts this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
@HardikChoudhary24, we are adding the Unicode
\u2066when we send the message, my proposal is to add it before starting to write and when the user is using Android. Please see how it looks in Android: Android.chat.messgage.gets.displayed.from.right.to.left.done.movYes that is what we are doing using the
convertToLTRForComposerfunction. We are not adding it when we send the message, we add it as we start to write.
As far as I can see we are using this function to do what you say: https://github.com/Expensify/App/blob/0d048314505f20f1c77c3d27ba3845f566943ddb/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js#L230
But this function for Android returns the same text (text) => text:
https://github.com/Expensify/App/blob/0d048314505f20f1c77c3d27ba3845f566943ddb/src/libs/convertToLTRForComposer/index.android.ts#L7
Perhaps the confusion is because there is another function with a similar name that does what you say, which is this one: https://github.com/Expensify/App/blob/main/src/libs/convertToLTR/index.android.ts
PD: When using Android we can't add the Unicode when the user is writing because the input control does not change its behavior, when must do that before writing see what I mean:
Unicode added before writing (in Android):
https://github.com/Expensify/App/assets/5216036/09f46832-629c-45ec-9cfb-311728fe6f3e
@HardikChoudhary24 Can you please share the link to that conversation? I would like to go through it once before choosing the way forward here. Thanks