@jsenv/navi 0.27.41 → 0.27.42

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.
@@ -34878,7 +34878,7 @@ const Dialog = props => {
34878
34878
  addCleanup(trapScrollInside(dialogEl));
34879
34879
  }
34880
34880
  if (centerInVisualViewportProp && window.visualViewport) {
34881
- const centerInVisualViewport = () => {
34881
+ const updatePosition = () => {
34882
34882
  const vv = window.visualViewport;
34883
34883
  const dialogHeight = dialogEl.offsetHeight;
34884
34884
  const availableHeight = vv.height;
@@ -34886,12 +34886,28 @@ const Dialog = props => {
34886
34886
  const marginTop = availableHeight > dialogHeight ? topOffset + (availableHeight - dialogHeight) / 2 : topOffset;
34887
34887
  dialogEl.style.setProperty("--dialog-top-inset", `${snapToPixel(marginTop)}px`);
34888
34888
  };
34889
- centerInVisualViewport();
34890
- window.visualViewport.addEventListener("resize", centerInVisualViewport);
34891
- window.visualViewport.addEventListener("scroll", centerInVisualViewport);
34889
+ const onScroll = () => {
34890
+ updatePosition();
34891
+ };
34892
+ let resizeTimeout;
34893
+ const cancelDelayedUpdatePosition = () => {
34894
+ clearTimeout(resizeTimeout);
34895
+ };
34896
+ const onResize = () => {
34897
+ // On mobile, tapping from one input to another triggers a resize because
34898
+ // the virtual keyboard briefly starts to close before the new input receives
34899
+ // focus and the keyboard reopens. Debouncing prevents repositioning the
34900
+ // dialog during that transient state, which would cause a visible flicker.
34901
+ cancelDelayedUpdatePosition();
34902
+ resizeTimeout = setTimeout(updatePosition, 100);
34903
+ };
34904
+ updatePosition();
34905
+ window.visualViewport.addEventListener("resize", onResize);
34906
+ window.visualViewport.addEventListener("scroll", onScroll);
34892
34907
  addCleanup(() => {
34893
- window.visualViewport.removeEventListener("resize", centerInVisualViewport);
34894
- window.visualViewport.removeEventListener("scroll", centerInVisualViewport);
34908
+ cancelDelayedUpdatePosition();
34909
+ window.visualViewport.removeEventListener("resize", onResize);
34910
+ window.visualViewport.removeEventListener("scroll", onScroll);
34895
34911
  dialogEl.style.removeProperty("--dialog-top-inset");
34896
34912
  });
34897
34913
  }