Skip to content

Conversation

@wgsquayson
Copy link
Contributor

@wgsquayson wgsquayson commented Jul 4, 2025

Explanation of Change

This PR aims to add interactive keyboard dismissal (or pull down to close keyboard) capabilities to the composer screen, specifically the ReportActionsList component and MoneyRequestReportActionsList. In order to do so, it adds:

  • for iOS, a custom useKeyboardHandler and the KeyboardGestureArea component from react-native-keyboard-controller. The iOS implementation animates the list insets using the keyboard height and the scroll position as parameters, as this is the recommended approach from react-native-keyboard-controller.
  • for android and other platforms, only the KeyboardGestureArea component is used, but the gesture does not work on web.

Fixed Issues

$ #54270
PROPOSAL: Adding the react-native-keyboard-controller recommended setup to achieve the interactive keyboard dismissal.

Tests

For Android and iOS

  1. Sign in to the app
  2. Touch/click any of your reports, preferably one that has enough messages to scroll
  3. You should be able to scroll up or down, and whenever you open the keyboard, the scroll position should be preserved
  4. You should be able to pull the composer down on scroll (from its top, like whatsapp) or touch the chat in order to close the keyboard, and the scroll position should be preserved as well
  5. You can write a long text, open the composer as full screen, close the full screen mode, and the scroll position should still be preserved.
  6. When writing a long text, and the composer grows, you should be able to pull down to perform the same as step 4
  7. When exiting the composer screen, the Keyboard should close automatically
  8. Pagination when reaching the list vertical edges while scrolling should work as before

For other platforms

The pull down to dismiss is not applicable, but all steps except 4 and 6 from the android and ios list can be tested here.

PS: I was not able to test on iOS Safari, but i'm guessing it behaves the same as iOS chrome.

Offline tests

Same as tests

QA Steps

Same as tests

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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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
android.mov
Android: mWeb Chrome
chrome.android.mp4
iOS: Native
ios.mov
iOS: mWeb Chrome
chrome.ios.mov
MacOS: Chrome / Safari
web.desktop.mov
MacOS: Desktop
web.desktop.mov

Comment on lines 835 to 819
<KeyboardGestureArea
style={styles.flexGrow1}
offset={90}
interpolator="ios"
textInputNativeID="composer"
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to highlight, that usage of this component will automatically enable interactive dismissal on Android (so we have to test that platform carefully as well).

Also if you discover any kind of bugs/undesired behavior, don't hesitate to remove it and test the implementation on iOS without this component. If KeyboardGestureArea produces any bugs, then let me know and I'll try to fix them!

(posting it here because KeyboardGestureArea relatively new component on iOS and may have some bugs 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it's working alright on android so far!

Comment on lines 835 to 819
<KeyboardGestureArea
style={styles.flexGrow1}
offset={90}
interpolator="ios"
textInputNativeID="composer"
>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't hardcode it? (correct me if I'm wrong)

When the multiline input grows I think it changes its size so we should reflect those changes here?

(but again, correct me if I'm wrong, maybe the approach with growing input has been re-worked recently and now it doesn't change its height if you type a lot of text)

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 changed it to grow according to the composer height :)

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.

am I correct in thinking that this is the PR in which we should remove android:windowSoftInputMode="adjustResize" in both NewDot standalone and HybridApp?

@wgsquayson
Copy link
Contributor Author

Hey @roryabraham sorry about the delay - i'm not sure what android:windowSoftInputMode="adjustResize" does, but i can take a look.

@roryabraham
Copy link
Contributor

roryabraham commented Jul 24, 2025

Disclaimer: It's been a long time since we started working on the react-native-keyboard-controller migration, and I'm writing from what I recall here. My recollection may be flawed. You and @kirillzyusko should investigate further.


If I'm not mistaken, android:windowSoftInputMode is the configuration that enables and disables Android's OS-level keyboard avoidance logic for apps. It works pretty well, but it's also complex for our use-case, because iOS does not have the same feature. So we have some confusing platform fragmentation in place:

  • manually manage keyboard avoidance in the React Native layer on iOS and mobile web
  • no-op on Android and let the OS handle it

Furthermore, if memory serves, android:windowSoftInputMode="adjustResize" does not work with interactive keyboard dismissal. So if that flag is still set in the AndroidManifest, it muddies the water on how keyboard avoidance works on Android.

@kirillzyusko
Copy link
Contributor

@roryabraham we enabled edge-to-edge and kept using adjustResize. Such a combination works very similar to adjustNothing (like iOS works too - all default keyboard handling gets disabled).

So at this point of time all keyboard avoiding is handled by react-native-keyboard-controller (mostly by its KeyboardAvoidingView component), not by OS anymore.

So now we can write cross-platform code that will work identically everywhere, and interactive keyboard dismissal can be implemented on Android too 👀

@wgsquayson
Copy link
Contributor Author

@kirillzyusko legend

@github-actions
Copy link
Contributor

🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions
Copy link
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪
Built from App PR #65517.

Android 🤖 iOS 🍎
https://ad-hoc-expensify-cash.s3.amazonaws.com/android/65517/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/65517/NewExpensify.dmg https://65517.pr-testing.expensify.com
Desktop Web

👀 View the workflow run that generated this build 👀

@mountiny
Copy link
Contributor

@parasharrajat here for a review, please give it a go and report any bugs you find! thanks!

@parasharrajat
Copy link
Member

I will test it shortly...

@parasharrajat
Copy link
Member

Looks like we are still working on some issues and in the process of discussing the implementation.

I will keep a watch on this PR as we progress. Feel free to seek help from me anytime if needed.

@wgsquayson wgsquayson force-pushed the feat/interactive-keyboard-dismissal branch from 04d87d0 to 183f8df Compare August 5, 2025 00:12
Copy link
Contributor

@chrispader chrispader left a comment

Choose a reason for hiding this comment

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

This looks pretty good already! Left some comments around the new implementation that we discussed yesterday.

lastScrollEvent.current = timestamp;
};

useAnimatedReaction(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to manually trigger onScroll here with an animated reaction? Can't we just pass the callback as a prop down to BaseInvertedFlatList -> KeyboardDismissableFlatList which then calls it it alongside the keyboard dismissal logic in a joint callback?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like the idea of having a separate manual trigger for the calling the onScroll callback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be done, i thought about just leaving this here since it was already here

@@ -0,0 +1,127 @@
import PropTypes from 'prop-types';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to have the keyboard dismissal logic in a context? I think this might cause some unnecessary re-renders. Can't we have just move this logic to a hook and then use it in KeyboardDismissableFlatList? This is not used across multiple components, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a hook and it is actually used across some components. I decided to write a context because I wanted to keep the scroll and insets implementation closer to the KeyboardDismissableFlatList component, and other components need access to the values that are updated by this component.

};
});

const onLayoutInternal = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment in ReportActionCompose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is actually needed to track the composer height on this component

@wgsquayson wgsquayson force-pushed the feat/interactive-keyboard-dismissal branch from b8e9059 to 3d938f9 Compare August 7, 2025 02:50
@wgsquayson wgsquayson marked this pull request as ready for review August 7, 2025 02:51
@wgsquayson wgsquayson requested review from a team as code owners August 7, 2025 02:51
@melvin-bot melvin-bot bot requested review from roryabraham and removed request for a team August 7, 2025 02:51
@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2025

@roryabraham 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]

@parasharrajat
Copy link
Member

I will start review now.

@wgsquayson wgsquayson force-pushed the feat/interactive-keyboard-dismissal branch from 2dcb0d7 to a64666a Compare August 7, 2025 23:51
@roryabraham

This comment was marked as outdated.

@mountiny
Copy link
Contributor

Thanks Chris

@chrispader
Copy link
Contributor

chrispader commented Sep 27, 2025

@roryabraham @trjExpensify @parasharrajat i would like to split this PR up into 2 smaller PRs, to prevent this PR from being reverted because of regressions and make review and testing easier:

  1. PR will just add the new components needed for interactive keyboard dismissal: KeyboardDismissableFlatList, CustomAnimatedFlatList copy of Animated.FlatList and other added logic for this feature
  2. PR will actually migrate the ReportActionsView and MoneyRequestReportView to use the new list components.

Does that sound good for you?

@parasharrajat
Copy link
Member

@chrispader I agree.

@chrispader
Copy link
Contributor

@roryabraham @trjExpensify @parasharrajat I've went ahead and split this up into two PRs:

  1. feat: Add components for interactive keyboard dismissal #71438
  2. feat: Migrate lists to interactive keyboard dismissal #71440

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