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

Standardize keyboard libs for determining when the keyboard is open #13629

Merged
merged 7 commits into from
Dec 19, 2022

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Dec 15, 2022

Fixed Issues

$ #13582

Tests

For web/desktop:

  1. Edit a comment that you have sent
  2. Verify that pressing the escape key cancels the comment editing form
  3. Verify that pressing the enter key submits the comment editing form

For all mobile platforms:

  1. Edit a comment that you have sent
  2. Verify that tapping the enter key on the keyboard does not submit the editing form
  • Verify that no errors appear in the JS console

Offline tests

Same as above

QA Steps

Same as above

  • 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 is localized by adding it to src/languages/* files and using the translation method
    • 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 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
2022-12-16_09-38-42.mp4
Mobile Web - Chrome
2022-12-16_09-43-42.mp4
Mobile Web - Safari
2022-12-16_09-42-22.mp4
Desktop
2022-12-16_09-39-12.mp4
iOS
2022-12-16_09-41-21.mp4
Android
2022-12-16_09-43-01.mp4

@tgolen tgolen self-assigned this Dec 15, 2022
@jasperhuangg jasperhuangg self-requested a review December 16, 2022 03:56
@jasperhuangg
Copy link
Contributor

jasperhuangg commented Dec 16, 2022

Self-requesting for review to keep this in my K2, but you should still Pullerbear someone since I'm gonna be OOO starting next week!

@tgolen tgolen changed the title Tgolen standardize keyboard libs Standardize keyboard libs for determining when the keyboard is open Dec 16, 2022
@@ -285,6 +284,7 @@ ReportActionItemMessageEdit.defaultProps = defaultProps;
export default compose(
withLocalize,
withWindowDimensions,
withKeyboardState,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I added this HOC, since ReportActionItemMessageEdit has it's own forwarded ref, I found out that this HOC isn't properly handling forwarded refs like the withWindowDimensions HOC. This caused me to do a refactoring of withKeyboardState so that it will better handle the forwarded refs.

@tgolen tgolen marked this pull request as ready for review December 16, 2022 16:59
@tgolen tgolen requested a review from a team as a code owner December 16, 2022 16:59
@melvin-bot melvin-bot bot requested review from stitesExpensify and thesahindia and removed request for a team December 16, 2022 17:00
@melvin-bot
Copy link

melvin-bot bot commented Dec 16, 2022

@thesahindia @stitesExpensify 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]

Copy link
Contributor

@stitesExpensify stitesExpensify 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!

@@ -241,15 +240,15 @@ class ReportActionItemMessageEdit extends React.Component {
onFocus={() => {
this.setState({isFocused: true});
ReportScrollManager.scrollToIndex({animated: true, index: this.props.index}, true);
toggleReportActionComposeView(false, VirtualKeyboard.shouldAssumeIsOpen());
toggleReportActionComposeView(false, this.props.isSmallScreenWidth);
Copy link
Member

Choose a reason for hiding this comment

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

The main composer will hide when editing the message in decreased screen size on web/Desktop. Are we fine with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I am OK with that. I think it's closer to what we want anyway where those smaller windows would act closer to our mobile platforms. Thanks for asking!

@thesahindia
Copy link
Member

Reviewer Checklist

  • 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:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • 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 is localized by adding it to src/languages/* files and using the translation method
    • 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 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 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 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.
  • 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-20.at.3.21.39.AM.mov
Mobile Web - Chrome
Screenrecording_20221220_031848.mp4
Mobile Web - Safari
Screen.Recording.2022-12-20.at.3.10.25.AM.mov
Desktop
Screen.Recording.2022-12-20.at.3.20.58.AM.mov
iOS
Screen.Recording.2022-12-20.at.3.06.59.AM.mov
Android
Screen.Recording.2022-12-20.at.3.12.11.AM.mov

Copy link
Member

@thesahindia thesahindia 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 and works well!

C+ reviewed 🎀👀🎀

cc: @stitesExpensify

@stitesExpensify stitesExpensify merged commit b66c24d into main Dec 19, 2022
@stitesExpensify stitesExpensify deleted the tgolen-standardize-keyboard-libs branch December 19, 2022 22:06
@OSBotify
Copy link
Contributor

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

@github-actions
Copy link
Contributor

Performance Comparison Report 📊

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Duration
TTI 824.917 ms → 844.215 ms (+19.298 ms, +2.3%)
runJsBundle 188.379 ms → 198.156 ms (+9.777 ms, +5.2%)
nativeLaunch 9.656 ms → 10.484 ms (+0.828 ms, +8.6%)
regularAppStart 0.018 ms → 0.017 ms (-0.001 ms, -4.4%)
Show details
Name Duration
TTI Baseline
Mean: 824.917 ms
Stdev: 44.694 ms (5.4%)
Runs: 741.2374490001239 764.889053999912 772.3039839998819 780.1286289999261 785.1539280000143 788.7567079998553 793.4638109998778 794.262511999812 794.3674329998903 798.6093609998934 799.1349530001171 800.7570299999788 805.306596999988 805.8062559999526 812.9872849998064 814.3451279997826 818.4838040000759 820.1804530001245 824.8210330000147 825.2127060000785 826.8183729997836 833.251126000192 847.5581620000303 865.3537119999528 873.7507850001566 875.2617219998501 880.6736150002107 895.558197000064 901.6035960000008 914.8025770001113 917.5739110000432

Current
Mean: 844.215 ms
Stdev: 33.518 ms (4.0%)
Runs: 800.7379850000143 801.4296079999767 806.7514960002154 807.9530770001002 809.925191000104 811.9810159998015 812.5790710002184 814.4581160000525 815.7936320002191 822.8755439999513 825.3304420001805 826.3428589999676 828.9255209998228 830.6293759997934 834.2881120000966 834.6151609998196 836.6254070000723 837.6261359998025 840.4762189998291 844.8786499998532 857.3338930001482 860.6185880000703 865.6367330001667 871.594628999941 877.3690949999727 878.764545999933 887.8568449998274 898.2377240001224 908.3464930001646 910.0843569999561 910.5904489997774
runJsBundle Baseline
Mean: 188.379 ms
Stdev: 16.255 ms (8.6%)
Runs: 158 160 167 167 169 170 179 179 182 183 183 183 183 187 189 190 191 193 193 193 196 197 200 204 205 207 212 219 224

Current
Mean: 198.156 ms
Stdev: 20.851 ms (10.5%)
Runs: 174 174 177 177 179 180 181 182 183 184 185 185 187 187 187 189 191 192 196 200 201 204 206 208 215 219 223 224 228 229 232 262
nativeLaunch Baseline
Mean: 9.656 ms
Stdev: 1.492 ms (15.4%)
Runs: 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 11 11 11 11 11 12 12 12 12 13

Current
Mean: 10.484 ms
Stdev: 2.408 ms (23.0%)
Runs: 8 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 12 13 13 14 14 14 16 17
regularAppStart Baseline
Mean: 0.018 ms
Stdev: 0.002 ms (12.5%)
Runs: 0.01509599993005395 0.015298999845981598 0.015381000004708767 0.015665999613702297 0.015910000074654818 0.015950000379234552 0.01599099999293685 0.016276000067591667 0.016276000067591667 0.016479999758303165 0.016480000223964453 0.0165200000628829 0.016561000142246485 0.0167239997535944 0.016763999592512846 0.01680499967187643 0.016927000135183334 0.017210999969393015 0.017537999898195267 0.017822000198066235 0.017822000198066235 0.017862000036984682 0.018106999807059765 0.01875900011509657 0.018920999951660633 0.019652999937534332 0.0197350000962615 0.02038599969819188 0.022909000050276518 0.02298999996855855 0.0235190000385046

Current
Mean: 0.017 ms
Stdev: 0.001 ms (4.5%)
Runs: 0.015584999695420265 0.015705999918282032 0.015746999997645617 0.01607299968600273 0.016153999604284763 0.01615400006994605 0.016194999683648348 0.01623600022867322 0.01631700014695525 0.01672299997881055 0.016724000219255686 0.016763999592512846 0.016764000058174133 0.0168869998306036 0.0168869998306036 0.016966999974101782 0.017008000053465366 0.017130999825894833 0.017293000128120184 0.017375000286847353 0.017416000366210938 0.017455999739468098 0.017659999895840883 0.017700000200420618 0.017862999811768532 0.01798499980941415 0.01814799988642335 0.018432999961078167

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @stitesExpensify in version: 1.2.42-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @yuwenmemon in version: 1.2.42-2 🚀

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

@@ -430,7 +431,8 @@ class ReportActionCompose extends React.Component {
* @param {Object} e
*/
triggerHotkeyActions(e) {
if (!e || VirtualKeyboard.shouldAssumeIsOpen()) {
// Do not trigger actions for mobileWeb or native clients that have the keyboard open because for those devices, we want the return key to insert newlines rather than submit the form
if (!e || this.props.isSmallScreenWidth || this.props.isKeyboardShown) {
Copy link
Member

@parasharrajat parasharrajat Dec 28, 2022

Choose a reason for hiding this comment

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

Did we test it against resized the Desktop app? I think we do not want that to behave like mobile app as that does not have Virtual Keyboard.

cc: @thesahindia

Copy link
Member

Choose a reason for hiding this comment

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

It is expected (#13629 (comment), slack thread)

Copy link
Member

@parasharrajat parasharrajat Dec 28, 2022

Choose a reason for hiding this comment

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

Thanks for sharing. Hmm, I can't give my full approval here without testing but let's hope there are no regressions from this. Anyways, you approved so this should be OK.

@@ -13,6 +14,7 @@ const propTypes = {
onToggleKeyboard: PropTypes.func,

...windowDimensionsPropTypes,
...keyboardStatePropTypes,
Copy link
Member

@rushatgabhane rushatgabhane Feb 6, 2023

Choose a reason for hiding this comment

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

Hey, we caused a console error with this change. #13862

Why? keyboardStatePropTypes contains native only props but being used for all platforms.

@@ -430,7 +431,8 @@ class ReportActionCompose extends React.Component {
* @param {Object} e
*/
triggerHotkeyActions(e) {
if (!e || VirtualKeyboard.shouldAssumeIsOpen()) {
// Do not trigger actions for mobileWeb or native clients that have the keyboard open because for those devices, we want the return key to insert newlines rather than submit the form
if (!e || this.props.isSmallScreenWidth || this.props.isKeyboardShown) {
Copy link
Member

Choose a reason for hiding this comment

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

Hi, just dropping a tiny tiny note that when a desktop window is resized to mobile, the Enter key behaviour changes and isn't consistent with full sized window.

Causing bug - #17206

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.

7 participants