Skip to content

Commit

Permalink
keep ref name consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdiary committed Aug 22, 2023
1 parent 4d165ce commit 09baf7b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function AttachmentPicker({type, children}) {

const completeAttachmentSelection = useRef();
const onModalHide = useRef();
const onCancel = useRef();
const onCanceled = useRef();

const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -217,9 +217,11 @@ function AttachmentPicker({type, children}) {
* Opens the attachment modal
*
* @param {function} onPickedHandler A callback that will be called with the selected attachment
* @param {function} onCanceledHandler A callback that will be called without a selected attachment
*/
const open = (onPickedHandler) => {
const open = (onPickedHandler, onCanceledHandler = () => {}) => {
completeAttachmentSelection.current = onPickedHandler;
onCanceled.current = onCanceledHandler;
setIsVisible(true);
};

Expand All @@ -240,7 +242,7 @@ function AttachmentPicker({type, children}) {
const pickAttachment = useCallback(
(attachments = []) => {
if (attachments.length === 0) {
onCancel.current();
onCanceled.current();
return Promise.resolve();
}

Expand Down Expand Up @@ -310,18 +312,15 @@ function AttachmentPicker({type, children}) {
*/
const renderChildren = () =>
children({
openPicker: ({onPicked, onCanceled = () => {}}) => {
open(onPicked);
onCancel.current = onCanceled;
},
openPicker: ({onPicked, onCanceled: newOnCanceled}) => open(onPicked, newOnCanceled),
});

return (
<>
<Popover
onClose={() => {
close();
onCancel.current();
onCanceled.current();
}}
isVisible={isVisible}
anchorPosition={styles.createMenuPosition}
Expand Down

0 comments on commit 09baf7b

Please sign in to comment.