You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HOLD for payment 2025-01-18] [$250] Android - Chat - Unable to close keyboard by tapping outside of it #53196
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:
Open the Expensify app.
Open any chat that has messages on it.
Tap on compose box to open keyboard.
Tap outside the keyboard area to close it.
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.
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
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
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
👋 @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.
'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
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:
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.
'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:
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:
<ViewonStartShouldSetResponder={()=>{setTimeout(()=>{Keyboard.dismiss();},500);// 500ms to recognize the long pressreturnfalse;}}style={highlightedBackgroundColorIfNeeded}>
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.
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:
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 InvertedFlatListhere (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
In our BaseGenericPressable.tsx component add a new prop shouldDismissKeyboardOnPress (boolean) defaulting to false (make sure to add the type PressableProps).
In the same component, within the the onPressHandler function, before return onPress(event); add:
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.
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.
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
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:
@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]
[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.
Activity
melvin-bot commentedon Nov 27, 2024
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.gadhiyamanan commentedon Nov 27, 2024
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 keyboardApp/src/pages/home/report/ReportActionsList.tsx
Lines 732 to 756 in c62ab78
What changes do you think we should make in order to solve the problem?
we can use
keyboardShouldPersistTaps="never"in ReportActionsList.tsx or removekeyboardShouldPersistTapsprop because by default the value ofkeyboardShouldPersistTapsisnever[-]Android - Chat - Unable to close keyboard by tapping outside of it[/-][+][$250] Android - Chat - Unable to close keyboard by tapping outside of it[/+]melvin-bot commentedon Nov 27, 2024
Job added to Upwork: https://www.upwork.com/jobs/~021861915865037036576
melvin-bot commentedon Nov 27, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @alitoshmatov (
External)mallenexpensify commentedon Nov 27, 2024
👋 @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.
huult commentedon Nov 28, 2024
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
keyboardShouldPersistTapswith the valuehandled, but with this setup, we are unable to hide the keyboard when tapping outsideApp/src/pages/home/report/ReportActionsList.tsx
Line 748 in 9909d61
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
onPressevent ofReportActionItemto dismiss the keyboard. Something like this:App/src/pages/home/report/ReportActionsListItemRenderer.tsx
Line 162 in 0b97bde
// 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)
daledah commentedon Nov 29, 2024
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?
App/src/pages/home/report/ReportActionsList.tsx
Line 748 in 9909d61
That means the keyboard will not be dismissed if the tap is handled by the children.
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
Viewcomponent:App/src/pages/home/report/ReportActionItemCreated.tsx
Line 54 in 9909d61
so it cannot handle the tap. So the keyboard is closed.
Otherwise, with the white area, it is the
Pressablecomponent:App/src/pages/home/report/ReportActionItem.tsx
Line 943 in 9909d61
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?
onStartShouldSetResponderin here:App/src/pages/home/report/ReportActionItem.tsx
Line 961 in 9909d61
or
This means that if the deepest component in:
App/src/pages/home/report/ReportActionItem.tsx
Line 943 in 9909d61
is an interactive component (such as Button, Pressable, etc.), the
onStartShouldSetResponderwill not be called. However, if the deepest component is a non-interactive component (like View, Text, etc.), theonStartShouldSetResponderwill be triggered, in other words, we callKeyboard.dismiss()in this case.What alternative solutions did you explore? (Optional)
App/src/pages/home/report/ReportActionItem.tsx
Line 945 in 9909d61
or
Keyboard.dismiss(), we can check whether the keyboard is opening or not. If so, callKeyboard.dismiss().ikevin127 commentedon Dec 1, 2024
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 theInvertedFlatListhere (has been there for more than 18 months at this point),handledmeaning:in our case, the chat report message being a
PressableWithSecondaryInteractionwhich 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 theonLongPressbehaviour 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:
onLongPressmessage functionality (even with the keyboard open)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
BaseGenericPressablecomponent and can be easily passed only where we need it, in ourReportActionItemcomponent toPressableWithSecondaryInteraction.Implementation
BaseGenericPressable.tsxcomponent add a new propshouldDismissKeyboardOnPress(boolean) defaulting tofalse(make sure to add the typePressableProps).onPressHandlerfunction, beforereturn onPress(event);add:leveraging our newly added prop and react-native's
Keyboardto ensure we only dismiss the keyboard when required by the new prop and when the keyboard is actually visible.ReportActionItem.tsxpass the newly addedshouldDismissKeyboardOnPressprop toPressableWithSecondaryInteractionastrue(no need to add={true}).And we're done, this ensures we can dynamically add the dismiss functionality for the onPress using the
shouldDismissKeyboardOnPressto elegantly get around the list'skeyboardShouldPersistTaps="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
What alternative solutions did you explore?
Alternatively, skip the addition of the
shouldDismissKeyboardOnPressprop 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.mp4
after.mp4
50 remaining items
[-][$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[/+]melvin-bot commentedon Jan 11, 2025
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Jan 11, 2025
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:
melvin-bot commentedon Jan 11, 2025
@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]
melvin-bot commentedon Jan 20, 2025
@AndrewGable, @mallenexpensify, @alitoshmatov, @daledah Whoops! This issue is 2 days overdue. Let's get this updated quick!
alitoshmatov commentedon Jan 20, 2025
BugZero Checklist:
Bug classification
Source of bug:
Where bug was reported:
Who reported the bug:
[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
mallenexpensify commentedon Jan 21, 2025
Contributor: @daledah paid $250 via Upwork
Contributor+: @alitoshmatov due $250 via NewDot
@alitoshmatov , I created a test case and added
Thx!
JmillsExpensify commentedon Jan 22, 2025
$250 approved for @alitoshmatov