File size: 1,487 Bytes
4a5ef51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | export const TOUCH_GESTURES = [
{gesture: 'single_tap', label: 'Single tap'},
{gesture: 'double_tap', label: 'Double tap'},
{gesture: 'triple_tap', label: 'Triple tap'},
{gesture: 'long_press', label: 'Long press'},
{gesture: 'forward_swipe', label: 'Forward swipe'},
{gesture: 'backward_swipe', label: 'Backward swipe'},
{gesture: 'up_swipe', label: 'Up swipe'},
{gesture: 'down_swipe', label: 'Down swipe'},
] as const;
export type TouchGesture = (typeof TOUCH_GESTURES)[number]['gesture'];
export type TouchGestureDefaults = Record<TouchGesture, boolean>;
export function initialTouchGestureDefaults(): TouchGestureDefaults {
return Object.fromEntries(TOUCH_GESTURES.map(({gesture}) => [gesture, true])) as TouchGestureDefaults;
}
// Keep the example buildable with the published SDK until this API ships.
// The optional method has the same signature as the new public SDK entry point.
type TouchGestureSdk = {
setTouchGestureDefaultBehaviorEnabled?: (
gesture: TouchGesture,
enabled: boolean,
) => Promise<unknown>;
};
export async function applyTouchGestureDefault(
sdk: TouchGestureSdk,
gesture: TouchGesture,
enabled: boolean,
): Promise<void> {
if (typeof sdk.setTouchGestureDefaultBehaviorEnabled !== 'function') {
throw new Error('Touchpad controls require an SDK build with touch gesture default behavior support.');
}
await sdk.setTouchGestureDefaultBehaviorEnabled(gesture, enabled);
}
|