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

Haptics Web Implementation #4

Closed
cameronrr opened this issue Jul 29, 2020 · 2 comments · Fixed by #5
Closed

Haptics Web Implementation #4

cameronrr opened this issue Jul 29, 2020 · 2 comments · Fixed by #5

Comments

@cameronrr
Copy link

cameronrr commented Jul 29, 2020

Feature Request

Plugin

HapticsWeb (extends WebPlugin implements HapticsPlugin)

Description

Haptics has native implementations, but no web implementation. The web plugin will make use of the web Vibration API to deliver functionality on vibration enabled devices (i.e. mobile). Note that some browsers implement permissions i.e. prompting the user to allow vibration when first run.

Platform(s)

Web

Preferred Solution

A Capacitor plugin which exposes the following functionality:

Vibration Example Code Behaviour
Once navigator.vibrate(1000) or navigator.vibrate([1000]) Vibrate for 1000ms
Sequence navigator.vibrate([50, 100, 150]) Vibrate for 50ms, still for 100ms, vibrate for 150ms
Cancel navigator.vibrate(0) or navigator.vibrate([]) Cancels any existing vibrations

New Plugin

export declare type HapticsWebVibratePattern = number | number[]
export declare class HapticsWeb extends WebPlugin implements HapticsPlugin {
    constructor()
    impact(): void;
    notification(): void;
    vibrate(options: HapticsWebVibratePattern): Promise<any>
    selectionStart(): void;
    selectionChanged(): void;
    selectionEnd(): void;
}

Vibrate Functionality

HapticsWeb.prototype.vibrate = function (options) {
    if (!navigator.vibrate) {
        return Promise.reject('Web Haptics API not available');
    }
    return navigator.vibrate(options);
};

Additional Context

W3C Vibration API: https://www.w3.org/TR/vibration/
Google Chrome Samples: https://googlechrome.github.io/samples/vibration/
MDN Web Docs: https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API/

@cameronrr
Copy link
Author

node_modules\@capacitor\core\dist\esm\core-plugin-definitions.d.ts contains interface VibrateOptions but this never seems to be assigned anywhere i.e. not to HapticsPlugin.vibrate().

export interface VibrateOptions {
    duration?: number;
}

The Web API requires options (a pattern) to be passed as number | number[]. It might be needed to review the implementation of VibrateOptions in order to use the same vibrate() method consistently across platforms.

@imhoffd imhoffd added the enhancement New feature or request label Jul 29, 2020
@imhoffd imhoffd linked a pull request Jul 31, 2020 that will close this issue
kpatfln pushed a commit to kpatfln/capacitor-plugins that referenced this issue Sep 5, 2022
Restrict animated Splash Screen for Android 7.1 and below
@ionitron-bot
Copy link

ionitron-bot bot commented Sep 30, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants