Skip to content
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
10 changes: 6 additions & 4 deletions src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,19 @@ function MagicCodeInput(props) {
let focusTimeout = null;
if (props.shouldDelayFocus) {
focusTimeout = setTimeout(() => inputRefs.current[0].focus(), CONST.ANIMATED_TRANSITION);
} else {
inputRefs.current[0].focus();
}

inputRefs.current[0].focus();

return () => {
if (!focusTimeout) {
return;
}
clearTimeout(focusTimeout);
};
}, [props.autoFocus, props.shouldDelayFocus]);
// We only want this to run on mount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Comment on lines +172 to +174

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if we keep those props?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is aligned with BaseTextInput.
No issue with original dependencies but no need, as auto-focus should happen only on component mount.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good. Can you also upload screen recordings of the magic code input on the login page working as expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Note: mSafari login magic code auto-focus doesn't work on main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@situchan It's working on Staging.

Screen.Recording.2023-07-05.at.3.08.34.PM.mov

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not working for me. Tested on iOS 16.4. Might depend on iOS version.

Screen.Recording.2023-07-05.at.11.20.17.AM.mov

It would be great if you can test this branch on your simulator.
As shouldDelayFocus is not passed to MagicCodeInput on sign in page, it should not be affected by this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it has do with the iOS version. Just tested locally and it works!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


/**
* Focuses on the input when it is pressed.
Expand Down Expand Up @@ -322,7 +324,7 @@ function MagicCodeInput(props) {
<View style={[StyleSheet.absoluteFillObject, styles.w100, isMobileSafari ? styles.bgTransparent : styles.opacity0]}>
<TextInput
ref={(ref) => (inputRefs.current[index] = ref)}
autoFocus={index === 0 && props.autoFocus}
autoFocus={index === 0 && props.autoFocus && !props.shouldDelayFocus}
inputMode="numeric"
textContentType="oneTimeCode"
name={props.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as User from '../../../../../libs/actions/User';
import Button from '../../../../../components/Button';
import DotIndicatorMessage from '../../../../../components/DotIndicatorMessage';
import * as Session from '../../../../../libs/actions/Session';
import shouldDelayFocus from '../../../../../libs/shouldDelayFocus';
import Text from '../../../../../components/Text';
import {withNetwork} from '../../../../../components/OnyxProvider';
import PressableWithFeedback from '../../../../../components/Pressable/PressableWithFeedback';
Expand Down Expand Up @@ -135,6 +136,7 @@ function BaseValidateCodeForm(props) {
errorText={formError.validateCode ? props.translate(formError.validateCode) : ErrorUtils.getLatestErrorMessage(props.account)}
onFulfill={validateAndSubmitForm}
autoFocus
shouldDelayFocus={shouldDelayFocus}
/>
<OfflineWithFeedback
pendingAction={lodashGet(loginData, 'pendingFields.validateCodeSent', null)}
Expand Down