StackedRouter: new router simulates app behaviour #45
					 1 changed files with 29 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -15,7 +15,7 @@ import {
 | 
			
		|||
import { createStore, unwrap } from "solid-js/store";
 | 
			
		||||
import { insert, render } from "solid-js/web";
 | 
			
		||||
import "./StackedRouter.css";
 | 
			
		||||
import { animateSlideInFromRight } from "./anim";
 | 
			
		||||
import { animateSlideInFromRight, animateSlideOutToRight } from "./anim";
 | 
			
		||||
import { ANIM_CURVE_DECELERATION, ANIM_CURVE_STD } from "../material/theme";
 | 
			
		||||
 | 
			
		||||
export type StackedRouterProps = Omit<RouterProps, "url">;
 | 
			
		||||
| 
						 | 
				
			
			@ -102,6 +102,32 @@ function onDialogClick(
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function animateClose(element: HTMLElement) {
 | 
			
		||||
  if (window.innerWidth <= 560) {
 | 
			
		||||
    return animateSlideOutToRight(element, { easing: ANIM_CURVE_DECELERATION });
 | 
			
		||||
  } else {
 | 
			
		||||
    return element.animate(
 | 
			
		||||
      {
 | 
			
		||||
        opacity: [0.5, 0],
 | 
			
		||||
      },
 | 
			
		||||
      { easing: ANIM_CURVE_STD, duration: 220 },
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function animateOpen(element: HTMLElement) {
 | 
			
		||||
  if (window.innerWidth <= 560) {
 | 
			
		||||
    animateSlideInFromRight(element, { easing: ANIM_CURVE_DECELERATION });
 | 
			
		||||
  } else {
 | 
			
		||||
    element.animate(
 | 
			
		||||
      {
 | 
			
		||||
        opacity: [0.5, 1],
 | 
			
		||||
      },
 | 
			
		||||
      { easing: ANIM_CURVE_STD, duration: 220 },
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The router that stacks the pages.
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -130,12 +156,7 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
 | 
			
		|||
        const lastFrame = stack[stack.length - 1];
 | 
			
		||||
        const element = document.getElementById(lastFrame.rootId)!;
 | 
			
		||||
        requestAnimationFrame(() => {
 | 
			
		||||
          const animation = element.animate(
 | 
			
		||||
            {
 | 
			
		||||
              opacity: [0.5, 0],
 | 
			
		||||
            },
 | 
			
		||||
            { easing: ANIM_CURVE_STD, duration: 220 },
 | 
			
		||||
          );
 | 
			
		||||
          const animation = animateClose(element);
 | 
			
		||||
          animation.addEventListener("finish", () =>
 | 
			
		||||
            mutStack((o) => o.toSpliced(o.length - depth, depth)),
 | 
			
		||||
          );
 | 
			
		||||
| 
						 | 
				
			
			@ -162,16 +183,7 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
 | 
			
		|||
    createEffect(() => {
 | 
			
		||||
      requestAnimationFrame(() => {
 | 
			
		||||
        element.showModal();
 | 
			
		||||
        if (window.innerWidth <= 560) {
 | 
			
		||||
          animateSlideInFromRight(element, { easing: ANIM_CURVE_DECELERATION });
 | 
			
		||||
        } else {
 | 
			
		||||
          element.animate(
 | 
			
		||||
            {
 | 
			
		||||
              opacity: [0.5, 1],
 | 
			
		||||
            },
 | 
			
		||||
            { easing: ANIM_CURVE_STD, duration: 220 },
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
        animateOpen(element);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue