Skip to content
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 inline code blocks #2527

Merged
merged 8 commits into from
Apr 30, 2021

Conversation

parasharrajat
Copy link
Member

@parasharrajat parasharrajat commented Apr 22, 2021

Please review.

Details

This PR also includes the reverted changes as per the comment #2307 (comment)

Problem

We (Including other contributors) tried using a combination of Text & View tag to achieve the above UI but there are a couple of issues as follows:

  1. Text is rendered as a block box but we want inline text.
  2. In Another way, we can get the inline text but border and border-radius are not being rendered.

How I fixed it?

I had an idea of tokenizing the text. Then apply the style selectively. This is working well. I have made a small snap here.

  1. we create one wrapper component which divides the text into tokens(words) divided based on word break. This component put the text tokens inline into a view and renders it.
  2. We can then pass styles selectively to tokens and manage the border-radius for the first and last tokens.

Fixed Issues

Fixes #986

the issue found here #2307 (comment)

Tests / QA Steps

  • Type a sentence with code block formatting (single ticks) in the middle, like this:
    This is a test to see how code renders in the middle of a sentence on mobile.
  • Notice that it should render inline like normal text.

Tested On

  • iOS
  • Android
  • Web
  • Mobile Web
  • Desktop

Screenshots

Web / Desktop

localhost_8080_r_68438375

Mobile Web

Screenshot_2021-04-23-10-58-51-910_com android chrome

Android

Screenshot_2021-04-23-10-51-07-588_com expensify chat

IOS

iPhone 11 iPhone 8
Simulator Screen Shot - iPhone 11 - 2021-04-23 at 01 02 52 Simulator Screen Shot - iPhone 8 - 2021-04-23 at 01 03 35

@parasharrajat parasharrajat requested a review from a team as a code owner April 22, 2021 02:20
@MelvinBot MelvinBot requested review from jasperhuangg and removed request for a team April 22, 2021 02:20
Comment on lines 7 to 10
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just borderRadius: 0? Why does this have to be included?

Copy link
Member Author

@parasharrajat parasharrajat Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasperhuangg these style props take precedence over borderRadius. Due to the reason we need to specify borderRadius for Web, we can't remove it from the main code styles. But on native, the new implementation only wants border radius for the first and last word. Thus to override it, I have to be specific for each edge.
In Short, borderRadius does not work.

Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat Can we please DRY this up with the following module structure:

src/styles/codeStyles/
---| index.js    // web/desktop/mWeb
---| defaultNativeCodeStyles.js   // all the similar styles between iOS and Android
---| index.ios.js   // import defaultNativeCodeStyles and override what you need
---| index.android.js   // import defaultNativeCodeStyles and override what you need

Also, can you please test on all platforms and provide screenshots for each? Without more context, it seems weird to me that we would be exporting empty objects on web/desktop.

@parasharrajat
Copy link
Member Author

Sure. These styles are only for native platforms as web support the styling natively.

I will provide screenshot for others as well.

@parasharrajat parasharrajat changed the title fix: IOS Inline code block's text is cropping fix inline code blocks Apr 23, 2021
@parasharrajat
Copy link
Member Author

@roryabraham Merged the reverted changes here.

Screenshots updated. Thanks.

src/components/InlineCodeBlock/WrappedText.js Outdated Show resolved Hide resolved
src/components/InlineCodeBlock/WrappedText.js Outdated Show resolved Hide resolved

// Outer View is important to vertically center the Text
<View
// eslint-disable-next-line react/no-array-index-key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this suppression is necessary? I'm confused because you are providing a key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Sorry. Just made few adjustments and forget to Change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, Eslint complains about an array index being used as key I know that is not the case but there is an error. So I had to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat Can you clarify what you mean here? What is the error?

Copy link
Member Author

@parasharrajat parasharrajat Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact error was Array index can't be used as a key. so I have to disable it to use the array index in the key.

src/components/InlineCodeBlock/index.native.js Outdated Show resolved Hide resolved
src/components/InlineCodeBlock/WrappedText.js Outdated Show resolved Hide resolved
parasharrajat and others added 3 commits April 23, 2021 23:10
Co-authored-by: Rory Abraham <47436092+roryabraham@users.noreply.github.com>
@parasharrajat
Copy link
Member Author

Updated. Thanks.

@parasharrajat
Copy link
Member Author

Updated.

Copy link
Contributor

@jasperhuangg jasperhuangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, besides the issue with eslint-disable-next-line that Rory commented on.

@parasharrajat
Copy link
Member Author

@jasperhuangg actually eslint complaints about using the array index into the key, even though I am using the combination to create unique key. So I had to disable the warnings.

@parasharrajat
Copy link
Member Author

@roryabraham Waiting for your input here. Sorry tagged you in a different issue, previously.

Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM and tested well 👍

@parasharrajat
Copy link
Member Author

@jasperhuangg All yours.

@parasharrajat
Copy link
Member Author

@jasperhuangg any input here.

@jasperhuangg
Copy link
Contributor

LGTM! merging

@jasperhuangg jasperhuangg merged commit a656a1e into Expensify:main Apr 30, 2021
@OSBotify
Copy link
Contributor

🚀 Deployed to staging in version: 1.0.34-2🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented May 8, 2021

🚀 Deployed to production in version: 1.0.39-5🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Comment on lines +12 to +14
const codeTextStyle = {
lineHeight: 15,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line height here was not enough and caused a regression #19922 when the inline code contains emojis.

Comment on lines +17 to +19
function getTextMatrix(text) {
return text.split('\n').map(row => _.without(row.split(/(\s)/), ''));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a regression #19922 when using emojis and text the inline code will look misaligned #19922 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocks of quoted text render incorrectly on mobile
5 participants