Socket
Book a DemoInstallSign in
Socket

device-motion

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

device-motion

A package to work with the device-motion API..

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

device-motion

Build Status Greenkeeper badge SonarCloud badge SonarCloud Coverage

This repository contains a little library I created to react on device-motion events.

Installation npm

npm install device-motion # OR yarn add device-motion

Sample

The following sample demonstrates how I use it with React.

import React from "react";

import { Seismograph } from "device-motion";

export default class SeismographDemo extends React.Component {
  constructor(props) {
    super(props);
    this.seismograph = null;
  }

  componentDidMount = () => {
    if (!this.seismograph) {
      this.seismograph = new Seismograph({
        minShakes: this.props.minShakes || 3,
        minAmplitude: this.props.minAmplitude || 3,
        onShake: this.onShake,
        delay: this.props.delay || 1500
      });
    }
    this.seismograph.startRecording();
  };

  componentWillUnmount() {
    if (this.seismograph) {
      this.seismograph.stopRecording();
    }
  };

  onShake = () => {
      ...
  };

  render = () => {
      ...
  };
}

Keywords

device-motion

FAQs

Package last updated on 08 Oct 2019

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