react-native-orientation-angle
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

React Native Orientation Angle

npm version

A React Native module that allows you to get device orientation angle

Installation

yarn add react-native-orientation-angle

# RN >= 0.60
cd ios && pod install

API

subscribe()

Subscribe to device motion

orientationAngle.subscribe((angles) => {
  console.log(angles) // { pitch: 0, roll: 0, yaw: 0 }
})

unsubscribe()

Unsubscribe from device motion

orientationAngle.unsubscribe()

setUpdateInterval()

Set update interval in milliseconds (100, 200, 300)

orientationAngle.setUpdateInterval(100) // milliseconds

getUpdateInterval()

Get update interval in milliseconds

orientationAngle.getUpdateInterval((milliseconds) => {
  console.log(milliseconds)
})

Hook Usage

import { useEffect } from 'react'
import { orientationAngle } from 'react-native-orientation-angle'

export const useOrientationAngle = () => {
  useEffect(() => {
    orientationAngle.setUpdateInterval(300)

    orientationAngle.subscribe((angles) => {
      console.log(angles)
    })

    return () => {
      orientationAngle.unsubscribe()
    }
  }, [])
}

License

MIT

Package Sidebar

Install

npm i react-native-orientation-angle

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

331 kB

Total Files

109

Last publish

Collaborators

  • dzvlk