touch operation...

This commit is contained in:
Gabe Yuan
2023-11-10 18:00:34 +08:00
parent 6805340a9a
commit 46428b7c7f
7 changed files with 189 additions and 2 deletions

19
src/hooks/Touch.js Normal file
View File

@@ -0,0 +1,19 @@
import { useCallback } from "react";
import { DEFAULT_TOUCH_OPERATION } from "../config";
import { useSetting } from "./Setting";
export function useTouch(action) {
const { setting, updateSetting } = useSetting();
const touchOperations = setting?.touchOperations || DEFAULT_TOUCH_OPERATION;
const touchOperation = touchOperations[action];
const setTouchOperation = useCallback(
async (val, idx) => {
touchOperations[action][idx] = val;
await updateSetting({ touchOperations: { ...touchOperations } });
},
[action, touchOperations, updateSetting]
);
return { touchOperation, setTouchOperation };
}