haptics
La traduction de cette page manque ou n'est plus à jour : elle s'affiche en anglais. Lire en anglais
Use haptics to confirm selection, communicate success or failure, or reinforce a physical-feeling interaction.
Distinguish selection, impact and notification feedback
import { HStack, Pressable, Text, haptics, signal } from 'kuito';
async function save(count: number): Promise<void> {
if (count > 9) throw new Error('At most 9 seats');
}
export function Seats() {
const count = signal(1);
return (
<HStack gap={12}>
<Pressable
onPress={() => {
count.value += 1;
void haptics.selection();
}}
>
<Text>{'Seats: ' + count.value}</Text>
</Pressable>
<Pressable
onPress={() => {
save(count.value).then(
() => haptics.notification('success'),
() => haptics.notification('error'),
);
}}
>
<Text>{haptics.supported ? 'Book' : 'Book (no haptics)'}</Text>
</Pressable>
</HStack>
);
}Behavior and limits
Use selection() for a changed choice, impact(style) for a collision-like response, and notification(type) for an outcome. supported reports device support. Simulators and devices without the relevant hardware may produce no feedback. Haptics should supplement a visible or spoken cue.
Continue
Read Pressable for the related workflow. The API reference lists every method, option, event and return type.
Référence
Exports 6
Méthodes, constantes et types exposés par cet espace de noms natif.
type
ImpactStyleThe weight of the collision haptics.impact plays: 'light', 'medium' or 'heavy'.typeNotificationTypeThe outcome a notification haptic reports: 'success', 'warning' or 'error'.valuesupportedWhether the device can play haptics.functionselectionThe tick of a picker or a segmented control changing value.functionimpactA collision of a UI element of the given weight.functionnotificationThe outcome of a task.Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.