Skip to content

[HOLD for payment 2025-01-18] [$250] Android - Chat - Unable to close keyboard by tapping outside of it #53196

Closed

Description

@IuliiaHerets

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.67-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y
Email or phone of affected tester (no customers): ibellicotest+41@gmail.com
Issue reported by: Applause Internal Team

Action Performed:

  1. Open the Expensify app.
  2. Open any chat that has messages on it.
  3. Tap on compose box to open keyboard.
  4. Tap outside the keyboard area to close it.
  5. Verify that the keyboard is closed when tapping outside of it.

Expected Result:

Keyboard should be closed when tapping outside of it.

Actual Result:

Keyboard is not closed when tapping outside of it in chats that already have messages. Keyboard closes normally when the chat doesn´t have any message or content on it.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6677688_1732684892160.Tap_Keyboard.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021861915865037036576
  • Upwork Job ID: 1861915865037036576
  • Last Price Increase: 2024-11-27
  • Automatic offers:
    • daledah | Contributor | 105283329
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 27, 2024
  2. melvin-bot commented on Nov 27, 2024

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. gadhiyamanan commented on Nov 27, 2024

    @gadhiyamanan
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    keyboard does not close on Tap outside the keyboard

    What is the root cause of that problem?

    we are using keyboardShouldPersistTaps="handled" props in ReportActionsList.tsx because of that keyboard will not dismiss automatically on Tap outside the keyboard

    <InvertedFlatList
    accessibilityLabel={translate('sidebarScreen.listOfChatMessages')}
    ref={reportScrollManager.ref}
    testID="report-actions-list"
    style={styles.overscrollBehaviorContain}
    data={sortedVisibleReportActions}
    renderItem={renderItem}
    contentContainerStyle={contentContainerStyle}
    keyExtractor={keyExtractor}
    initialNumToRender={initialNumToRender}
    onEndReached={onEndReached}
    onEndReachedThreshold={0.75}
    onStartReached={onStartReached}
    onStartReachedThreshold={0.75}
    ListFooterComponent={listFooterComponent}
    ListHeaderComponent={listHeaderComponent}
    keyboardShouldPersistTaps="handled"
    onLayout={onLayoutInner}
    onContentSizeChange={onContentSizeChangeInner}
    onScroll={trackVerticalScrolling}
    onScrollToIndexFailed={onScrollToIndexFailed}
    extraData={extraData}
    key={listID}
    shouldEnableAutoScrollToTopThreshold={shouldEnableAutoScrollToTopThreshold}
    />

    What changes do you think we should make in order to solve the problem?

    we can use keyboardShouldPersistTaps="never" in ReportActionsList.tsx or remove keyboardShouldPersistTaps prop because by default the value of keyboardShouldPersistTaps is never

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 27, 2024
  5. changed the title [-]Android - Chat - Unable to close keyboard by tapping outside of it[/-] [+][$250] Android - Chat - Unable to close keyboard by tapping outside of it[/+] on Nov 27, 2024
  6. melvin-bot commented on Nov 27, 2024

    @melvin-bot
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 27, 2024
  8. melvin-bot commented on Nov 27, 2024

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @alitoshmatov (External)

  9. mallenexpensify commented on Nov 27, 2024

    @mallenexpensify
    Contributor

    👋 @gadhiyamanan , it's been a minute!
    @alitoshmatov , plz attempt reproduction. If you're able to repro, please review Manan's proposal. I won't be able to test on Android til I'm back in the bank on Monday.

  10. huult commented on Nov 28, 2024

    @huult
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-11-28 04:11:57 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Unable to close keyboard by tapping outside of it

    What is the root cause of that problem?

    We are using keyboardShouldPersistTaps with the value handled, but with this setup, we are unable to hide the keyboard when tapping outside

    keyboardShouldPersistTaps="handled"

    'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).
    false, deprecated, use 'never' instead
    true, deprecated, use 'always' instead

    Screenshot 2024-11-28 at 11 21 42

    What changes do you think we should make in order to solve the problem?

    To resolve this issue and avoid impacting the current logic and behavior, we should handle the onPress event of ReportActionItem to dismiss the keyboard. Something like this:

    // src/pages/home/report/ReportActionsListItemRenderer.tsx#L162
        <ReportActionItem
            shouldHideThreadDividerLine={shouldHideThreadDividerLine}
            parentReportAction={parentReportAction}
            report={report}
            transactionThreadReport={transactionThreadReport}
            parentReportActionForTransactionThread={parentReportActionForTransactionThread}
            action={action}
            reportActions={reportActions}
            linkedReportActionID={linkedReportActionID}
            displayAsGroup={displayAsGroup}
            shouldDisplayNewMarker={shouldDisplayNewMarker}
            shouldShowSubscriptAvatar={
                (ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isInvoiceRoom(report)) &&
                [
                    CONST.REPORT.ACTIONS.TYPE.IOU,
                    CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
                    CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
                    CONST.REPORT.ACTIONS.TYPE.APPROVED,
                    CONST.REPORT.ACTIONS.TYPE.FORWARDED,
                ].some((type) => type === reportAction.actionName)
            }
            isMostRecentIOUReportAction={reportAction.reportActionID === mostRecentIOUReportActionID}
            index={index}
            isFirstVisibleReportAction={isFirstVisibleReportAction}
            shouldUseThreadDividerLine={shouldUseThreadDividerLine}
    +        onPress={() => {
    +            Keyboard.dismiss();
    +        }}
        />
    POC
    Screen.Recording.2024-11-28.at.11.07.51.mov

    Note: For similar cases like this issue, we can reuse this solution

    What alternative solutions did you explore? (Optional)

  11. daledah commented on Nov 29, 2024

    @daledah
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-11-29 07:35:59 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Keyboard is not closed when tapping outside of it in chats that already have messages. Keyboard closes normally when the chat doesn´t have any message or content on it.

    What is the root cause of that problem?

    • We are using:

    keyboardShouldPersistTaps="handled"

    'handled': the keyboard will not dismiss automatically when the tap was handled by children of the scroll view (or captured by an ancestor).

    That means the keyboard will not be dismissed if the tap is handled by the children.

    • The state mentioned in OP "Keyboard is not closed when tapping outside of it in chats that already have messages" is not fully correct. Given the below image:

    image

    The keyboard is still closed if we click on red area. When clicking on the white area, the keyboard is not closed. It is because the red area is just a normal View component:

    <View style={[styles.pRelative]}>

    so it cannot handle the tap. So the keyboard is closed.

    Otherwise, with the white area, it is the Pressable component:

    <PressableWithSecondaryInteraction

    so it can handle the tap. Based on the docs, the keyboard will not dismiss automatically when the tap was handled by children.

    What changes do you think we should make in order to solve the problem?

    • We can use onStartShouldSetResponder in here:

    <View style={highlightedBackgroundColorIfNeeded}>

                        <View
                            onStartShouldSetResponder={() => {
                                Keyboard.dismiss();
                                return false;
                            }}
                            style={highlightedBackgroundColorIfNeeded}
                        >

    or

                        <View
                            onStartShouldSetResponder={() => {
                                setTimeout(() => {
                                    Keyboard.dismiss();
                                }, 500); // 500ms to recognize the long press
                                return false;
                            }}
                            style={highlightedBackgroundColorIfNeeded}
                        >
    • Explanation: Based on the docs:

    onStartShouldSetResponder are called with a bubbling pattern, where the deepest node is called first. That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers. This is desirable in most cases, because it makes sure all controls and buttons are usable.

    This means that if the deepest component in:

    <PressableWithSecondaryInteraction

    is an interactive component (such as Button, Pressable, etc.), the onStartShouldSetResponder will not be called. However, if the deepest component is a non-interactive component (like View, Text, etc.), the onStartShouldSetResponder will be triggered, in other words, we call Keyboard.dismiss() in this case.

    What alternative solutions did you explore? (Optional)

    • We need to manually close the keyboard when user clicks on white area. To do it, we can update:

    onPress={draftMessage === undefined ? onPress : undefined}

                onPress={
                    draftMessage === undefined
                        ? () => {
                              onPress?.();
                              Keyboard.dismiss();
                          }
                        : undefined
                }

    or

                onPress={
                    draftMessage === undefined
                        ? () => {
                              onPress?.();
                              Keyboard.dismiss();
                          }
                        : () => {
                              Keyboard.dismiss();
                          }
                }
    • Before calling Keyboard.dismiss(), we can check whether the keyboard is opening or not. If so, call Keyboard.dismiss().
  12. ikevin127 commented on Dec 1, 2024

    @ikevin127
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-12-02 12:26:18 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue

    In chat reports that have messages, the keyboard is not closed when tapping outside of it on any of the messages.

    What is the root cause of that problem?

    The keyboardShouldPersistTaps="handled" prop is passed to the InvertedFlatList here (has been there for more than 18 months at this point), handled meaning:

    handled: the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).

    in our case, the chat report message being a PressableWithSecondaryInteraction which already handles tap (onPress), the keyboard won't close when tapped on a message (onPress).

    What changes do you think we should make in order to solve the problem?

    Given that keyboardShouldPersistTaps="handled" has been there for over 18 months, I don't think we should remove or change it because that would also remove the onLongPress behaviour of the message which opens the context menu (even with the keyboard open) and we would have to close the keyboard first then long press on a message in order to open the context menu (which is bad UX).

    The ideal solution here would have to fulfil both:

    • keep the current onLongPress message functionality (even with the keyboard open)
    • dismiss the keyboard when simple tap (onPress) is performed on a message while the keyboard is opened

    Therefore I'm coming forward with the following solution which allows to dynamically set the required behaviour based on a prop that stands at the root of our BaseGenericPressable component and can be easily passed only where we need it, in our ReportActionItem component to PressableWithSecondaryInteraction.

    Implementation

    1. In our BaseGenericPressable.tsx component add a new prop shouldDismissKeyboardOnPress (boolean) defaulting to false (make sure to add the type PressableProps).
    2. In the same component, within the the onPressHandler function, before return onPress(event); add:
    if (shouldDismissKeyboardOnPress && Keyboard.isVisible()) {
        Keyboard.dismiss();
    }

    leveraging our newly added prop and react-native's Keyboard to ensure we only dismiss the keyboard when required by the new prop and when the keyboard is actually visible.

    1. In ReportActionItem.tsx pass the newly added shouldDismissKeyboardOnPress prop to PressableWithSecondaryInteraction as true (no need to add ={true}).

    And we're done, this ensures we can dynamically add the dismiss functionality for the onPress using the shouldDismissKeyboardOnPress to elegantly get around the list's keyboardShouldPersistTaps="handled" prop and fulfil the issue's Expected result while providing a way for developers to use the same prop should similar issues arise in the future.

    Here's a diff of all the changes for convenience:

    DIFF
    diff --git a/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx b/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx
    index 1765560eaae..9bdeb82fc6a 100644
    --- a/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx
    +++ b/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx
    @@ -2,7 +2,7 @@ import type {ForwardedRef} from 'react';
     import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
     import type {GestureResponderEvent, View} from 'react-native';
     // eslint-disable-next-line no-restricted-imports
    -import {Pressable} from 'react-native';
    +import {Keyboard, Pressable} from 'react-native';
     import type {PressableRef} from '@components/Pressable/GenericPressable/types';
     import type PressableProps from '@components/Pressable/GenericPressable/types';
     import useSingleExecution from '@hooks/useSingleExecution';
    @@ -37,6 +37,7 @@ function GenericPressable(
             accessible = true,
             fullDisabled = false,
             interactive = true,
    +        shouldDismissKeyboardOnPress = false,
             ...rest
         }: PressableProps,
         ref: PressableRef,
    @@ -115,6 +116,9 @@ function GenericPressable(
                     ref.current?.blur();
                     Accessibility.moveAccessibilityFocus(nextFocusRef);
                 }
    +            if (shouldDismissKeyboardOnPress && Keyboard.isVisible()) {
    +                Keyboard.dismiss();
    +            }
                 return onPress(event);
             },
             [shouldUseHapticsOnPress, onPress, nextFocusRef, ref, isDisabled, interactive],
    diff --git a/src/components/Pressable/GenericPressable/types.ts b/src/components/Pressable/GenericPressable/types.ts
    index 61cb6db8ee7..d8f38a44fda 100644
    --- a/src/components/Pressable/GenericPressable/types.ts
    +++ b/src/components/Pressable/GenericPressable/types.ts
    @@ -148,6 +148,11 @@ type PressableProps = RNPressableProps &
              * e.g., show disabled cursor when disabled
              */
             interactive?: boolean;
    +
    +        /** Used for when a list has keyboardShouldPersistTaps set to `handled`
    +         * and we need the keyboard to be dismissed on onPress.
    +         */
    +        shouldDismissKeyboardOnPress?: boolean;
         };
     
     type PressableRef = ForwardedRef<HTMLDivElement | View | RNText | undefined>;
    diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx
    index 399550069c0..963b2787158 100644
    --- a/src/pages/home/report/ReportActionItem.tsx
    +++ b/src/pages/home/report/ReportActionItem.tsx
    @@ -968,6 +968,7 @@ function ReportActionItem({
                 withoutFocusOnSecondaryInteraction
                 accessibilityLabel={translate('accessibilityHints.chatMessage')}
                 accessible
    +            shouldDismissKeyboardOnPress
             >
                 <Hoverable
                     shouldHandleScroll

    What alternative solutions did you explore?

    Alternatively, skip the addition of the shouldDismissKeyboardOnPress prop and simply add the keyboard dismiss logic in the same place as stated in the main solution.

    Result video (before / after)

    Android: Native (One Plus 7T - Real device)
    Before After
    before.mp4
    after.mp4
  13. 50 remaining items

  14. changed the title [-][$250] Android - Chat - Unable to close keyboard by tapping outside of it[/-] [+][HOLD for payment 2025-01-18] [$250] Android - Chat - Unable to close keyboard by tapping outside of it[/+] on Jan 11, 2025
  15. melvin-bot commented on Jan 11, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  16. melvin-bot commented on Jan 11, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.83-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-01-18. 🎊

    For reference, here are some details about the assignees on this issue:

  17. melvin-bot commented on Jan 11, 2025

    @melvin-bot

    @alitoshmatov @mallenexpensify @alitoshmatov The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  18. melvin-bot commented on Jan 20, 2025

    @melvin-bot

    @AndrewGable, @mallenexpensify, @alitoshmatov, @daledah Whoops! This issue is 2 days overdue. Let's get this updated quick!

  19. alitoshmatov commented on Jan 20, 2025

    @alitoshmatov
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/18637/files#r1922522843

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: No discussion

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • I don't think regression is needed

  20. mallenexpensify commented on Jan 21, 2025

    @mallenexpensify
    Contributor

    Contributor: @daledah paid $250 via Upwork
    Contributor+: @alitoshmatov due $250 via NewDot

    @alitoshmatov , I created a test case and added

    Unsure if we need/want this, erring on the safe side, will let you decide.

    Thx!

  21. JmillsExpensify commented on Jan 22, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @alitoshmatov

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions