Skip to content

Commit

Permalink
Merge pull request #46172 from bernhardoj/fix/46134-cant-close-keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Jul 29, 2024
2 parents 5b99455 + b67d261 commit 48e8017
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/hooks/useAutoFocusInput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {useFocusEffect} from '@react-navigation/native';
import {useCallback, useContext, useEffect, useRef, useState} from 'react';
import type {RefObject} from 'react';
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 +57,5 @@ export default function useAutoFocusInput(): UseAutoFocusInput {
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);
}
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;
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);
}
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);
}
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);
}
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 @@ -117,8 +117,10 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti
if (!element) {
return;
}
if (!inputRef.current) {
updateMultilineInputRange(inputRef.current);
}
inputRef.current = element;
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;
}}
/>
</View>
Expand Down

0 comments on commit 48e8017

Please sign in to comment.