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

Scroll to the right spot when clicking "Fix Errors" #12954

Merged
merged 14 commits into from
Dec 5, 2022
Merged

Conversation

Gonals
Copy link
Contributor

@Gonals Gonals commented Nov 23, 2022

Details

Fixed Issues

$ #12942

Tests

  1. Go to Settings => Payments => Add a debit card
  2. Without entering any data, click "Save"
  3. Click on 'fix the errors' button
  4. System should focus on the first input and scroll to it with no lines cut
  5. Populate the first field and make the screen small enough so that not all fields fit in it.
  6. Click 'fix errors again'
  7. You should now get scrolled to the second field (and it should get focused too)
  • Verify that no errors appear in the JS console

Offline tests

Not relevant

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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for expected offline behavior are in the Offline steps section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web Screen Shot 2022-11-23 at 1 18 07 PM
Desktop Screen Shot 2022-11-23 at 4 43 50 PM
iOS Screen Shot 2022-11-23 at 3 47 49 PM
Android

@Gonals Gonals requested a review from a team as a code owner November 23, 2022 14:43
@Gonals Gonals self-assigned this Nov 23, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 23, 2022

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@melvin-bot melvin-bot bot requested review from danieldoglas and rushatgabhane and removed request for a team November 23, 2022 14:44
@melvin-bot
Copy link

melvin-bot bot commented Nov 23, 2022

@rushatgabhane @danieldoglas One of you needs to 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]

@rushatgabhane
Copy link
Member

rushatgabhane commented Nov 23, 2022

@Gonals oops, looks like we have some lint errors

@@ -245,6 +246,10 @@ class Form extends React.Component {
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
keyboardShouldPersistTaps="handled"
ref={el => this.form = el}
onLayout={(event) => {
this.inputPosition = event.nativeEvent.layout.y + 1;
Copy link
Member

Choose a reason for hiding this comment

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

@Gonals why the +1?

suggestion: add a comment for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, adding a comment.

Without the +1, we'll scroll right to the border of the component, potentially covering the upper border

Copy link
Member

Choose a reason for hiding this comment

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

thanks, that makes sense!

@Gonals
Copy link
Contributor Author

Gonals commented Nov 23, 2022

Checks passing! I'm having trouble testing on Android today, so if you could give it a try there, it'd be awesome!

@@ -259,6 +266,9 @@ class Form extends React.Component {
const errors = !_.isEmpty(this.state.errors) ? this.state.errors : this.props.formState.errorFields;
const focusKey = _.find(_.keys(this.inputRefs), key => _.keys(errors).includes(key));
this.inputRefs[focusKey].focus();
this.inputRefs[focusKey].measure((fx, fy, width, height, px, py) => {
this.form.scrollTo({y: py - this.viewPosition, animated: false});
Copy link
Member

@rushatgabhane rushatgabhane Nov 23, 2022

Choose a reason for hiding this comment

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

@danieldoglas @Gonals I'm not sure how to handle this, but we need an enhancement.

Problem: On mobile, when the keyboard is open we scroll to a position that's hidden under the keyboard.

Solution 1: Always scroll to a position so that the input is just above the keyboard.
Solution 2: Always scroll to a position so that the input is at the very top of screen.
...??

Screen.Recording.2022-11-23.at.9.32.49.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, nice catch! Looking into it

Copy link
Member

@rushatgabhane rushatgabhane Nov 23, 2022

Choose a reason for hiding this comment

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

If it's too complicated to calculate the scroll postion / detect if the keyboard is open, we might need keyboard avoiding view experts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I changed things around a little bit and I think it is working more smoothly now!
Quick thing, I see you added a bunch of Name fields for testing. Make sure you give them different inputID, as those are involved when determining where to scroll and might be the reason of the weird behavior you saw

@rushatgabhane
Copy link
Member

I'm having trouble testing on Android today

no worries, I'll take care of it

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

Quick thing, I see you added a bunch of Name fields for testing. Make sure you give them different inputID, as those are involved when determining where to scroll and might be the reason of the weird behavior you saw

thanks @Gonals , I'll make sure to use unique ids.

prerequisites:

  1. increase the page height. This can be done by inserting a bunch of dummy input fields just after name. make sure to use unique ids.
  2. use iOS and make sure the virtual keyboard is open by pressing ⌘ + K

bug: focused input is behind the keyboard

steps:

  1. click on zip code
  2. click on expensify password
  3. click on fix the errors
  4. scroll down and click on fix the errors again.

Expected: zip code input is above the keyboard
Actual: zip code input is behind the keyboard

Screen.Recording.2022-11-24.at.2.51.16.PM.mov

@Gonals
Copy link
Contributor Author

Gonals commented Nov 25, 2022

Ok! The math was becoming a pain, so I completely changed the approach and it seems to be working! Ready for another look!

@rushatgabhane
Copy link
Member

rushatgabhane commented Nov 28, 2022

@danieldoglas LGTM! 🎉

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

@Gonals noticed three bugs on Android

  1. Sometimes the form can't be scrolled on clicking fix errors for expiry date input (0:10 mark in video)
  2. On clicking fix errors, the password input is hidden behind the keyboard (0:17 mark).
  3. Click on password field and the save button is always behind the keyboard (0:39 mark)
WhatsApp.Video.2022-11-29.at.00.34.35.mp4

@Gonals
Copy link
Contributor Author

Gonals commented Nov 29, 2022

@Gonals noticed three bugs on Android

  1. Sometimes the form can't be scrolled on clicking fix errors for expiry date input (0:10 mark in video)
  2. On clicking fix errors, the password input is hidden behind the keyboard (0:17 mark).
  3. Click on password field and the save button is always behind the keyboard (0:39 mark)

WhatsApp.Video.2022-11-29.at.00.34.35.mp4

Hi @rushatgabhane,

  1. This does not seem related to this PR. I haven't been able to reproduce it, but it may be device-specific. In any case, I don't think it is caused by this.
  2. I'm not sure I'm seeing this one in the video. The date is wrong, so that's where you are being scrolled to, right? That's the reason password gets covered
  3. This one I can reproduce, but it happens in main too. Basically, any time password is selected. I don't think this is a bug, but, in any case, it is not related to this PR.

@rushatgabhane
Copy link
Member

rushatgabhane commented Nov 30, 2022

I'm not sure I'm seeing this one in the video. The date is wrong, so that's where you are being scrolled to, right? That's the reason password gets covered

Oh yeah, you're right! I was mistaken that it should scroll to password.

it is not related to this PR

agree!

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

Reviewer Checklist

@danieldoglas LGTM!

@Gonals fantastic work in changing to a new approach! ✨

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2022-12-01.at.1.57.45.AM.mov
Mobile Web - Chrome
Screen.Recording.2022-12-01.at.2.43.37.AM.mov
Mobile Web - Safari
Screen.Recording.2022-12-01.at.2.00.42.AM.mov
Desktop
Screen.Recording.2022-12-01.at.1.58.50.AM.mov
iOS
Screen.Recording.2022-12-01.at.2.45.21.AM.mov
Android
WhatsApp.Video.2022-12-01.at.02.42.59.mp4

@Gonals
Copy link
Contributor Author

Gonals commented Dec 1, 2022

@danieldoglas All yours!

@Gonals
Copy link
Contributor Author

Gonals commented Dec 5, 2022

@danieldoglas bump!

@danieldoglas
Copy link
Contributor

oops, sorry! Looking into this now!

Copy link
Contributor

@danieldoglas danieldoglas 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

@danieldoglas danieldoglas merged commit 56b69d4 into main Dec 5, 2022
@danieldoglas danieldoglas deleted the alberto-scroll branch December 5, 2022 16:47
@OSBotify
Copy link
Contributor

OSBotify commented Dec 5, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@luacmartins
Copy link
Contributor

@Gonals I'm seeing this error on the VBA page. See this issue #13344
Screenshot_1670283345

The text elements don't have any props.

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Dec 7, 2022

I think this PR caused this regression (not yet in staging): #13401

If I revert the changes, the spinner is back at the middle of the page.

@rushatgabhane
Copy link
Member

That's so interesting. really curious to know why it's affecting the spinner for some empty page that's a form child

Comment on lines +112 to +119
setPosition(element, position) {
if (!element.props.inputID && element.props.children) {
_.forEach(element.props.children, (child) => {
this.setPosition(child, position);
});
} else {
this.childPosition[element.props.inputID] = position;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If element.props.inputID is false, but element.props.children is also falsey, then you will enter in the else which I think is wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I put some console logs, and it doesn't happen in the debit card form, but in other forms like opening Personal details it does happen:

element.props.inputID is undefined and element.props.children is also undefined

@aldo-expensify
Copy link
Contributor

Reverting PR here + different fix to achieve the same: #13499

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.2.38-6 🚀

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

@luacmartins
Copy link
Contributor

Just FYI that this PR caused this bug.

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.

6 participants