Skip to content

Fix back navigation focus in task creation #47209

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

Merged
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
6 changes: 6 additions & 0 deletions src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {Ref} from 'react';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
Expand Down Expand Up @@ -46,6 +47,9 @@ type FormAlertWithSubmitButtonProps = {
/** Whether to show the alert text */
isAlertVisible?: boolean;

/** React ref being forwarded to the submit button */
buttonRef?: Ref<View>;

/** Text for the button */
buttonText: string;

Expand All @@ -70,6 +74,7 @@ function FormAlertWithSubmitButton({
disablePressOnEnter = false,
isSubmitActionDangerous = false,
footerContent,
buttonRef,
buttonStyles,
buttonText,
isAlertVisible = false,
Expand Down Expand Up @@ -105,6 +110,7 @@ function FormAlertWithSubmitButton({
/>
) : (
<Button
ref={buttonRef}
success
pressOnEnter={!disablePressOnEnter}
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
Expand Down
23 changes: 20 additions & 3 deletions src/pages/tasks/NewTaskPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {useFocusEffect} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager, View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import FormHelpMessage from '@components/FormHelpMessage';
Expand All @@ -14,13 +15,15 @@ import ScrollView from '@components/ScrollView';
import useLocalize from '@hooks/useLocalize';
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets';
import useThemeStyles from '@hooks/useThemeStyles';
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
import Navigation from '@libs/Navigation/Navigation';
import type {NewTaskNavigatorParamList} from '@libs/Navigation/types';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import * as TaskActions from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
Expand Down Expand Up @@ -59,6 +62,19 @@ function NewTaskPage({task, reports, personalDetails}: NewTaskPageProps) {

const {paddingBottom} = useStyledSafeAreaInsets();

const confirmButtonRef = useRef<View>(null);
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
InteractionManager.runAfterInteractions(() => {
blurActiveElement();
});
}, CONST.ANIMATED_TRANSITION);
return () => focusTimeoutRef.current && clearTimeout(focusTimeoutRef.current);
}, []),
);

useEffect(() => {
setErrorMessage('');

Expand Down Expand Up @@ -205,6 +221,7 @@ function NewTaskPage({task, reports, personalDetails}: NewTaskPageProps) {
message={errorMessage}
onSubmit={onSubmit}
enabledWhenOffline
buttonRef={confirmButtonRef}
buttonText={translate('newTaskPage.confirmTask')}
containerStyles={[styles.mh0, styles.mt5, styles.flex1, styles.ph5, !paddingBottom ? styles.mb5 : null]}
/>
Expand Down
Loading