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: 29950 Reload on title and description of task field does not focus back #30266

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 5 additions & 27 deletions src/pages/tasks/NewTaskDescriptionPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useRef, useCallback} from 'react';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import {useFocusEffect} from '@react-navigation/native';
import PropTypes from 'prop-types';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
Expand All @@ -18,6 +17,7 @@ import * as Task from '../../libs/actions/Task';
import updateMultilineInputRange from '../../libs/UpdateMultilineInputRange';
import CONST from '../../CONST';
import * as Browser from '../../libs/Browser';
import useAutoFocusInput from '../../hooks/useAutoFocusInput';

const propTypes = {
/** Beta features list */
Expand All @@ -40,26 +40,7 @@ const defaultProps = {
};

function NewTaskDescriptionPage(props) {
const inputRef = useRef(null);
const focusTimeoutRef = useRef(null);
// On submit, we want to call the assignTask function and wait to validate
// the response

useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
if (inputRef.current) {
inputRef.current.focus();
}
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, CONST.ANIMATED_TRANSITION);
}, []),
);
const {inputCallbackRef} = useAutoFocusInput();

const onSubmit = (values) => {
Task.setDescriptionValue(values.taskDescription);
Expand Down Expand Up @@ -97,11 +78,8 @@ function NewTaskDescriptionPage(props) {
accessibilityLabel={props.translate('newTaskPage.descriptionOptional')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
ref={(el) => {
if (!el) {
return;
}
inputRef.current = el;
updateMultilineInputRange(inputRef.current);
inputCallbackRef(el);
updateMultilineInputRange(el);
}}
autoGrowHeight
submitOnEnter={!Browser.isMobile()}
Expand Down
14 changes: 4 additions & 10 deletions src/pages/tasks/NewTaskTitlePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useRef} from 'react';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
Expand All @@ -16,6 +16,7 @@ import Permissions from '../../libs/Permissions';
import ROUTES from '../../ROUTES';
import * as Task from '../../libs/actions/Task';
import CONST from '../../CONST';
import useAutoFocusInput from '../../hooks/useAutoFocusInput';

const propTypes = {
/** Beta features list */
Expand All @@ -38,7 +39,7 @@ const defaultProps = {
};

function NewTaskTitlePage(props) {
const inputRef = useRef(null);
const {inputCallbackRef} = useAutoFocusInput();

/**
* @param {Object} values - form input values passed by the Form component
Expand Down Expand Up @@ -68,13 +69,6 @@ function NewTaskTitlePage(props) {
}
return (
<ScreenWrapper
onEntryTransitionEnd={() => {
if (!inputRef.current) {
return;
}

inputRef.current.focus();
}}
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
testID={NewTaskTitlePage.displayName}
Expand All @@ -97,7 +91,7 @@ function NewTaskTitlePage(props) {
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={props.task.title}
ref={(el) => (inputRef.current = el)}
ref={inputCallbackRef}
inputID="taskTitle"
label={props.translate('task.title')}
accessibilityLabel={props.translate('task.title')}
Expand Down
Loading