Giter Site home page Giter Site logo

yamill / react-native-orientation Goto Github PK

View Code? Open in Web Editor NEW
1.7K 1.7K 803.0 242 KB

Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis.

Home Page: https://www.npmjs.com/package/react-native-orientation

License: ISC License

Objective-C 44.98% JavaScript 12.06% Java 38.84% Ruby 4.12%

react-native-orientation's Introduction

React Native Orientation

npm version

Listen to device orientation changes in React Native applications and programmatically set preferred orientation on a per screen basis. Works on both Android and iOS.

Installing

npm install react-native-orientation --save

Linking Native Dependencies

Automatic Linking

react-native link react-native-orientation

Please note that you still need to manually configure a couple files even when using automatic linking. Please see the 'Configuration' section below. You will also need to restart your simulator before the package will work properly.

Manual Linking

iOS

  1. Add node_modules/react-native-orientation/iOS/RCTOrientation.xcodeproj to your xcode project, usually under the Libraries group
  2. Add libRCTOrientation.a (from Products under RCTOrientation.xcodeproj) to build target's Linked Frameworks and Libraries list
  3. Add $(SRCROOT)/node_modules/react-native-orientation/iOS/RCTOrientation/ to Project Name -> Build Settings -> Header Search Paths

Android

  1. In android/setting.gradle

    ...
    include ':react-native-orientation', ':app'
    project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')
    
  2. In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':react-native-orientation')
    }
    
  3. Register module in MainApplication.java

    import com.github.yamill.orientation.OrientationPackage;  // <--- import
    
    public class MainApplication extends Application implements ReactApplication {
      ......
    
      @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new OrientationPackage()      <------- Add this
          );
      }
    
      ......
    
    }

Configuration

iOS

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

#import "Orientation.h" // <--- import

@implementation AppDelegate

  // ...

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

@end

Android

Implement onConfigurationChanged method in MainActivity.java

    import android.content.Intent; // <--- import
    import android.content.res.Configuration; // <--- import

    public class MainActivity extends ReactActivity {
      ......
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        this.sendBroadcast(intent);
    }

      ......

    }

Usage

To use the react-native-orientation package in your codebase, you should use the Orientation module:

import Orientation from 'react-native-orientation';
export default class AppScreen extends Component {
  // ...

  componentWillMount() {
    // The getOrientation method is async. It happens sometimes that
    // you need the orientation at the moment the JS runtime starts running on device.
    // `getInitialOrientation` returns directly because its a constant set at the
    // beginning of the JS runtime.

    const initial = Orientation.getInitialOrientation();
    if (initial === 'PORTRAIT') {
      // do something
    } else {
      // do something else
    }
  },

  componentDidMount() {
    // this locks the view to Portrait Mode
    Orientation.lockToPortrait();

    // this locks the view to Landscape Mode
    // Orientation.lockToLandscape();

    // this unlocks any previous locks to all Orientations
    // Orientation.unlockAllOrientations();

    Orientation.addOrientationListener(this._orientationDidChange);
  },

  _orientationDidChange = (orientation) => {
    if (orientation === 'LANDSCAPE') {
      // do something with landscape layout
    } else {
      // do something with portrait layout
    }
  },

  componentWillUnmount() {
    Orientation.getOrientation((err, orientation) => {
      console.log(`Current Device Orientation: ${orientation}`);
    });


    // Remember to remove listener
    Orientation.removeOrientationListener(this._orientationDidChange);
  }

  render() {
    // ...

    return (
      // ...
    )
  }
}

Orientation Events

addOrientationListener((orientation) => {});

orientation will return one of the following values:

  • LANDSCAPE
  • PORTRAIT
  • PORTRAITUPSIDEDOWN
  • UNKNOWN
removeOrientationListener((orientation) => {});
addSpecificOrientationListener((specificOrientation) => {});

specificOrientation will return one of the following values:

  • LANDSCAPE-LEFT
  • LANDSCAPE-RIGHT
  • PORTRAIT
  • PORTRAITUPSIDEDOWN
  • UNKNOWN
removeSpecificOrientationListener((specificOrientation) => {});

API

  • lockToPortrait()
  • lockToLandscape()
  • lockToLandscapeLeft()
  • lockToLandscapeRight()
  • unlockAllOrientations()
  • getOrientation((err, orientation) => {})
  • getSpecificOrientation((err, specificOrientation) => {})

react-native-orientation's People

Contributors

asafbrieferydev avatar brianjd avatar chetstone avatar chris-griffin avatar daleljefferson avatar eduardinni avatar fungilation avatar gitim avatar jastanton avatar jaysoo avatar josepbordesjove avatar kdenz avatar ldom avatar mcrumm avatar naoto-ida avatar ncnlinh avatar nklhtv avatar nmorozov avatar pjcabrera avatar radko93 avatar sh3rawi avatar skv-headless avatar stoneman1 avatar thoblr avatar tunezola avatar vitaminwater avatar waldyrious avatar watert avatar yamill avatar youennpennarun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-orientation's Issues

GetState

How do i get the state of the navigation like when it's pushed or poped? Sample Implementation would be much appreciated.

imports

I think that you forgot to mention that you need to add these packages also.

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

After rotation Dimensions remain the same

Hi The dimension of the page is not affected by the rotation, so for example calling this in Landscape:
Dimensions.get('window').height has the same result of calling it in Portrait

Unbalanced calls start/end for tag 5

I am getting the above message when Debugging in Chrome. Comes from RCTLog.js:38.

I am using react native 0.18.1

Is this something to look at or safe to ignore? I believe there is an 'info' icon next to the message (blue circle with white line)

Landscape Left is not supported

After the latest update where an orientation change is forced there is one unintended consequence. whenever landscape is forced, it will be in landscape-right. This might be ok for some apps but for our use case it breaks. Is there a way to get around this? if not, would you be willing to take a PR which solves this problem?
my idea is to have the following orientations after the change:

LANDSCAPE
LANDSCAPE-LEFT (new)
PORTRAIT
UNKNOWN
PORTRAITUPSIDEDOWN
PORTRAIT

listener not removed after component unmount

Listener is not removed when a component is unmounted, I get a warning because a listener is called on an unmounted component.

In your code

addOrientationListener(cb) {
listeners[cb] = DeviceEventEmitter.addListener(orientationDidChangeEvent,
(body) => {
cb(body.orientation);
});
},
removeOrientationListener(cb) {
if (!listeners[cb]) {
return;
}
listeners[cb].remove();
listeners[cb] = null;
},

you maintain a unneeded listeners array, but more importantly you forgot to do DeviceEventEmitter.removeListener with the good params or call the cb returned by DeviceEventEmitter.addListener with cb.remove()
please see https://github.com/inProgress-team/react-native-orientation-controller/blob/master/index.android.js#L29-L40 and https://github.com/inProgress-team/react-native-orientation-controller#removelistenercallback for a good implementation.

I now use react-native-orientation-controller to fix this issue.

Differentiate PORTRAIT with UPSIDEDOWN in addOrientationListener

As the title says.

As I am creating my React Native app, I have different layouts shown to the user when the phone is in portrait and landscape. When I set 'unlockAllOrientations' for a particular screen I am seeing the expected layouts for portrait (home button at bottom) and landscape. However, when I rotate the phone upside down, the layout is completely mangled.

It is showing the portrait layout but with a 90 degree rotation (as if the app was in landscape) resulting in a buggy and ugly looking screen. I thought this might be a problem because in my XCode project I had unchecked the 'Upside Down' Device Orientation setting. So I turned it on and tried and again and I saw the same problem. My expected result was the portrait layout shown exactly as in the portrait orientation (with home button at bottom).

It looks like a react native app is prevented from being in the upside down orientation (can anyone confirm this?) whether or not the option is checked in XCode. After commenting out line 72 of RCTOrientation/Orientation.m my problem was instantly fixed.

As a result I propose to differentiate PORTRAIT with UPSIDEDOWN in addOrientationListener and anywhere else where it is appropriate in this library.

What do you think @yamill ? I can make a pull request if you approve of this change.

Forcing rotation change

I am trying to develop an iOS app where some screens support only landscape rotation and some screens only portrait. The problem occurs when I lock the rotation to portrait while the device is in landscape position. Screen remains in landscape until I physically rotate it. Changing the Scene (using Navigator) is not helping. Therefore, I need to somehow force rotation change.

I've made a longer research but I did not find anything useful. However, this is my first iOS app, so I may be missing something trivial.

Since I do not know what the problem really is, I am not sure whether this is suitable for issue, but I assume this can be considered a feature suggestion.

undefined is not an object (evaluating 'Orientation.lockToPortrait')

Hi I am trying to use the lockToPortrait function and I keep get this error in console:

undefined is not an object (evaluating 'Orientation.lockToPortrait')

I imported your package, set its name to Orientation just as in your usage examples, and inside of componentDidMount I am just calling Orientation.lockToPortrait();

Please help :)

Update documentation for Android

I am having difficulties installing this for android with react-native v0.23.1.

My MainActivity.java looks something like this:

package com.mkinteriordesign;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

import android.content.Intent;
import android.content.res.Configuration;
import com.github.yamill.orientation.OrientationPackage;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "MkInteriorDesign";
    }

    /**
     * Returns whether dev mode should be enabled.
     * This enables e.g. the dev menu.
     */
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

    /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new OrientationPackage(this)
        );
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        this.sendBroadcast(intent);
    }
}

Anyone gotten this to work for android with the latest version of react-native?

RCTEventDeviceEmitter - unable to resolve module

Hey,
Working on 1.6.0 here. Works fine for my use (lockToPortrait only), but when I run the app, I still got the error:

Unable to resolve module RCTDeviceEventEmitter from /Users/tnguyen/JibberJabber/JibberJabber/node_modules/react-native-orientation/index.js

Works better if I comment //var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); in index.js, but I don't know if there will be any problem then.

Podspecs

Hi can u make podspecs for this?

Not working in RN 0.21

The callback to the listener is not being called in RN 0.21

  componentDidMount () {
    console.warn('mounted')
    Orientation.addOrientationListener(this._orientationDidChange.bind(this))
  }

  _orientationDidChange (orientation) {
    console.warn('changed')
    if (orientation === ORIENTATION.LANDSCAPE) {
      this.setState({
        orientationStatus: ORIENTATION.LANDSCAPE
      })
    } else if (orientation === ORIENTATION.PORTRAIT) {
      this.setState({
        orientationStatus: ORIENTATION.PORTRAIT
      })
    }
  }

Incomplete module bridging on Android

Those functions are not bridged for Android:

  • getSpecificOrientation(function(err, specificOrientation))
  • lockToLandscapeLeft()
  • lockToLandscapeRight()

Get current lock

Is there a way to get the current orientation lock? I have some conditionals that change what is displayed based on whether the view is unlocked in landscape mode or not.

iOS 6s+

I'm using react-native-orientation and it works great on my iphone 6s. It doesn't seem to recognize events consistently on ios 6s-plus, though.

I wanted to check to see if this is an implementation error on my part or an issue. Have people been successfully using this library with 6s-plus? Was that included in testing? Thanks in advance.

Switching screen orientation

Hi, I'm switching to landscape orientation and back to portrait using the lockTo function. How do i do this? I keep getting an error when i set it on "componentWillUnmount"
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.

Does it override xcode settings?

Hey guys,

Does this lib override the default project settings set in xcode? I am experiencing really wired behaviour after adding the lib into my project.

It is locked to the portrait orientation but when I add this lib (and I even dont import it anywhere in my source code) it overrides the orientation setting and unlocks all. Is it how it supposed to behave?

What I am trying to achieve is to enable only for 1 view (with video obviously ... ) the landscape orientation? Is it possible and I am doing something wrong?

Thanks for your help guys!

Orientation layout problem

Hi,
I am new to react native. I developed a small application using orientation which needs to work with two layouts for portrait view and landscape view both are different styles layouts. when i open the application in landscape and when i logout through landscape i get no problem in the layout where as when i login in landscape view and logout in portrait view i get the landscape layout its not getting the present orientation which i am using when we logout. I get the initial orientation according to that its getting the final view. can some one help me or suggest me what to do ..

listener can get called with a meaningless value

It seems whenever orientation changes, my listener gets called twice: once with a valid string, then with an integer:

2016-04-05 17:30:22.047 browser.js:107 History:debug Window width +7ms 480
2016-04-05 17:30:22.054 browser.js:107 History:debug New Device Orientation: +7ms LANDSCAPE
2016-04-05 17:30:22.055 browser.js:107 History:debug New Device Orientation: +1ms 3
2016-04-05 17:30:44.438 browser.js:107 History:debug Window width +2ms 320
2016-04-05 17:30:44.446 browser.js:107 History:debug New Device Orientation: +8ms PORTRAIT
2016-04-05 17:30:44.446 browser.js:107 History:debug New Device Orientation: +0ms 1

Workaround: test if the parameter is one of the expected strings, otherwise ignore it.

Orientation.getOrientation is not a function

Hi!

First of all: awesome work! this is helping me very much.

The Lock-Functions and the Listeners work very fine!

Sadly the getOrientation seems not a function:

Error: Orientation.getOrientation is not a function
 stack: 
  Select.render                                                                index.ios.bundle:54417
  ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext  index.ios.bundle:8980
  ReactCompositeComponentMixin._renderValidatedComponent                       index.ios.bundle:9002
  wrapper [as _renderValidatedComponent]                                       index.ios.bundle:5869
  ReactCompositeComponentMixin.mountComponent                                  index.ios.bundle:8499
  wrapper [as mountComponent]                                                  index.ios.bundle:5869
  Object.ReactReconciler.mountComponent                                        index.ios.bundle:6707
  ReactMultiChild.Mixin.mountChildren                                          index.ios.bundle:23384
  ReactNativeBaseComponent.Mixin.initializeChildren                            index.ios.bundle:19801
  ReactNativeBaseComponent.Mixin.mountComponent                                index.ios.bundle:19925
 URL: undefined
 line: undefined
 message: Orientation.getOrientation is not a functionhandleException @ index.ios.bundle:10723
5index.ios.bundle:10744 Exception thrown while executing UI block: put reactNavSuperviewLink back

usage:

 render() {
    // console.log('splash');
    // console.log(this.props);
     Orientation.getOrientation((err,orientation)=> {
        console.log("Current Device Orientation: ", orientation);
    });

package.json:

{
  "name": "xx",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node_modules/react-native/packager/packager.sh"
  },
  "dependencies": {
    "react-native": "^0.13.2",
    "react-native-camera": "^0.3.8",
    "react-native-orientation": "^1.8.0",
    "react-native-screcorder": "0.1.0",
    "react-native-video": "^0.6.1"
  }
}

Android support

Update the readme to include Android setup ( if it is supported that is ? )

Can't use module from an InputMethodService on Android

I'm trying to use the orientation package from an InputMethodService to force my React-Native componet to rerender. Basically I need to recalclate the style and apply the different width to the width of my controls. Unfortuantely the orientation module on android requires an activity in the constructor.

new OrientationPackage(Activity activity)

Any ideas on how to pass it something Activy like to the constructor? Or maybe an alternate constructor that takes an InputMethodService? Or better yet, an empty construtor that grabs onto what it needs in the constructor via some sort of global singleton?

Not work on android react-native 0.21

@Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new WebRTCModulePackage(),
            new VectorIconsPackage(),
            new BarcodeScanner(),
            new RNSharePackage(),
            new OrientationPackage(this)// Right or wrong?
        );
    }

Not work on android react-native 0.21.

import Orientation from 'react-native-orientation';

class ShowMyScreen extends Component {
    componentDidMount() {
        Orientation.lockToPortrait();
    }
    render() {
        return (
            <Navigator
                initialRoute={{name: 'SMS', component: Home}}
                renderScene={(route, navigator) => {
          if(route.component) {
            let Component = route.component;
            return <Component {...route.params} navigator={ navigator } route={route} />
          }
        }}
            />
        );
    }
}

The error is: Orientation is not an object.

How should I configure on react-native 0.21 on android?

shouldRotate API could be cleaner

Currently I think this is a tad confusing to use - rather than shouldRotate could it be lockToPortrait(), lockToLandscape() and unlockAllOrientations()?

Install with rnpm

Hi there,

Is it possible to install this with rnpm instead of doing it manually?

Cheers.

[iOS] Exception when setting up landscape orientation: Orientation.lockToLandscape()

2016-04-10 16:55:58.237 [info][tid:com.facebook.React.JavaScript] Running application "appname" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2016-04-10 16:55:58.340 [appname][28184:498712] Locked to Landscape
2016-04-10 16:55:58.348 [appname][28184:498575] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [RCTModalHostViewController shouldAutorotate] is returning YES'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e52ed85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d723deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e52ecbd +[NSException raise:format:] + 205
    3   UIKit                               0x00000001104f5e36 -[UIViewController __supportedInterfaceOrientations] + 903
    4   UIKit                               0x00000001104e46c3 -[UIViewController _preferredInterfaceOrientationGivenStatusBarAndDeviceAndOrientation:] + 90
    5   UIKit                               0x00000001103b6c63 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 320
    6   UIKit                               0x000000011069225c -[UIScreen _notifyOrientationWillChangeAndPropagateToAllWindows:] + 356
    7   UIKit                               0x000000011068f387 -[UIScreen _computeMetrics:] + 2088
    8   UIKit                               0x000000011069047e -[UIScreen _setInterfaceOrientation:computeMetrics:animated:] + 94
    9   UIKit                               0x0000000110340f8a -[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:updateBlock:] + 793
    10  UIKit                               0x00000001103b9223 __78-[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:]_block_invoke1183 + 275
    11  UIKit                               0x0000000110969fad __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke_2 + 161
    12  UIKit                               0x00000001103f282b +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
    13  UIKit                               0x0000000110969dd8 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 134
    14  UIKit                               0x00000001103ed838 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
    15  UIKit                               0x00000001103edc6d +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 105
    16  UIKit                               0x0000000110969cc5 -[_UIWindowRotationAnimationController animateTransition:] + 535
    17  UIKit                               0x00000001103b5dfe -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 656
    18  UIKit                               0x00000001103b8c54 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 2047
    19  UIKit                               0x00000001103b974d -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 842
    20  UIKit                               0x00000001103b8280 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 184
    21  UIKit                               0x00000001103b6ed1 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 107
    22  UIKit                               0x00000001103b6d09 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 486
    23  CoreFoundation                      0x000000010e4f8c8c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    24  CoreFoundation                      0x000000010e4f89cb _CFXRegistrationPost + 427
    25  CoreFoundation                      0x000000010e4f8732 ___CFXNotificationPost_block_invoke + 50
    26  CoreFoundation                      0x000000010e5411e2 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1986
    27  CoreFoundation                      0x000000010e3f0679 _CFXNotificationPost + 633
    28  Foundation                          0x000000010d2afcd9 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    29  UIKit                               0x000000011068730c -[UIDevice setOrientation:animated:] + 326
    30  Foundation                          0x000000010d2ee19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    31  appname                    0x000000010cfa65fb __30-[Orientation lockToLandscape]_block_invoke + 155
    32  Foundation                          0x000000010d396630 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
    33  Foundation                          0x000000010d2d1805 -[NSBlockOperation main] + 101
    34  Foundation                          0x000000010d2b4725 -[__NSOperationInternal _start:] + 646
    35  Foundation                          0x000000010d2b4336 __NSOQSchedule_f + 194
    36  libdispatch.dylib                   0x00000001120203eb _dispatch_client_callout + 8
    37  libdispatch.dylib                   0x00000001120081ef _dispatch_main_queue_callback_4CF + 1738
    38  CoreFoundation                      0x000000010e4880f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    39  CoreFoundation                      0x000000010e449b99 __CFRunLoopRun + 2073
    40  CoreFoundation                      0x000000010e4490f8 CFRunLoopRunSpecific + 488
    41  GraphicsServices                    0x0000000113599ad2 GSEventRunModal + 161
    42  UIKit                               0x000000011033cf09 UIApplicationMain + 171
    43  appname                    0x000000010cfa564f main + 111
    44  libdyld.dylib                       0x000000011205492d start + 1
    45  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

I am trying to lock a screen using either portrait or landscape.
I have tested that it works for android, both portrait and landscape. However, only portrait is working for ios. When i tried to use Orientation.lockToLandscape() in componentDidMount, it threw the above exception.

Unable to install with newer versions of React Native

React Native is on version 0.27, but it's not possible to install with this since it says v0.5 and up, and unfortunately the RN team did not use 0.05 like they should have, so NPM complains.

Can you please raise the version to something in v0.2x so this can be installed with a new install?

RN 0.11 Conflicting return type in AppDelegate.m

Hi,

Since RN 0.11, the Installation instructions may be out of date. In particularly, this line gets a warning for a conflicting return type in AppDelegate.m:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *) window {

Cannot find interface declaration for 'AppDelegate'

[APPNAME]/node_modules/react-native-orientation/RCTOrientation/Orientation.h:16:12: Cannot find interface declaration for 'AppDelegate'

Am I missing something here?

I followed the steps as mentioned in the README but unable to build the application because of the above error.

Missing FaceUP and FaceDown

It would appear you are not currently listening to the

UIDeviceOrientationFaceDown or UIDeviceOrientationFaceUP in the case statement so those values are returning UNKNOWN

Not sure if Android provides the option which might be why it was left out but having false unknowns wasn't preferred here. I think that it probably makes the most sense to modify the style to return an object to the listener personally.

{ orientation: portrait, direction: normal }
{ orientation: portrait, direction: up }
{ orientation: landscape, direction: down }
{ orientation: portrait, direction: upsidedown }

etc, just a thought!

lockToLandscapeRight and lockToLandscapeLeft are swapped

See https://github.com/yamill/react-native-orientation/blob/master/RCTOrientation/Orientation.m#L144-L152

RCT_EXPORT_METHOD(lockToLandscapeRight)
...
setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]

versus https://github.com/yamill/react-native-orientation/blob/master/RCTOrientation/Orientation.m#L156-L165

RCT_EXPORT_METHOD(lockToLandscapeLeft)
...
setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight]

pop can't call lock method well

I do navigator.push() and execute lockToLANDSCAPE in componentDidMount method and I get LANDSCAPE orientation.

then I want to navigator.pop() and expect back to PORTRAIT orientation, so I call lockToPortrait after pop, it works.

.. but I find that device orientation can't change to PORTRAIT if I already put my device in PORTRAIT orientation (lockToLANDSCAPE now) when I prepare to pop.

how should I fix it?

thanks for your time.

Android crash: java.lang.IllegalArgumentException: Receiver not registered

Hi,
I'm a newbie Android developer, wanted to lock down orientation on my react-native app. After implementing this module, App crashes on reload and seeing below error in the log.
I did verify by completely removing this module and don't see App crashing anymore. Any suggestions?

  • Device: SAMSUNG-SGH-I337 - 5.0.1
  • React-Native: 0.1.7

In my .js code, I've this

  _orientationDidChange:function(orientation){
    console.log('orientation change');
  },
  componentDidMount: function(){
    Orientation.addOrientationListener(this._orientationDidChange);
    Orientation.lockToPortrait();
  },
  componentWillUnmount: function() {
    Orientation.removeOrientationListener(this._orientationDidChange);    
  }, 

E/AndroidRuntime(27863): FATAL EXCEPTION: main
E/AndroidRuntime(27863): Process: com.helloworld, PID: 27863
E/AndroidRuntime(27863): java.lang.IllegalArgumentException: Receiver not registered: com.github.yamill.orientation.OrientationModule$1@5a2ced3
E/AndroidRuntime(27863):  at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:822)
E/AndroidRuntime(27863):  at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:2038)
E/AndroidRuntime(27863):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:528)
E/AndroidRuntime(27863):  at com.github.yamill.orientation.OrientationModule$2.onHostDestroy(OrientationModule.java:63)
E/AndroidRuntime(27863):  at com.facebook.react.bridge.ReactContext.onDestroy(ReactContext.java:160)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl.tearDownReactContext(ReactInstanceManagerImpl.java:595)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl.access$500(ReactInstanceManagerImpl.java:78)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPreExecute(ReactInstanceManagerImpl.java:161)
E/AndroidRuntime(27863):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
E/AndroidRuntime(27863):  at android.os.AsyncTask.execute(AsyncTask.java:535)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl.recreateReactContextInBackground(ReactInstanceManagerImpl.java:526)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl.onJSBundleLoadedFromServer(ReactInstanceManagerImpl.java:510)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl.access$100(ReactInstanceManagerImpl.java:78)
E/AndroidRuntime(27863):  at com.facebook.react.ReactInstanceManagerImpl$1.onJSBundleLoadedFromServer(ReactInstanceManagerImpl.java:114)
E/AndroidRuntime(27863):  at com.facebook.react.devsupport.DevSupportManager$15$1.run(DevSupportManager.java:575)
E/AndroidRuntime(27863):  at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(27863):  at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(27863):  at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime(27863):  at android.app.ActivityThread.main(ActivityThread.java:5951)
E/AndroidRuntime(27863):  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27863):  at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(27863):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

[Android] reload js crash

React Native v0.17

15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime: FATAL EXCEPTION: main
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime: Process: com.smarthome, PID: 13632
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime: java.lang.IllegalArgumentException: Receiver not registered: com.github.yamill.orientation.OrientationModule$1@2443df15
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:763)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1697)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:517)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.github.yamill.orientation.OrientationModule$2.onHostDestroy(OrientationModule.java:63)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.bridge.ReactContext.onDestroy(ReactContext.java:160)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl.tearDownReactContext(ReactInstanceManagerImpl.java:595)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl.access$500(ReactInstanceManagerImpl.java:78)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPreExecute(ReactInstanceManagerImpl.java:161)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.os.AsyncTask.execute(AsyncTask.java:535)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl.recreateReactContextInBackground(ReactInstanceManagerImpl.java:526)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl.onJSBundleLoadedFromServer(ReactInstanceManagerImpl.java:510)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl.access$100(ReactInstanceManagerImpl.java:78)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.ReactInstanceManagerImpl$1.onJSBundleLoadedFromServer(ReactInstanceManagerImpl.java:114)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.facebook.react.devsupport.DevSupportManager$15$1.run(DevSupportManager.java:575)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5253)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
01-12 15:50:00.451 13632-13632/com.smarthome E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

"Unable to resolve module NativeModules"

Hi guys,

I've got an error displayed in the terminal when I run the app. It says:

Unable to resolve module NativeModules from /App/node_modules/react-native-orientation/index.js
Unable to resolve module RCTDeviceEventEmitter from /App/node_modules/react-native-orientation/index.js

However the project works correctly. Any idea what could cause this?

Won't compile with RN 0.11

When compiling Orientation.h, I get the error:

RCTOrientation/Orientation.h:16:12: Cannot find interface declaration for 'AppDelegate'

autoRotation (w/ fixed parent)

Feels like I am missing something obvious, but does anyone know of a workaround to keep the parent window/view fixed, while allowing specific children to autorotate?

Orientation locking not working

I have been using this package for a few months, and it worked well. This week we upgraded from react native 0.24 to 0.27. Now the orientation locking methods are not working. I tried other orientations as well, but none of them worked either. Stepping through it, the function is being called, and no error is being thrown.

componentWillMount() {
        console.log(Orientation.getInitialOrientation());
        Orientation.addOrientationListener(this._orientationDidChange);
        if(Device.isTablet){
            Orientation.lockToLandscape();
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.