-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { IS_DOM } from "expo/dom"; | ||
import { useEffect } from "react"; | ||
|
||
// Function to determine the size scale based on button dimensions | ||
function getSizeScale(button: HTMLButtonElement) { | ||
const width = button.offsetWidth; | ||
const height = button.offsetHeight; | ||
const area = width * height; | ||
|
||
// Assign a scale based on button area (you can tweak these thresholds) | ||
if (area < 4000) { | ||
return 0; // Small | ||
} else if (area < 7000) { | ||
return 1; // Medium | ||
} else { | ||
return 2; // Large | ||
} | ||
} | ||
|
||
export function useGlobalButtonHaptics(haptics?: (size: number) => void) { | ||
if (!IS_DOM) { | ||
return null; | ||
} | ||
|
||
useEffect(() => { | ||
if (!haptics) return; | ||
|
||
const listener = (event: MouseEvent) => { | ||
// Check if the clicked element is a button | ||
if (event.target?.tagName === "BUTTON") { | ||
haptics(getSizeScale(event.target as HTMLButtonElement)); | ||
} | ||
}; | ||
// Global event listener for clicks | ||
document.addEventListener("click", listener); | ||
|
||
return () => { | ||
document.removeEventListener("click", listener); | ||
}; | ||
}, [haptics]); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters