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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-nitro-orientation

v0.0.6

Published

react-native-nitro-orientation is a react native package built with Nitro

Readme

react-native-nitro-orientation

Native orientation control for React Native built with Nitro Modules.

Overview

This module provides native-level orientation detection and locking capabilities for both Android and iOS. It exposes simple JS/TS APIs to read UI and device orientation, lock/unlock orientations, and listen to orientation events emitted from native.

Features

  • Read UI orientation and device (sensor) orientation
  • Lock to portrait / portraitUpsideDown / landscapeLeft / landscapeRight
  • Unlock to allow all orientations
  • Listen to orientation change events with a simple callback API
  • Built with Nitro Modules for native performance and autolinking support

Requirements

  • React Native >= 0.76
  • Node >= 18
  • react-native-nitro-modules must be installed (Nitro runtime)

Installation

npm install react-native-nitro-orientation react-native-nitro-modules
# or
yarn add react-native-nitro-orientation react-native-nitro-modules

Configuration

iOS

Add the following to your project's AppDelegate.mm:


+#import <NitroOrientation/NitroOrientation.h>

@implementation AppDelegate

// ...

+- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
+  return [NitroOrientation getOrientation];
+}

@end

Android

Add following to android/app/src/main/AndroidManifest.xml

      <activity
        ....
+       android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">

          ....

      </activity>

Implement onConfigurationChanged method (in MainActivity.kt)


import android.content.Intent
import android.content.res.Configuration

// ...


class MainActivity : ReactActivity() {
//...
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        val intent = Intent("onConfigurationChanged")
        intent.putExtra("newConfig", newConfig)
        this.sendBroadcast(intent)
    }
}

Add following to MainApplication.kt


import com.margelo.nitro.orientation.NitroOrientationActivityLifecycle
//...

class MainApplication : Application(), ReactApplication {
  override fun onCreate() {
    //...
    registerActivityLifecycleCallbacks(NitroOrientationActivityLifecycle.instance)
  }
}

Quick usage (JS/TS)

import {
  getOrientation,
  getDeviceOrientation,
  lockToPortrait,
  lockToLandscape,
  unlockAllOrientations,
  Orientation,
} from 'react-native-nitro-orientation'

// UI orientation
const ui = getOrientation()

// Device orientation from sensors
const device = getDeviceOrientation()

// Lock / unlock
lockToPortrait()
lockToLandscape()
unlockAllOrientations()

// Listen to orientation changes
const handleOrientationChange = (orientation: 'portrait' | 'landscape') => {
  console.log('Orientation changed to:', orientation)
}

Orientation.addOrientationListener(handleOrientationChange)

// Don't forget to remove the listener when component unmounts
Orientation.removeOrientationListener(handleOrientationChange)

API

Orientation Control

  • getOrientation(): string — returns one of: portrait, portraitUpsideDown, landscapeLeft, landscapeRight, unknown
  • getDeviceOrientation(): string — orientation from device sensors
  • lockToPortrait(): void
  • lockToPortraitUpsideDown(): void
  • lockToLandscape(): void — sensor-based landscape (Android)
  • lockToLandscapeLeft(): void
  • lockToLandscapeRight(): void
  • unlockAllOrientations(): void
  • getAutoRotateState(): boolean — (Android) returns whether Auto-Rotate is enabled

Event Listening

  • Orientation.addOrientationListener(callback) — add a listener for orientation changes
  • Orientation.removeOrientationListener(callback) — remove a previously added listener

The callback receives one parameter: orientation: 'portrait' | 'landscape'

Events

The module provides a simple event listening API through the Orientation manager:

import { useEffect } from 'react'
import { Orientation } from 'react-native-nitro-orientation'

useEffect(() => {
  const handleOrientationChange = (orientation: 'portrait' | 'landscape') => {
    console.log('Orientation changed to:', orientation)
  }

  // Add listener
  Orientation.addOrientationListener(handleOrientationChange)

  // Cleanup
  return () => {
    Orientation.removeOrientationListener(handleOrientationChange)
  }
}, [])

Advanced examples

import {
  lockToLandscapeLeft,
  lockToLandscapeRight,
  lockToLandscape,
  Orientation,
} from 'react-native-nitro-orientation'

// Lock to landscape left
lockToLandscapeLeft()

// Lock to landscape right
lockToLandscapeRight()

// Sensor-based landscape (Android)
lockToLandscape()

// Create a custom hook for orientation changes
const useOrientation = () => {
  const [orientation, setOrientation] = useState<'portrait' | 'landscape'>('portrait')

  useEffect(() => {
    const handleChange = (newOrientation: 'portrait' | 'landscape') => {
      setOrientation(newOrientation)
    }

    Orientation.addOrientationListener(handleChange)

    return () => {
      Orientation.removeOrientationListener(handleChange)
    }
  }, [])

  return orientation
}

Platform Support

Android

  • ✅ Full support

iOS

  • 🚧 In development

Troubleshooting

  • Events not emitted on Android: ensure NitroOrientationActivityLifecycle is registered in your Application and Nitro runtime provides applicationContext.
  • On iOS, if requestGeometryUpdate does not change UI orientation: verify Info.plist and supportedInterfaceOrientationsFor implementation.
  • Make sure to remove orientation listeners when components unmount to avoid memory leaks.

Migration / notes

  • Orientation strings used by the module: portrait, portraitUpsideDown, landscapeLeft, landscapeRight, unknown.
  • Event callbacks receive simplified orientation values: 'portrait' | 'landscape'.
  • When updating spec files in src/specs/*.nitro.ts, regenerate Nitro artifacts:
npx nitro-codegen

Contributing

See CONTRIBUTING.md for contribution workflow. Run npx nitro-codegen after editing spec files.

Project structure

  • android/ — native Android (Kotlin)
  • ios/ — native iOS (Swift / ObjC bridge)
  • src/ — TypeScript exports
  • nitrogen/ — generated Nitro artifacts

Acknowledgements

Special thanks to the following open-source projects which inspired and supported the development of this library:

License

MIT © Thành Công