Skip to content

Commit

Permalink
chore(example): Add Haptics page (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars authored Nov 11, 2024
1 parent b2aea04 commit fdc382d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
6 changes: 5 additions & 1 deletion examples/api/src-tauri/capabilities/mobile.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"geolocation:allow-check-permissions",
"geolocation:allow-request-permissions",
"geolocation:allow-watch-position",
"geolocation:allow-get-current-position"
"geolocation:allow-get-current-position",
"haptics:allow-impact-feedback",
"haptics:allow-notification-feedback",
"haptics:allow-selection-feedback",
"haptics:allow-vibrate"
]
}
6 changes: 6 additions & 0 deletions examples/api/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Scanner from './views/Scanner.svelte'
import Biometric from './views/Biometric.svelte'
import Geolocation from './views/Geolocation.svelte'
import Haptics from './views/Haptics.svelte'
import { onMount, tick } from 'svelte'
import { ask } from '@tauri-apps/plugin-dialog'
Expand Down Expand Up @@ -130,6 +131,11 @@
label: 'Geolocation',
component: Geolocation,
icon: 'i-ph-map-pin'
},
isMobile && {
label: 'Haptics',
component: Haptics,
icon: 'i-ph-vibrate'
}
]
Expand Down
46 changes: 46 additions & 0 deletions examples/api/src/views/Haptics.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script>
import {
vibrate,
impactFeedback,
notificationFeedback,
selectionFeedback
} from '@tauri-apps/plugin-haptics'
export let onMessage
</script>

<div>
<button
class="btn"
on:click={() => vibrate(300).then(onMessage).catch(onMessage)}
>vibrate short</button
>
<button
class="btn"
on:click={() => vibrate(1500).then(onMessage).catch(onMessage)}
>vibrate long</button
>
<button
class="btn"
on:click={() => impactFeedback('medium').then(onMessage).catch(onMessage)}
>impact medium</button
>
<button
class="btn"
on:click={() =>
notificationFeedback('warning').then(onMessage).catch(onMessage)}
>notification warning</button
>
<button
class="btn"
on:click={() => selectionFeedback().then(onMessage).catch(onMessage)}
>selection</button
>
</div>

<br />

<p>
Depending on your device settings for haptic feedback some of the buttons may
not work.
</p>
2 changes: 1 addition & 1 deletion plugins/deep-link/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdc382d

Please sign in to comment.