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

Supported presenting modals in queues and added code documentation #3

Merged
merged 3 commits into from
Feb 10, 2023

Conversation

lurui1029
Copy link
Contributor

No description provided.

export type ModalHandler = {
/**
* Same `dismiss` function as in `ModalContentProps`.
*/
dismiss: () => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this also have an onDismiss?: () => void type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

Copy link
Collaborator

Choose a reason for hiding this comment

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

and then this one should be the one with dismiss: ModalDismissFunc right?

if (ref) {
// FIXME: set up a flag here to prevent multiple `dismiss` calls during the out animation.
ref.animatedOut(() => {
rootSiblings?.destroy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

these two blocks are similar, can we rewrite this as follows?

const dismissModal = () => {
  rootSiblings.destroy();
  rootSiblings = null;
  options?.onDismiss?.();
  onDismissForQueue?.();
  onDismiss?.();
}

if (ref) {
  ref.animatedOut(() => {
    ref = null;
    dismissModal();
  });
} else {
  console.warn('Dismissing a modal without animation because ref has been lost.');
  dismissModal();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. I'll apply your suggestion.

return;
}
const modal = this.modals[0];
const finalDelay = Math.max(modal.delay ?? 0, this.minimumDelay);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be changed to Math.max(modal.delay ?? this.minimumDelay) since this.minimumDelay will always be > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

minimumDelay is 0 by default but users can change it to any other value. We need to add value verification to the minimumDelay's setter, or leave this as is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ahhhh ok, let's leave this as is then!

if (finalDelay > 0) {
await (new Promise<void>(resolve => setTimeout(resolve, finalDelay)));
}
await (new Promise<void>(resolve => modal.present(resolve)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can also be simplified as just

await (new Promise<void>(resolve => setTimeout(resolve => modal.present(resolve), finalDelay)));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both setTimeout and new Promise creates async blocks (for setTimeout, even though the value is 0), so we can reduce this if finalDelay is 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense, let's leave it as it is then

/**
* Get notified when the modal is later dismissed.
*/
onDismiss?: ModalDismissFunc;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This onDismiss? shouldn't be a function that receives a function, it should be the function itself:

onDismiss?: () => void;

@lucaslt89 lucaslt89 merged commit 4d9b173 into master Feb 10, 2023
@lucaslt89 lucaslt89 deleted the supporting-modal-queue branch February 10, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants