diff --git a/src/components/mobile/Appartment/ViewControllerModal1.tsx b/src/components/mobile/Appartment/ViewControllerModal1.tsx index 96a88a8..9aa6241 100644 --- a/src/components/mobile/Appartment/ViewControllerModal1.tsx +++ b/src/components/mobile/Appartment/ViewControllerModal1.tsx @@ -1,13 +1,18 @@ import { useDrag } from "@use-gesture/react"; import { a, useSpring, config } from "@react-spring/web"; +import { useLayoutEffect, useState } from "react"; import styles from "./styles.module.css"; const items = ["save item", "open item", "share item", "delete item", "cancel"]; // const height = items.length * 60 + 80; -const height = items.length * 60 + 80; export default function ButtomPanel() { + const [height, setHeight] = useState(0); + useLayoutEffect(() => { + setHeight(window.screen.height); + }, []); + const [{ y }, api] = useSpring(() => ({ y: height })); const open = ({ canceled }) => { @@ -21,7 +26,7 @@ export default function ButtomPanel() { }; const close = (velocity = 0) => { api.start({ - y: height, + y: height - 64, immediate: false, config: { ...config.stiff, velocity }, }); @@ -38,14 +43,38 @@ export default function ButtomPanel() { }) => { // if the user drags up passed a threshold, then we cancel // the drag so that the sheet resets to its open position - if (oy < -70) cancel(); + if (oy < -10) cancel(); // when the user releases the sheet, we check whether it passed // the threshold for it to close, or if we reset it to its open positino if (last) { - oy > height * 0.5 || (vy > 0.5 && dy > 0) - ? close(vy) - : open({ canceled }); + // oy > height * 0.8 || (vy > 0.8 && dy > 0) + // ? close(vy) + // : open({ canceled }); + console.log("oy", oy); + if (oy > height * 0.8) { + console.log("close"); + close(vy); + } + if (oy < height * 0.8) { + console.log("open"); + open({ canceled }); + } + // else { + // } + // if (oy > height * 0.2 || (vy > 0.5 && dy > 0)) { + // console.log("close"); + // close(vy); + // } else if ((vy > 0.5 && dy < 0) || oy < height * 0.2) { + // console.log("open"); + // open({ canceled }); + // } + // if (oy > height * 0.5 || (vy > 0.5 && dy > 0)) { + // close(vy); + // } + // if (oy < height * 0.8) { + // open({ canceled }); + // } } // when the user keeps dragging, we just move the sheet according to // the cursor position @@ -61,30 +90,12 @@ export default function ButtomPanel() { const display = y.to((py) => (py < height ? "block" : "none")); - const bgStyle = { - transform: y.to( - [0, height], - ["translateY(-8%) scale(1.16)", "translateY(0px) scale(1.05)"] - ), - opacity: y.to([0, height], [0.4, 1], "clamp"), - }; return (
-
-