fix: 滑卡退出距离自适应屏幕宽度,小屏设备体验更顺滑
This commit is contained in:
@@ -13,7 +13,8 @@ import RestaurantCard from "./RestaurantCard";
|
|||||||
import { Restaurant, SwipeDirection } from "@/types";
|
import { Restaurant, SwipeDirection } from "@/types";
|
||||||
|
|
||||||
const SWIPE_THRESHOLD = 120;
|
const SWIPE_THRESHOLD = 120;
|
||||||
const EXIT_X = 600;
|
const getExitX = () =>
|
||||||
|
typeof window !== "undefined" ? window.innerWidth * 1.5 : 600;
|
||||||
const ROTATION_RANGE = 18;
|
const ROTATION_RANGE = 18;
|
||||||
|
|
||||||
interface SwipeableCardProps {
|
interface SwipeableCardProps {
|
||||||
@@ -66,7 +67,8 @@ export default function SwipeableCard({
|
|||||||
const flyOut = (direction: SwipeDirection) => {
|
const flyOut = (direction: SwipeDirection) => {
|
||||||
if (isSwiping.current) return;
|
if (isSwiping.current) return;
|
||||||
isSwiping.current = true;
|
isSwiping.current = true;
|
||||||
const exitX = direction === "right" ? EXIT_X : -EXIT_X;
|
const exit = getExitX();
|
||||||
|
const exitX = direction === "right" ? exit : -exit;
|
||||||
animate(x, exitX, {
|
animate(x, exitX, {
|
||||||
type: "spring",
|
type: "spring",
|
||||||
stiffness: 600,
|
stiffness: 600,
|
||||||
|
|||||||
Reference in New Issue
Block a user