Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(example): Add Haptics page #2032

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading