@ahnseungchan/webviewkit 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/constants.ts
2
- var STACK_TRANSITION_MS = 300;
2
+ var STACK_TRANSITION_MS = 500;
3
3
  var TRANSITION_END_GRACE_MS = 50;
4
4
  var BACK_TIMEOUT_MS = 1e3;
5
5
  var BRIDGE_TIMEOUT_MS = 5e3;
@@ -815,22 +815,33 @@ import { css, keyframes } from "@emotion/react";
815
815
  import styled2 from "@emotion/styled";
816
816
  import { useLayoutEffect, useRef as useRef2 } from "react";
817
817
  import { jsx as jsx4 } from "@emotion/react/jsx-runtime";
818
- var slideInRight = keyframes`
818
+ var IOS_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
819
+ var FADE_EASING = "ease";
820
+ var PARALLAX_OFFSET = "-30%";
821
+ var coverIn = keyframes`
819
822
  from { transform: translate3d(100%, 0, 0); }
820
823
  to { transform: translate3d(0, 0, 0); }
821
824
  `;
822
- var slideOutLeft = keyframes`
823
- from { transform: translate3d(0, 0, 0); opacity: 1; }
824
- to { transform: translate3d(-30%, 0, 0); opacity: 0.6; }
825
- `;
826
- var slideInLeft = keyframes`
827
- from { transform: translate3d(-30%, 0, 0); opacity: 0.6; }
828
- to { transform: translate3d(0, 0, 0); opacity: 1; }
829
- `;
830
- var slideOutRight = keyframes`
825
+ var coverOut = keyframes`
831
826
  from { transform: translate3d(0, 0, 0); }
832
827
  to { transform: translate3d(100%, 0, 0); }
833
828
  `;
829
+ var parallaxOut = keyframes`
830
+ from { transform: translate3d(0, 0, 0); }
831
+ to { transform: translate3d(${PARALLAX_OFFSET}, 0, 0); }
832
+ `;
833
+ var parallaxIn = keyframes`
834
+ from { transform: translate3d(${PARALLAX_OFFSET}, 0, 0); }
835
+ to { transform: translate3d(0, 0, 0); }
836
+ `;
837
+ var dimIn = keyframes`
838
+ from { opacity: 0; }
839
+ to { opacity: 1; }
840
+ `;
841
+ var dimOut = keyframes`
842
+ from { opacity: 1; }
843
+ to { opacity: 0; }
844
+ `;
834
845
  var fadeIn = keyframes`
835
846
  from { opacity: 0; }
836
847
  to { opacity: 1; }
@@ -839,14 +850,27 @@ var fadeOut = keyframes`
839
850
  from { opacity: 1; }
840
851
  to { opacity: 0; }
841
852
  `;
842
- var SLIDE_KEYFRAMES = {
843
- push: { enter: slideInRight, exit: slideOutLeft },
844
- pop: { enter: slideInLeft, exit: slideOutRight }
845
- };
846
- var FADE_KEYFRAMES = { enter: fadeIn, exit: fadeOut };
847
- function pickKeyframes(transition, direction, pageState) {
848
- if (transition === "fade") return FADE_KEYFRAMES[pageState];
849
- return SLIDE_KEYFRAMES[direction][pageState];
853
+ var layerOf = (direction, pageState) => direction === "push" === (pageState === "enter") ? "upper" : "lower";
854
+ function slideStyles(direction, pageState, duration) {
855
+ const timing = `${duration}ms ${IOS_EASING} forwards`;
856
+ if (layerOf(direction, pageState) === "upper") {
857
+ return css`
858
+ animation: ${direction === "push" ? coverIn : coverOut} ${timing};
859
+ box-shadow: var(--wvk-edge-shadow, -6px 0 24px rgba(0, 0, 0, 0.12));
860
+ `;
861
+ }
862
+ return css`
863
+ animation: ${direction === "push" ? parallaxOut : parallaxIn} ${timing};
864
+ &::after {
865
+ content: "";
866
+ /* transform 중인 페이지 기준 fixed = 스크롤과 무관하게 페이지 전체를 덮음 */
867
+ position: fixed;
868
+ inset: 0;
869
+ pointer-events: none;
870
+ background: var(--wvk-dim-color, rgba(0, 0, 0, 0.12));
871
+ animation: ${direction === "push" ? dimIn : dimOut} ${timing};
872
+ }
873
+ `;
850
874
  }
851
875
  var PageWrapper = styled2.div`
852
876
  position: absolute;
@@ -859,10 +883,16 @@ var PageWrapper = styled2.div`
859
883
  ${({ pageState, direction, transitionType, duration }) => {
860
884
  if (pageState !== "enter" && pageState !== "exit") return "";
861
885
  if (transitionType === "none" || duration === 0) return "";
886
+ if (transitionType === "fade") {
887
+ return css`
888
+ will-change: opacity;
889
+ animation: ${pageState === "enter" ? fadeIn : fadeOut} ${duration}ms
890
+ ${FADE_EASING} forwards;
891
+ `;
892
+ }
862
893
  return css`
863
- will-change: transform, opacity;
864
- animation: ${pickKeyframes(transitionType, direction, pageState)}
865
- ${duration}ms ease-in-out forwards;
894
+ will-change: transform;
895
+ ${slideStyles(direction, pageState, duration)}
866
896
  `;
867
897
  }}
868
898
  `;
@@ -885,7 +915,9 @@ function StackPage({
885
915
  "data-state": wrapperProps.pageState,
886
916
  "aria-hidden": isTop ? void 0 : true,
887
917
  onAnimationEnd: (event) => {
888
- if (event.target === event.currentTarget) onAnimationEnd == null ? void 0 : onAnimationEnd();
918
+ if (event.target === event.currentTarget && !event.pseudoElement) {
919
+ onAnimationEnd == null ? void 0 : onAnimationEnd();
920
+ }
889
921
  },
890
922
  children
891
923
  }
@@ -1198,12 +1230,8 @@ function useStackNavigation(options) {
1198
1230
  const delta = Math.min(Math.max(1, count), entries.length - 1);
1199
1231
  const targetIndex = entries.length - 1 - delta;
1200
1232
  busyRef.current = true;
1201
- void history.travel(-delta).then((popped) => {
1202
- if (!popped) {
1203
- busyRef.current = false;
1204
- dispatch({ type: "POP_TO", index: targetIndex, animate: false });
1205
- }
1206
- });
1233
+ dispatch({ type: "POP_TO", index: targetIndex, animate: animate() });
1234
+ void history.travel(-delta);
1207
1235
  return true;
1208
1236
  }, []);
1209
1237
  const back = useCallback(() => pop(1), [pop]);