Skip to content

Commit

Permalink
wip: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Aug 8, 2023
1 parent 9739c08 commit eb9baf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as Expensicons from '../../../../components/Icon/Expensicons';
import AttachmentPicker from '../../../../components/AttachmentPicker';
import * as Report from '../../../../libs/actions/Report';
import PopoverMenu from '../../../../components/PopoverMenu';
import willBlurTextInputOnTapOutsideFunc from '../../../../libs/willBlurTextInputOnTapOutside';
import CONST from '../../../../CONST';
import Tooltip from '../../../../components/Tooltip';
import * as Browser from '../../../../libs/Browser';
Expand Down Expand Up @@ -36,6 +35,8 @@ function AttachmentPickerWithMenu({
disabled,
setMenuVisibility,
isMenuVisible,
// Added
onTriggerAttachmentPicker,
}) {
const actionButtonRef = useRef(null);
const {translate} = useLocalize();
Expand Down Expand Up @@ -90,11 +91,7 @@ function AttachmentPickerWithMenu({
<AttachmentPicker>
{({openPicker}) => {
const triggerAttachmentPicker = () => {
// Set a flag to block suggestion calculation until we're finished using the file picker,
// which will stop any flickering as the file picker opens on non-native devices.
if (willBlurTextInputOnTapOutsideFunc) {
suggestionsRef.current.setShouldBlockSuggestionCalc(true);
}
onTriggerAttachmentPicker();
openPicker({
onPicked: displayFileInModal,
});
Expand Down
10 changes: 10 additions & 0 deletions src/pages/home/report/ReportActionCompose/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ function ReportActionCompose({
RNTextInputReset.resetKeyboardInput(findNodeHandle(textInputRef));
}, [textInputRef]);

const onTriggerAttachmentPicker = useCallback(() => {
// Set a flag to block suggestion calculation until we're finished using the file picker,
// which will stop any flickering as the file picker opens on non-native devices.
if (!willBlurTextInputOnTapOutsideFunc) {
return;
}
suggestionsRef.current.setShouldBlockSuggestionCalc(true);
}, [suggestionsRef]);

useEffect(() => {
const unsubscribeNavigationBlur = navigation.addListener('blur', () => KeyDownListener.removeKeyDownPressListner(focusComposerOnKeyPress));
const unsubscribeNavigationFocus = navigation.addListener('focus', () => {
Expand Down Expand Up @@ -706,6 +715,7 @@ function ReportActionCompose({
disabled={isBlockedFromConcierge || disabled}
setMenuVisibility={setMenuVisibility}
isMenuVisible={isMenuVisible}
onTriggerAttachmentPicker={onTriggerAttachmentPicker}
/>
<View style={[containerComposeStyles, styles.textInputComposeBorder]}>
<Composer
Expand Down

0 comments on commit eb9baf8

Please sign in to comment.