-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
lib/ModalPresenter.tsx
Outdated
export type ModalHandler = { | ||
/** | ||
* Same `dismiss` function as in `ModalContentProps`. | ||
*/ | ||
dismiss: () => void; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
There was a problem hiding this comment.
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?
lib/ModalPresenter.tsx
Outdated
if (ref) { | ||
// FIXME: set up a flag here to prevent multiple `dismiss` calls during the out animation. | ||
ref.animatedOut(() => { | ||
rootSiblings?.destroy(); |
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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)));
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
lib/ModalPresenter.tsx
Outdated
/** | ||
* Get notified when the modal is later dismissed. | ||
*/ | ||
onDismiss?: ModalDismissFunc; |
There was a problem hiding this comment.
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;
No description provided.