Skip to content

Commit

Permalink
foc focus state
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Aug 24, 2023
1 parent 9826f49 commit 9b7c07b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ const propTypes = {
/** Called when the menu with the items is closed after it was open */
onMenuClosed: PropTypes.func.isRequired,

/** Called when the add action button is pressed */
onAddActionPressed: PropTypes.func.isRequired,

/** A ref for the add action button */
actionButtonRef: PropTypes.shape({
// eslint-disable-next-line react/forbid-prop-types
current: PropTypes.object,
}).isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -104,10 +111,10 @@ function AttachmentPickerWithMenuItems({
onCanceledAttachmentPicker,
onMenuClosed,
onAddActionPressed,
actionButtonRef,
}) {
const {translate} = useLocalize();
const {windowHeight} = useWindowDimensions();
const actionButtonRef = useRef(null);

/**
* Returns the list of IOU Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ function ComposerWithSuggestions({
focus,
replaceSelectionWithText,
prepareCommentAndResetComposer,
isFocused: () => textInputRef.current.isFocused(),
}),
[blur, focus, prepareCommentAndResetComposer, replaceSelectionWithText],
);
Expand Down
13 changes: 9 additions & 4 deletions src/pages/home/report/ReportActionCompose/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function ReportActionCompose({
const navigation = useNavigation();
const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions();
const animatedRef = useAnimatedRef();
const actionButtonRef = useRef(null);

/**
* Updates the Highlight state of the composer
Expand Down Expand Up @@ -178,13 +179,13 @@ function ReportActionCompose({
if (!isKeyboardVisibleWhenShowingModalRef.current) {
return;
}
focus(true);
composerRef.current.focus(true);
isKeyboardVisibleWhenShowingModalRef.current = false;
}, [focus]);
}, []);

const onAddActionPressed = useCallback(() => {
if (!willBlurTextInputOnTapOutside) {
isKeyboardVisibleWhenShowingModalRef.current = textInputRef.current.isFocused();
isKeyboardVisibleWhenShowingModalRef.current = composerRef.current.isFocused();
}
composerRef.current.blur();
}, []);
Expand Down Expand Up @@ -257,9 +258,12 @@ function ReportActionCompose({
isNextModalWillOpenRef.current = true;
}, []);

const onBlur = useCallback(() => {
const onBlur = useCallback((e) => {
setIsFocused(false);
suggestionsRef.current.resetSuggestions();
if (e.relatedTarget && e.relatedTarget === actionButtonRef.current) {
isKeyboardVisibleWhenShowingModalRef.current = true;
}
}, []);

const onFocus = useCallback(() => {
Expand Down Expand Up @@ -337,6 +341,7 @@ function ReportActionCompose({
onCanceledAttachmentPicker={restoreKeyboardState}
onMenuClosed={restoreKeyboardState}
onAddActionPressed={onAddActionPressed}
actionButtonRef={actionButtonRef}
/>
<ComposerWithSuggestions
ref={composerRef}
Expand Down

0 comments on commit 9b7c07b

Please sign in to comment.