Skip to content

Commit fdc382d

Browse files
authored
chore(example): Add Haptics page (tauri-apps#2032)
1 parent b2aea04 commit fdc382d

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

examples/api/src-tauri/capabilities/mobile.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"geolocation:allow-check-permissions",
1616
"geolocation:allow-request-permissions",
1717
"geolocation:allow-watch-position",
18-
"geolocation:allow-get-current-position"
18+
"geolocation:allow-get-current-position",
19+
"haptics:allow-impact-feedback",
20+
"haptics:allow-notification-feedback",
21+
"haptics:allow-selection-feedback",
22+
"haptics:allow-vibrate"
1923
]
2024
}

examples/api/src/App.svelte

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import Scanner from './views/Scanner.svelte'
2222
import Biometric from './views/Biometric.svelte'
2323
import Geolocation from './views/Geolocation.svelte'
24+
import Haptics from './views/Haptics.svelte'
2425
2526
import { onMount, tick } from 'svelte'
2627
import { ask } from '@tauri-apps/plugin-dialog'
@@ -130,6 +131,11 @@
130131
label: 'Geolocation',
131132
component: Geolocation,
132133
icon: 'i-ph-map-pin'
134+
},
135+
isMobile && {
136+
label: 'Haptics',
137+
component: Haptics,
138+
icon: 'i-ph-vibrate'
133139
}
134140
]
135141

examples/api/src/views/Haptics.svelte

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script>
2+
import {
3+
vibrate,
4+
impactFeedback,
5+
notificationFeedback,
6+
selectionFeedback
7+
} from '@tauri-apps/plugin-haptics'
8+
9+
export let onMessage
10+
</script>
11+
12+
<div>
13+
<button
14+
class="btn"
15+
on:click={() => vibrate(300).then(onMessage).catch(onMessage)}
16+
>vibrate short</button
17+
>
18+
<button
19+
class="btn"
20+
on:click={() => vibrate(1500).then(onMessage).catch(onMessage)}
21+
>vibrate long</button
22+
>
23+
<button
24+
class="btn"
25+
on:click={() => impactFeedback('medium').then(onMessage).catch(onMessage)}
26+
>impact medium</button
27+
>
28+
<button
29+
class="btn"
30+
on:click={() =>
31+
notificationFeedback('warning').then(onMessage).catch(onMessage)}
32+
>notification warning</button
33+
>
34+
<button
35+
class="btn"
36+
on:click={() => selectionFeedback().then(onMessage).catch(onMessage)}
37+
>selection</button
38+
>
39+
</div>
40+
41+
<br />
42+
43+
<p>
44+
Depending on your device settings for haptic feedback some of the buttons may
45+
not work.
46+
</p>

plugins/deep-link/api-iife.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)