npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-expo-device-orientation

v1.0.7

Published

This package helps you to get the device's current orientation data using the Accelerometer sensor.

Downloads

151

Readme

React Native Expo Device Orientation

A React Native Expo package for detecting device orientation changes and providing the current orientation of the device.

It provide the orientation data using Accelerometer sensor of your device.

It does not depend on device's screen orientation, you can get device orientation data without rotating your app screen.

Features

  • Detects device orientation changes.
  • Provides the current orientation of the device.
  • Lightweight and easy to use.
  • Supports both Android and iOS.

Values

  • 0° = PORTRAIT_UP
  • 90° = LANDSCAPE_LEFT
  • -90° = LANDSCAPE_RIGHT
  • 180° = PORTRAIT_DOWN

Installation

npm i react-native-expo-device-orientation

Use In EXPO App

  1. Install the react-native-expo-device-orientation package.
npm i react-native-expo-device-orientation
  1. Import in your project.
    import { useDeviceOrientation } from 'react-native-expo-device-orientation';

  2. Use in your project
    const orientation = useDeviceOrientation();

Example Code

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { useDeviceOrientation } from 'react-native-expo-device-orientation'; // importing

export default function App() {
const orientation = useDeviceOrientation(); // getting orientation data

// You can customize the accelerometer update interval (in milliseconds)
// by passing an object to useDeviceOrientation. The default is 1000ms (1 second).
// Example:
// const orientation = useDeviceOrientation({
//   accelerometerUpdateInterval: 100, // sets update interval to 100ms
// });
//
// Note: Starting from Android 12 (API level 31), the system has a 200ms limit for sensor updates.
// If you need an update interval less than 200ms, you should:
// - Add `android.permission.HIGH_SAMPLING_RATE_SENSORS` to the app.json permissions field.
// - If you are using the bare workflow, add <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"/>
//   to your AndroidManifest.xml.

return (
<View style={styles.container}>
<Text style={styles.orientationText}>Orientation: {orientation}°</Text> // 0° = PORTRAIT_UP , 90° = LANDSCAPE_LEFT , -90° = LANDSCAPE_RIGHT , 180° = PORTRAIT_DOWN
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 20,
},
orientationText: {
textAlign: 'center',
marginTop: 20,
fontSize: 18,
},
});

Use In bare REACT-NATIVE App

  1. Install the react-native-expo-device-orientation package.
npm i react-native-expo-device-orientation
  1. Import in your project.
    import { useDeviceOrientation } from 'react-native-expo-device-orientation';

  2. To install and use Expo modules in bare REACT-NATIVE App , the easiest way to get up and running is with the install-expo-modules command.

    npx install-expo-modules@latest
  3. Use in your project
    const orientation = useDeviceOrientation();

info: Your project should work perfectly, if not working properly try to reopen the project. If still not working try manual installing of Expo modules in React Native 0.74. Manually repeating step 3.

Example Code


import React from 'react';

import {

Text,

View,
} from 'react-native';

import { useDeviceOrientation } from 'react-native-expo-device-orientation';

function App(): React.JSX.Element {

const ori=useDeviceOrientation();

return (
<View>
<Text> Orientation = {ori} </Text> // 0° = PORTRAIT_UP , 90° = LANDSCAPE_LEFT , -90° = LANDSCAPE_RIGHT , 180° = PORTRAIT_DOWN
</View>
);
}

export default App;
  • Feel free to contribute

NOTE: Submit a Pull Request to the contrib-testing branch of the main repository. All contributions will be reviewed and tested on the contrib-testing branch before being merged into main

GitHub

LinkedIn