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

Composer - optimise rendering behaviour for onKeyPress & onSubmit #29561

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
8 changes: 5 additions & 3 deletions src/hooks/useDebounce.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodashDebounce from 'lodash/debounce';
import {useEffect, useRef} from 'react';
import {useCallback, useEffect, useRef} from 'react';

/**
* Create and return a debounced function.
Expand Down Expand Up @@ -27,11 +27,13 @@ export default function useDebounce(func, wait, options) {
return debouncedFn.cancel;
}, [func, wait, leading, maxWait, trailing]);

return (...args) => {
const debounceCallback = useCallback((...args) => {
const debouncedFn = debouncedFnRef.current;

if (debouncedFn) {
debouncedFn(...args);
}
};
}, []);

return debounceCallback;
}
16 changes: 3 additions & 13 deletions src/pages/home/report/ReportActionCompose/SuggestionMention.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import * as Expensicons from '@components/Icon/Expensicons';
import MentionSuggestions from '@components/MentionSuggestions';
import {usePersonalDetails} from '@components/OnyxProvider';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import * as SuggestionsUtils from '@libs/SuggestionUtils';
import * as UserUtils from '@libs/UserUtils';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import * as SuggestionProps from './suggestionProps';

/**
Expand All @@ -29,17 +27,13 @@ const defaultSuggestionsValues = {
};

const propTypes = {
/** Personal details of all users */
personalDetails: PropTypes.objectOf(personalDetailsPropType),

/** A ref to this component */
forwardedRef: PropTypes.shape({current: PropTypes.shape({})}),

...SuggestionProps.implementationBaseProps,
};

const defaultProps = {
personalDetails: {},
forwardedRef: null,
};

Expand All @@ -49,14 +43,14 @@ function SuggestionMention({
selection,
setSelection,
isComposerFullSize,
personalDetails,
updateComment,
composerHeight,
forwardedRef,
isAutoSuggestionPickerLarge,
measureParentContainer,
isComposerFocused,
}) {
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;
const {translate} = useLocalize();
const previousValue = usePrevious(value);
const [suggestionValues, setSuggestionValues] = useState(defaultSuggestionsValues);
Expand Down Expand Up @@ -316,8 +310,4 @@ const SuggestionMentionWithRef = React.forwardRef((props, ref) => (

SuggestionMentionWithRef.displayName = 'SuggestionMentionWithRef';

export default withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(SuggestionMentionWithRef);
export default SuggestionMentionWithRef;