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

Ability to dismiss all open modals at once #37

Open
furkanarabaci opened this issue Feb 13, 2019 · 0 comments
Open

Ability to dismiss all open modals at once #37

furkanarabaci opened this issue Feb 13, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@furkanarabaci
Copy link
Contributor

It would be nice to dismiss all open modals at once, based on the needs of not being able to push a different route ( parent directory ) inside of a modal. For example :

/user/register
/user/signIn/forgot/password ( modal )
/user/signIn/forgot/password/verify/email ( modal only accessible from modal )

When the user wants to navigate from /user/signIn/forgot/password/verify to /user/register, we need to dismiss both modals in order, otherwise it is not possible to navigate. To tackle that, we use a workaround to dismiss modals programmatically inside of routerDidEnter of the previous modal.

const DISMISS_TIMEOUT = 400;
...
StackRouter.of({
    path: "/user/signIn/forgot",
    modal: true,
    build: buildExtender({
    // Not necessary
    }),
    Route.of({
        path: "/user/signIn/forgot/password",
        build: {
             // Not necessary
        },
        routeDidEnter: (router, route) => {
            let { action, prevUrl } = router.getState();
            if (action === "POP" && prevUrl === "/user/signIn/forgot/password/verify/email") {
                setTimeout(() => {
                    router.dismiss(() => {}, false);
                }, DISMISS_TIMEOUT);
            }
         }
    }),
}),
Route.of({
    path: "/user/signIn",
    build: buildExtender({
    // Not necessary
    }),
    routeDidEnter: (router, route) => {
        if (router.getState().action === "POP") {
            setTimeout(() => {
                router.push("/user/register");
            }, DISMISS_TIMEOUT);
        }
    }
}),

The reason for timeout is explained in the #34
This will dismiss both modal and will navigate to the route in the parent directory.

Note: This code snippet is just a brief prototype of the case, it is not to take reference for best practice or an example of the router implementation.

With the feature of dismissAll() ( just an example for the name ), all of the routeEnter methods will not be needed. For example, inside of the page that has the modal of /user/signIn/forgot/password/verify/email

function goToRegister() {
    const page = this;
    page.router.dismissAll(() => {
        page.router.push("/user/register", false); // Not sure about the pushes without animation, did not test the exact usage.
   }, false);
}

Risks:

  • This will probably require to log every state of opened/closed modals in a different history
  • Modals ( routes ) which have a different parent directory might cause crashes or unexpected behaviors
  • Calling onShow() method on the page on dismiss action might cause some unexpected behaviors, since the modals will close instantly.

Remarks:

  • A different method like canDismissAll() to control the availability to dismiss every modal might be needed.
@furkanarabaci furkanarabaci added the enhancement New feature or request label Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants