Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lesca-sensor-orientation

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lesca-sensor-orientation

The mobile device orientation. include request permission and return 3 axis value.

  • 1.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

NPM React React React React React NPM

Why use it?

full steps for get mobile 3 axis value of mobile orientation.

See https://developer.mozilla.org/en-US/docs/Web/Events/Detecting_device_orientation for a demonstration!

Live Demo

Installation

npm install lesca-sensor-orientation --save

Usage

As a Node module:

import { useState, useEffect, useMemo } from 'react';
import Orientation from 'lesca-sensor-orientation';

// (1) waiting for permission => Must be user-triggered event and SSL required
// (2) add addEventListener
const Components = () => {
  const [state, setState] = useState(false);
  const orientation = useMemo(() => new Orientation(), []);

  const require_permission = () => {
    orientation
      .permission()
      .then(() => {
        // permission granted
        setState(true);
      })
      .catch(() => {
        // permission deined
      });
  };

  useEffect(() => {
    if (state) {
      orientation.addEventListener((e) => {
        alert(e);
      });
    }
    return () => {
      orientation.destory();
    };
  }, [state]);

  return <button onClick={require_permission}></button>;
};

Development

Methods

Methods

methoddescriptionreturn
.permission()ask user permissionvoid
addEventListener(callback:function)get 3 axis value each timevoid
.destory()destory eventvoid

Properties

Propertiesdescriptiondefault
disable:booleanstop / continue event listentrue
isSuppord:booleanpermission granted or deined(read only)

Features

  • TypeScript
  • maintain if necessary

Keywords

FAQs

Package last updated on 08 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc