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

Fix can't close keyboard in some pages #46172

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hooks/useAutoFocusInput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {useFocusEffect} from '@react-navigation/native';
import {useCallback, useContext, useEffect, useRef, useState} from 'react';
import {RefObject, useCallback, useContext, useEffect, useRef, useState} from 'react';

Check failure on line 2 in src/hooks/useAutoFocusInput.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Imports "RefObject" are only used as type
import type {TextInput} from 'react-native';
import {InteractionManager} from 'react-native';
import CONST from '@src/CONST';
import * as Expensify from '@src/Expensify';

type UseAutoFocusInput = {
inputCallbackRef: (ref: TextInput | null) => void;
inputRef: RefObject<TextInput | null>;
};

export default function useAutoFocusInput(): UseAutoFocusInput {
Expand Down Expand Up @@ -55,5 +56,5 @@
setIsInputInitialized(true);
};

return {inputCallbackRef};
return {inputCallbackRef, inputRef};
}
4 changes: 3 additions & 1 deletion src/pages/PrivateNotes/PrivateNotesEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ function PrivateNotesEditPage({route, personalDetailsList, report, session}: Pri
if (!el) {
return;
}
if (!privateNotesInput.current) {
updateMultilineInputRange(el);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_p_note.mp4

privateNotesInput.current = el;
updateMultilineInputRange(privateNotesInput.current);
}}
isMarkdownEnabled
/>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/RoomDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
if (!el) {
return;
}
if (!reportDescriptionInputRef.current) {
updateMultilineInputRange(el);
}
reportDescriptionInputRef.current = el;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_desc_room.mp4

updateMultilineInputRange(el);
}}
value={description}
onChangeText={handleReportDescriptionChange}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ function IOURequestStepDescription({
if (!el) {
return;
}
if (!inputRef.current) {
updateMultilineInputRange(el);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_desc.mp4

inputRef.current = el;
updateMultilineInputRange(inputRef.current);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyRe
const {keyboardHeight} = useKeyboardState();
const {windowHeight} = useWindowDimensions();
const {top: safeAreaInsetsTop} = useSafeAreaInsets();
const {inputCallbackRef} = useAutoFocusInput();
const {inputCallbackRef, inputRef} = useAutoFocusInput();

const {reason, backTo} = route.params;
const {isOffline} = useNetwork({
Expand Down Expand Up @@ -134,7 +134,9 @@ function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyRe
if (!el) {
return;
}
updateMultilineInputRange(el);
if (!inputRef.current) {
updateMultilineInputRange(el);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_exit_survey.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #50962 (BZ Checklist):

We’re missing a test for this case, and an error is visible in the screenshot video when the user navigates from the reason page to the response page. To address this, we should prevent using focus at the same time as other input functionalities related to input selection.

inputCallbackRef(el);
}}
containerStyles={[baseResponseInputContainerStyle]}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/tasks/NewTaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type NewTaskDescriptionPageProps = NewTaskDescriptionPageOnyxProps & StackScreen
function NewTaskDescriptionPage({task}: NewTaskDescriptionPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const {inputCallbackRef, inputRef} = useAutoFocusInput();

const onSubmit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_TASK_FORM>) => {
TaskActions.setDescriptionValue(values.taskDescription);
Expand Down Expand Up @@ -83,8 +83,10 @@ function NewTaskDescriptionPage({task}: NewTaskDescriptionPageProps) {
accessibilityLabel={translate('newTaskPage.descriptionOptional')}
role={CONST.ROLE.PRESENTATION}
ref={(el) => {
if (!inputRef.current) {
updateMultilineInputRange(el);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_task_description.mp4

inputCallbackRef(el);
updateMultilineInputRange(el);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/tasks/TaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti
if (!element) {
return;
}
if (!inputRef.current) {
updateMultilineInputRange(inputRef.current);
}
inputRef.current = element;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_task_description_2.mp4

updateMultilineInputRange(inputRef.current);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function WorkspaceInviteMessagePage({

const [welcomeNote, setWelcomeNote] = useState<string>();

const {inputCallbackRef} = useAutoFocusInput();
const {inputCallbackRef, inputRef} = useAutoFocusInput();

const welcomeNoteSubject = useMemo(
() => `# ${currentUserPersonalDetails?.displayName ?? ''} invited you to ${policy?.name ?? 'a workspace'}`,
Expand Down Expand Up @@ -207,8 +207,10 @@ function WorkspaceInviteMessagePage({
if (!element) {
return;
}
if (!inputRef.current) {
updateMultilineInputRange(element);
}
inputCallbackRef(element);
updateMultilineInputRange(element);
}}
/>
</View>
Expand Down
8 changes: 6 additions & 2 deletions src/pages/workspace/WorkspaceProfileDescriptionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useState} from 'react';
import React, {useCallback, useRef, useState} from 'react';
import {Keyboard, View} from 'react-native';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand Down Expand Up @@ -26,6 +26,7 @@ type Props = WithPolicyProps;
function WorkspaceProfileDescriptionPage({policy}: Props) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const isInputInitializedRef = useRef(false);
const [description, setDescription] = useState(() =>
Parser.htmlToMarkdown(
// policy?.description can be an empty string
Expand Down Expand Up @@ -109,7 +110,10 @@ function WorkspaceProfileDescriptionPage({policy}: Props) {
autoGrowHeight
isMarkdownEnabled
ref={(el: BaseTextInputRef | null): void => {
updateMultilineInputRange(el);
if (!isInputInitializedRef.current) {
updateMultilineInputRange(el);
}
isInputInitializedRef.current = true;
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ios_profile_desc.mp4

/>
</View>
Expand Down
Loading