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: room name field does not automatically focus when returning from the chat option #28646

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const CONST = {
OUT: 'out',
},
ARROW_HIDE_DELAY: 3000,
INPUT_FOCUS_DELAY: 600,
robertjchen marked this conversation as resolved.
Show resolved Hide resolved

API_ATTACHMENT_VALIDATIONS: {
// 24 megabytes in bytes, this is limit set on servers, do not update without wider internal discussion
Expand Down
25 changes: 25 additions & 0 deletions src/hooks/useDelayedInputFocus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {useCallback, useRef} from 'react';
import {useFocusEffect} from '@react-navigation/native';
import CONST from '../CONST';

/**
* Focus a text input when a screen is navigated to, after the specified time delay has elapsed.
*
* @param {Object} inputRef
* @param {Number} [delay]
*/
export default function useDelayedInputFocus(inputRef, delay = CONST.INPUT_FOCUS_DELAY) {
const timeoutRef = useRef(null);

useFocusEffect(
useCallback(() => {
timeoutRef.current = setTimeout(() => inputRef.current && inputRef.current.focus(), delay);
return () => {
if (!timeoutRef.current) {
return;
}
clearTimeout(timeoutRef.current);
};
}, [delay, inputRef]),
);
}
7 changes: 6 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState, useCallback, useMemo} from 'react';
import React, {useState, useCallback, useMemo, useRef} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -25,6 +25,7 @@ import policyMemberPropType from '../policyMemberPropType';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import compose from '../../libs/compose';
import variables from '../../styles/variables';
import useDelayedInputFocus from '../../hooks/useDelayedInputFocus';

const propTypes = {
/** All reports shared with the user */
Expand Down Expand Up @@ -144,6 +145,9 @@ function WorkspaceNewRoomPage(props) {
[translate],
);

const roomNameInputRef = useRef(null);
useDelayedInputFocus(roomNameInputRef);

return (
<FullPageNotFoundView
shouldShow={!Permissions.canUsePolicyRooms(props.betas) || !workspaceOptions.length}
Expand Down Expand Up @@ -177,6 +181,7 @@ function WorkspaceNewRoomPage(props) {
>
<View style={styles.mb5}>
<RoomNameInput
ref={(el) => (roomNameInputRef.current = el)}
inputID="roomName"
isFocused={props.isFocused}
shouldDelayFocus
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this? shouldDelayFocus and autoFocus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't think we do. I'll remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abdulrahuman5196 Actually, after testing, these are still needed on web for cases when the user refreshes the browser window while the Room tab is active.

Expand Down