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

Magic code blur #28711

Merged
merged 25 commits into from
Nov 28, 2023
Merged

Magic code blur #28711

merged 25 commits into from
Nov 28, 2023

Conversation

wojtus7
Copy link
Contributor

@wojtus7 wojtus7 commented Oct 3, 2023

Details

This PR is a direct continuation of the PR that got reverted here.

It should his two release blockers:
#28494
#28590

Additionally resolve issue:
#26090

Description:
In order to make blur possible I needed to refactor the magic component. Instead of 6 separate text inputs there is only one wrapped inside TapGestureHandler that determine which number should be inputed. This resulted is some code that is simpler, taps are handled by gesture handler and right-click/context menu/context is handled by native text input. but at the same time created small issue that paste button shows only on the beginning of the input.

Fixed Issues

$ #18244
PROPOSAL: #18244 (comment)

Tests

  1. Log out
  2. Provide email address
  3. Try to break the magic code input (Click at random places, use arrows, backspace, change tabs and go back on web etc)
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Log out
  2. Provide email address
  3. Try to break the magic code input (Click at random places, use arrows, backspace, change tabs and go back on web etc)
  • 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 / Chrome
    • iOS / native
    • iOS / 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 verified the translation was requested/reviewed 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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.js 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 a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
      • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(themeColors.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 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.
  • 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
bez.nazwy.mov
Mobile Web - Chrome
Screenrecorder-2023-08-01-17-22-47-275.mp4
Mobile Web - Safari
Nagranie.z.ekranu.2023-08-1.o.14.42.25.mov
Desktop
bez.nazwy.mov
iOS
Nagranie.z.ekranu.2023-08-1.o.14.44.35.mov
Android
Nagranie.z.ekranu.2023-08-1.o.14.41.23.mov

@wojtus7 wojtus7 requested a review from a team as a code owner October 3, 2023 11:03
@melvin-bot melvin-bot bot removed the request for review from a team October 3, 2023 11:03
@melvin-bot
Copy link

melvin-bot bot commented Oct 3, 2023

@Santhosh-Sellavel 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]

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 3, 2023

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Oct 4, 2023

@wojtus7 What's the new fix for the two blockers, can you explain for me please?

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 5, 2023

@Santhosh-Sellavel

Issue #28494:

So the problem here is that the code you get from SMS is not pasted but very rapidly inputed on the keyboard. In this implementation of magic input I get the value and clear the input after user type anything. If user paste anything I get 6 digits and use it and then clear input. The way iOS rapidly input new digits from SMS is breaking because it inputs the values so fast that react doesn't have time to clear the input because useState is async and takes a little time. So for code: 123456 the input in magic code was: 112123 because every change of the input was 1 -> 12 -> 123 -> 1234 and every state of the input was interpreted as pasted code.

The answer was to create new ref const lastValue = useRef(); that will hold last input value and remove the shared beginning. If the code would be 123456 then for 1 -> 12 it would recognise the clear of the input did not happen and remove it from the string and just use 2.

At the same time we can't just not clear the input because the paste button on mobile devices will show in random places on the input not just on the first space :(

Answer for #28590 was just add focus() after modal closure

@Santhosh-Sellavel
Copy link
Collaborator

@wojtus7 Sorry for the delay, please resolve conflicts!

@Santhosh-Sellavel
Copy link
Collaborator

bump @wojtus7

@dangrous
Copy link
Contributor

hi, just letting y'all know I'm back from OOO and happy to review this whenever!

@dangrous
Copy link
Contributor

@wojtus7 I'd love to get this merged this week - do you have time to resolve conflicts and get this ready to review again? Thank you!

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 23, 2023

Hi @dangrous Today I'm first day back after being OOO for 2 weeks. I started to work on it right away and have all conflicts resolved but my GPG stopped working after not using Mac for some reason and trying to figure it out. Working on it right now, will push the changes whenever it's resolved and will do my best to make this PR merge this week!

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 23, 2023

@Santhosh-Sellavel all conflicts resolved!

@dangrous
Copy link
Contributor

Thank you @wojtus7 ! @Santhosh-Sellavel let us knwo if you have time to review today or tomorrow - thank you!

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Oct 25, 2023

TestFails on Android.

The keyboard disappears immediately when magic code input is presented

Screen.Recording.2023-10-26.at.12.08.38.AM.mov

@Santhosh-Sellavel
Copy link
Collaborator

This #28590 is not resolved

Screen.Recording.2023-10-26.at.12.24.52.AM.mov

@Santhosh-Sellavel
Copy link
Collaborator

@wojtus7
#26090 This is not resolved either

Screen_Recording_20231026_004910_New.Expensify.Dev.mp4

🔴 🔴 While testing found even a weirder case was able to enter more than 6 numbers but it changed only the last digit and the code was not submitted at all.

Screen_Recording_20231026_005218_New.Expensify.Dev.mp4

cc: @dangrous

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 25, 2023

Hmm. I guess some things break after the main merge or I am going crazy 😞
I'm looking at thise things right now

@Santhosh-Sellavel about:
"🔴 🔴 While testing found even a weirder case was able to enter more than 6 numbers but it changed only the last digit and the code was not submitted at all."

I think this is caused by and the auto submit feature being turn off after one time:
#29731

@wojtus7
Copy link
Contributor Author

wojtus7 commented Oct 27, 2023

TestFails on Android.

The keyboard disappears immediately when magic code input is presented

Screen.Recording.2023-10-26.at.12.08.38.AM.mov

I think this is more complex than that. I tested it a lot and it happen in a lot of places and not only in the way you described but also can happen when go back a screen then the email input fails, and sometimes the error doesn't happen at all.
Trying to fix it locally in magic code but maybe this is some navigation issue?

Nagranie.z.ekranu.2023-10-27.o.19.59.15.mov

@Santhosh-Sellavel
Copy link
Collaborator

@wojtus7 @dangrous @kosmydel

Mostly looks good. While testing today I ran into this issue while testing on Android Alone.

Tested this issue #28590. Focus is set correctly but the keyboard is not shown on the Android

Screen.Recording.2023-11-15.at.11.23.43.PM.mov

This is NAB as it is specific to a platform and can be handled as a follow-up.

Basic cases pass for me, so I'm good with approving this. But I couldn't test this issue on iOS Simulator can you test this please @dangrous iPhone, thanks!

@dangrous
Copy link
Contributor

Oh hm I'm not sure I can test that even with a physical iPhone since I need it to text me and I don't think it will... Let me investigate.

@dangrous
Copy link
Contributor

In the meantime, if we CAN find a fix for the keyboard thing you mentioned that would be ideal, but yeah I don't think it's a blocker

@kosmydel
Copy link
Contributor

In the meantime, if we CAN find a fix for the keyboard thing you mentioned that would be ideal, but yeah I don't think it's a blocker

I've fixed this issue here, pulled main & resolved conflicts.

Video:

fix-android.mov

I've tested the magic code, but I couldn't test the OTP auto-fill functionality (I can't send text messages to the testing devices that I have).

cc @Santhosh-Sellavel for another review

@dangrous
Copy link
Contributor

Okay I managed to set up getting texts on my physical iOS device.

BUT - both on staging, main, and this branch - the phone does not try to autofill from a text anymore - I don't get the prompt. Can one of you possibly try on staging and see if it's my phone or something else? It does look like the messaging changed since that bug was filed, so that could be it.

If you can't, I can ask around internally, too. Thanks!

@Santhosh-Sellavel
Copy link
Collaborator

@dangrous I can't test this case alone, please ask internally.

@dangrous
Copy link
Contributor

Okay, I figured it out! Seems to work well.

@kosmydel
Copy link
Contributor

Hey, when can I expect another round of review? @Santhosh-Sellavel @dangrous

@dangrous
Copy link
Contributor

@Santhosh-Sellavel are you able to test/review again? The iOS issue seems to be solved with this PR.

@Santhosh-Sellavel
Copy link
Collaborator

AFK today, will do tomorrow.

@Santhosh-Sellavel
Copy link
Collaborator

On it now again!

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

LGTM, tests well!

@melvin-bot melvin-bot bot requested a review from dangrous November 23, 2023 17:20
Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

Two minor clarifications, otherwise this is looking good!

Comment on lines 308 to 310
setInput(TEXT_INPUT_EMPTY_STATE);
setFocusedIndex(newFocusedIndex);
setEditIndex(newFocusedIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

We use these three lines in a number of places - might it be good to separate them out into a helper function?

@@ -181,9 +233,12 @@ function MagicCodeInput(props) {
return;
}

const addedValue =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment to explain this? It's very confusing to look at, haha. Also some parentheses around the boolean section might help.

Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

love it!

@dangrous
Copy link
Contributor

Okay, going to merge, let's be sure to watch this for bugs but I think we're going to be good this time.

@@ -264,6 +264,11 @@ class ContactMethodDetailsPage extends Component {
title={this.props.translate('contacts.removeContactMethod')}
onConfirm={this.confirmDeleteAndHideModal}
onCancel={() => this.toggleDeleteModal(false)}
onModalHide={() => {
InteractionManager.runAfterInteractions(() => {
this.validateCodeFormRef.current.focusLastSelected();
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 crash. Now deploy blocker - #32181
@wojtus7 are you able to raise quick PR?

crash

Copy link
Contributor

Choose a reason for hiding this comment

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

I can handle the fix if need be but if you're around @wojtus7 that would be great!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey, @wojtus7 is not here. I can help with this one in an hour or two.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can help too )

Copy link
Contributor

Choose a reason for hiding this comment

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

Working on the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for jumping in @kosmydel! We'll be ready to review whenever

Copy link
Contributor

Choose a reason for hiding this comment

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

PR

I'm recording videos, however, I have a rate limit for adding new contact methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

The PR is ready :)
cc @situchan @dangrous

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.4.5-7 🚀

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

}));

useFocusEffect(
useCallback(() => {
if (!inputValidateCodeRef.current) {
return;
}
if (focusTimeoutRef.current) {
clearTimeout(focusTimeoutRef.current);
}
focusTimeoutRef.current = setTimeout(inputValidateCodeRef.current.focus, CONST.ANIMATED_TRANSITION);
Copy link
Contributor

@alitoshmatov alitoshmatov Dec 29, 2023

Choose a reason for hiding this comment

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

focusLastSelected should have been used also here, like this:
focusTimeoutRef.current = setTimeout(inputValidateCodeRef.current.focusLastSelected, CONST.ANIMATED_TRANSITION);

This caused issue - #33170

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.

8 participants