mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
support native haptics
This commit is contained in:
parent
5353780c67
commit
4634691b31
@ -1,4 +1,5 @@
|
|||||||
import Core from "evite/src/core"
|
import Core from "evite/src/core"
|
||||||
|
import { Haptics } from "@capacitor/haptics"
|
||||||
|
|
||||||
const vibrationPatterns = {
|
const vibrationPatterns = {
|
||||||
light: [10],
|
light: [10],
|
||||||
@ -19,6 +20,10 @@ export default class HapticsCore extends Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onInitialize() {
|
async onInitialize() {
|
||||||
|
if (window.navigator.userAgent === "capacitor") {
|
||||||
|
navigator.vibrate = this.nativeVibrate
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("click", this.handleClickEvent)
|
document.addEventListener("click", this.handleClickEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +32,18 @@ export default class HapticsCore extends Core {
|
|||||||
vibrate: this.vibrate.bind(this),
|
vibrate: this.vibrate.bind(this),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nativeVibrate = (pattern) => {
|
||||||
|
if (!Array.isArray(pattern)) {
|
||||||
|
pattern = [pattern]
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < pattern.length; i++) {
|
||||||
|
Haptics.vibrate({
|
||||||
|
duration: pattern[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleClickEvent = (event) => {
|
handleClickEvent = (event) => {
|
||||||
const button = event.target.closest("button") || event.target.closest(".ant-btn")
|
const button = event.target.closest("button") || event.target.closest(".ant-btn")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user