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

Use simple styles for code blocks in Native platforms #56924

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fabioh8010
Copy link
Contributor

@fabioh8010 fabioh8010 commented Feb 17, 2025

Explanation of Change

This PR fixes code block misalignments in native platforms by simplifying the stylings for these platforms. For a follow-up we will work in a proper fix for it inside react-native.

Fixed Issues

$ #53458
PROPOSAL: #53458 (comment)

Tests

For Android/iOS

  1. Go to any chat.
  2. Send a message that contains inline code blocks and emojis e.g. Lorem ipsum `dolor 🚀` sit amet, con`s``e`ctetur `adipiscing elit, sed do eiusmod tempor incididunt` ut labore et dolore `magna` ali`q`u`a`. 🚀
  3. Assert a different font and background are being applied to the code blocks and they are properly aligned with the normal text.
  4. Go to Settings and switch the Theme.
  5. Go to the chat again and assert it's using the corresponding styles from that theme.

For the other Platforms

  1. Go to any chat.
  2. Send a message that contains inline code blocks and emojis e.g. Lorem ipsum `dolor 🚀` sit amet, con`s``e`ctetur `adipiscing elit, sed do eiusmod tempor incididunt` ut labore et dolore `magna` ali`q`u`a`. 🚀
  3. Assert the same code block stylings as we have today are being used and they are properly aligned with the normal text.
  4. Go to Settings and switch the Theme.
  5. Go to the chat again and assert it's using the corresponding styles from that Theme.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests.

QA Steps

Same as Tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2025-02-18.at.18.45.09-compressed.mov
Android: mWeb Chrome
Screen.Recording.2025-02-18.at.18.50.46-compressed.mov
iOS: Native
Screen.Recording.2025-02-18.at.19.04.51-compressed.mov
iOS: mWeb Safari
Screen.Recording.2025-02-18.at.19.08.04-compressed.mov
MacOS: Chrome / Safari
Screen.Recording.2025-02-18.at.19.09.15-compressed.mov
Screen.Recording.2025-02-18.at.19.10.22-compressed.mov
MacOS: Desktop
Screen.Recording.2025-02-18.at.19.13.16-compressed.mov

@fabioh8010 fabioh8010 changed the title [WIPUse simple styles for code blocks in Native platforms [WIP] Use simple styles for code blocks in Native platforms Feb 17, 2025
@fabioh8010 fabioh8010 marked this pull request as ready for review February 17, 2025 09:51
@fabioh8010 fabioh8010 requested review from a team as code owners February 17, 2025 09:51
@melvin-bot melvin-bot bot requested review from allgandalf and removed request for a team February 17, 2025 09:51
Copy link

melvin-bot bot commented Feb 17, 2025

@allgandalf Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@shawnborton
Copy link
Contributor

Will trigger a test build for us, cc @Expensify/design

@allgandalf
Copy link
Contributor

@shawnborton can you trigger a build please

@shawnborton
Copy link
Contributor

shawnborton commented Feb 18, 2025

Oops sorry about that, I had forgotten the label. Trying again now!

Copy link
Contributor

🚧 @shawnborton has triggered a test build. You can view the workflow run here.

This comment has been minimized.

@shawnborton
Copy link
Contributor

Probably need to merge main on this one?

@fabioh8010
Copy link
Contributor Author

working on it – will prepare the PR for review and add screenshots/test steps

@fabioh8010 fabioh8010 changed the title [WIP] Use simple styles for code blocks in Native platforms Use simple styles for code blocks in Native platforms Feb 18, 2025
@fabioh8010
Copy link
Contributor Author

@shawnborton @allgandalf PR is ready for complete review.

Copy link
Contributor

🚧 @shawnborton has triggered a test build. You can view the workflow run here.

@shawnborton
Copy link
Contributor

I triggered a new test build, let's see what happens.

In the meantime, @fabioh8010 one thing I notice here is that it feels like the text sits far down within the highlighted area:
CleanShot 2025-02-18 at 21 28 25@2x

Meaning, it feels like there is more BG color above the text than below it. Anything we can do to adjust that? Does the inline code have the same line height as the other text (20px)?

Copy link
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪

Android 🤖 iOS 🍎
https://ad-hoc-expensify-cash.s3.amazonaws.com/android/56924/index.html ❌ FAILED ❌
Android The QR code can't be generated, because the iOS build failed
Desktop 💻 Web 🕸️
https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/56924/NewExpensify.dmg https://56924.pr-testing.expensify.com
Desktop Web

👀 View the workflow run that generated this build 👀

@shawnborton
Copy link
Contributor

Dang, I think all iOS adhoc builds have been busted today... might want to check in the open source room to see what is going on there.

@fabioh8010
Copy link
Contributor Author

I triggered a new test build, let's see what happens.

In the meantime, @fabioh8010 one thing I notice here is that it feels like the text sits far down within the highlighted area: CleanShot 2025-02-18 at 21 28 25@2x

Meaning, it feels like there is more BG color above the text than below it. Anything we can do to adjust that? Does the inline code have the same line height as the other text (20px)?

@shawnborton These are the styles that are being passed to the code block Text in native:

 (NOBRIDGE) LOG  boxModelStyle {"backgroundColor": "#072419", "borderBottomColor": "#1A3D32", "borderBottomLeftRadius": 5, "borderBottomRightRadius": 5, "borderBottomWidth": 1, "borderLeftColor": "#1A3D32", "borderLeftWidth": 1, "borderRightColor": "#1A3D32", "borderRightWidth": 1, "borderTopColor": "#1A3D32", "borderTopLeftRadius": 5, "borderTopRightRadius": 5, "borderTopWidth": 1, "paddingLeft": 5, "paddingRight": 5}
 (NOBRIDGE) LOG  textStyle {"color": "#E7ECE9", "fontFamily": "Expensify Mono", "fontSize": 13, "fontStyle": "normal", "fontWeight": "400", "lineHeight": 20, "writingDirection": "ltr"}

As you can see line height is 20px. I think this impression you had is because of the different font we use for inline code blocks (Expensify Mono). Check out the difference if I remove this font in native.

With Expensify Mono font With normal font
Screenshot 2025-02-20 at 11 12 26 Screenshot 2025-02-20 at 11 11 59

@shawnborton
Copy link
Contributor

Hmm are you sure? Doesn't it feel like there is much more space about the d in the first line compared to the second line where it feels like there is much more space above it?

CleanShot 2025-02-20 at 12 11 36@2x

You can see they aren't the same:
CleanShot 2025-02-20 at 12 12 42@2x

Can you look into that for us?

@fabioh8010
Copy link
Contributor Author

@shawnborton Ok, now I understand what you are mentioning, I'm going to have a look today!

@fabioh8010
Copy link
Contributor Author

@shawnborton The problem seems to happen when you have emojis inside the code blocks.

Screenshot 2025-02-24 at 16 51 14

It will happen even if I remove all styles from the code block Text components. I think it's some internal problem caused by the nested Text components used to render the code blocks.

Unfortunately I couldn't find the root cause yet. Do you think this is a blocker for now or we can proceed with this fix?

@shawnborton
Copy link
Contributor

Hmm I think we can proceed, but let's definitely keep investigating and see if we can solve it.

@allgandalf
Copy link
Contributor

@fabioh8010 is this ready for final review ?

@fabioh8010
Copy link
Contributor Author

@allgandalf Yes

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

Successfully merging this pull request may close these issues.

3 participants