1.0.1 • Published 2 years ago

react-native-orientation-angle v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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