fab keep at the last position

This commit is contained in:
Gabe Yuan
2023-08-16 22:38:58 +08:00
parent 7de712b2b0
commit 7b6391a673
5 changed files with 31 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { limitNumber } from "../../libs/utils";
import { isMobile } from "../../libs/mobile";
import { setFab } from "../../libs";
const getEdgePosition = (
{ x: left, y: top, edge },
@@ -88,7 +89,7 @@ export default function Draggable({
setEdgeTimer(
setTimeout(() => {
setPosition((pre) => getHidePosition(pre, w, h, width, height));
}, 2000)
}, 1500)
);
}, []);
@@ -149,6 +150,15 @@ export default function Draggable({
goEdge(windowSize.w, windowSize.h, width, height);
}, [snapEdge, goEdge, windowSize.w, windowSize.h, width, height]);
useEffect(() => {
if (position.hide) {
setFab({
x: position.x,
y: position.y,
});
}
}, [position]);
const opacity = useMemo(() => {
if (snapEdge) {
return position.hide ? 0.1 : 1;

View File

@@ -12,7 +12,7 @@ import { StoragesProvider } from "../../hooks/Storage";
import Popup from "../Popup";
import { debounce } from "../../libs/utils";
export default function Action({ translator }) {
export default function Action({ translator, fab }) {
const fabWidth = 40;
const [showPopup, setShowPopup] = useState(false);
const [windowSize, setWindowSize] = useState({
@@ -76,8 +76,8 @@ export default function Action({ translator }) {
windowSize,
width: fabWidth,
height: fabWidth,
left: windowSize.w - fabWidth,
top: windowSize.h / 2,
left: fab.x ?? windowSize.w - fabWidth,
top: fab.y ?? windowSize.h / 2,
};
return (