mo22 / react-native-mo-orientation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-mo-orientation

Lets you query and lock the device orientation

Installation

Install just like your ordinary react-native module.

Usage

import { Orientation, OrientationConsumer, OrientationLock } from 'react-native-mo-orientation';

console.log(Orientation.interfaceOrientation.value);

const sub = Orientation.interfaceOrientation.subscribe((orientation) => {
});
// ...
sub.release();

return (
  <OrientationLock allowed="portrait" />
  <OrientationLock allowed="any" />
);

return (
  <OrientationConsumer>
    {(orientation) => (
      <SomeObject orientation={orientation} />
    )}
  </OrientationConsumer>
)

Notes

  • On iOS the orientation lock is implemented by swizzeling the application:supportedInterfaceOrientationsForWindow: selector on the active app delegate. This is done only if setOrientation is ever called. This means that if you had that selector implemented it will not be called any more.

  • On iPad/universal apps the orientation locking only works for full screen apps

  • Android cannot handle orientation locks like portrait + landscapeleft. A console.warn will be given in dev mode.

TODO

  • check which is the correct field for orientations (check tablet etc.?) on android
    • display.getRotation() or configuration.getOrientation() ?
    • on galaxy tab and phones getRotation works out
  • ios does not rotate back if allowed orientations are changed

About


Languages

Language:TypeScript 53.2%Language:Objective-C 23.5%Language:Java 18.9%Language:Shell 2.3%Language:Ruby 2.1%