Installations
npm install react-native-orientation
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
8.8.1
NPM Version
5.5.1
Statistics
1,724 Stars
148 Commits
813 Forks
24 Watching
2 Branches
36 Contributors
Updated on 19 Nov 2024
Bundle Size
1.18 kB
Minified
501.00 B
Minified + Gzipped
Languages
Objective-C (44.98%)
Java (38.84%)
JavaScript (12.06%)
Ruby (4.12%)
Total Downloads
Cumulative downloads
Total Downloads
6,027,345
Last day
101.7%
2,442
Compared to previous day
Last week
1.7%
10,043
Compared to previous week
Last month
28.7%
43,327
Compared to previous month
Last year
-12.3%
416,977
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
React Native Orientation
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
- Add
node_modules/react-native-orientation/iOS/RCTOrientation.xcodeproj
to your xcode project, usually under theLibraries
group - Add
libRCTOrientation.a
(fromProducts
underRCTOrientation.xcodeproj
) to build target'sLinked Frameworks and Libraries
list - Add
$(SRCROOT)/node_modules/react-native-orientation/iOS/RCTOrientation/
toProject Name
->Build Settings
->Header Search Paths
Android
-
In
android/setting.gradle
... include ':react-native-orientation', ':app' project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')
-
In
android/app/build.gradle
... dependencies { ... compile project(':react-native-orientation') }
-
Register module in
MainApplication.java
1import com.github.yamill.orientation.OrientationPackage; // <--- import 2 3public class MainApplication extends Application implements ReactApplication { 4 ...... 5 6 @Override 7 protected List<ReactPackage> getPackages() { 8 return Arrays.<ReactPackage>asList( 9 new MainReactPackage(), 10 new OrientationPackage() <------- Add this 11 ); 12 } 13 14 ...... 15 16}
Configuration
iOS
Add the following to your project's AppDelegate.m
:
1#import "Orientation.h" // <--- import 2 3@implementation AppDelegate 4 5 // ... 6 7- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 8 return [Orientation getOrientation]; 9} 10 11 12@end
Android
Implement onConfigurationChanged
method in MainActivity.java
1 import android.content.Intent; // <--- import 2 import android.content.res.Configuration; // <--- import 3 4 public class MainActivity extends ReactActivity { 5 ...... 6 @Override 7 public void onConfigurationChanged(Configuration newConfig) { 8 super.onConfigurationChanged(newConfig); 9 Intent intent = new Intent("onConfigurationChanged"); 10 intent.putExtra("newConfig", newConfig); 11 this.sendBroadcast(intent); 12 } 13 14 ...... 15 16 }
Usage
To use the react-native-orientation
package in your codebase, you should use the Orientation module:
1import Orientation from 'react-native-orientation';
1export default class AppScreen extends Component { 2 // ... 3 4 componentWillMount() { 5 // The getOrientation method is async. It happens sometimes that 6 // you need the orientation at the moment the JS runtime starts running on device. 7 // `getInitialOrientation` returns directly because its a constant set at the 8 // beginning of the JS runtime. 9 10 const initial = Orientation.getInitialOrientation(); 11 if (initial === 'PORTRAIT') { 12 // do something 13 } else { 14 // do something else 15 } 16 }, 17 18 componentDidMount() { 19 // this locks the view to Portrait Mode 20 Orientation.lockToPortrait(); 21 22 // this locks the view to Landscape Mode 23 // Orientation.lockToLandscape(); 24 25 // this unlocks any previous locks to all Orientations 26 // Orientation.unlockAllOrientations(); 27 28 Orientation.addOrientationListener(this._orientationDidChange); 29 }, 30 31 _orientationDidChange = (orientation) => { 32 if (orientation === 'LANDSCAPE') { 33 // do something with landscape layout 34 } else { 35 // do something with portrait layout 36 } 37 }, 38 39 componentWillUnmount() { 40 Orientation.getOrientation((err, orientation) => { 41 console.log(`Current Device Orientation: ${orientation}`); 42 }); 43 44 45 // Remember to remove listener 46 Orientation.removeOrientationListener(this._orientationDidChange); 47 } 48 49 render() { 50 // ... 51 52 return ( 53 // ... 54 ) 55 } 56}
Orientation Events
1addOrientationListener((orientation) => {});
orientation
will return one of the following values:
LANDSCAPE
PORTRAIT
PORTRAITUPSIDEDOWN
UNKNOWN
1removeOrientationListener((orientation) => {});
1addSpecificOrientationListener((specificOrientation) => {});
specificOrientation
will return one of the following values:
LANDSCAPE-LEFT
LANDSCAPE-RIGHT
PORTRAIT
PORTRAITUPSIDEDOWN
UNKNOWN
1removeSpecificOrientationListener((specificOrientation) => {});
API
lockToPortrait()
lockToLandscape()
lockToLandscapeLeft()
lockToLandscapeRight()
unlockAllOrientations()
getOrientation((err, orientation) => {})
getSpecificOrientation((err, specificOrientation) => {})
No vulnerabilities found.
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: ISC License: LICENSE.md:0
Reason
binaries present in source code
Details
- Warn: binary detected: demo/android/gradle/wrapper/gradle-wrapper.jar:1
Reason
Found 16/27 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Reason
68 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-j4mr-9xw3-c9jx
- Warn: Project is vulnerable to: GHSA-7p89-p6hx-q4fw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-9qj9-36jm-prpv
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-qx2f-477c-35rq
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-446m-mv8f-q348
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-gwg9-rgvj-4h5j
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-7mc5-chhp-fmc3
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-4cpg-3vgw-4877
- Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-gff7-g5r8-mg8m
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-5v72-xg48-5rpm
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-h6q6-9hqw-rwfv
- Warn: Project is vulnerable to: GHSA-5fg8-2547-mr8q
- Warn: Project is vulnerable to: GHSA-crh6-fp67-6883
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-orientation
@types/react-native-orientation
TypeScript definitions for react-native-orientation
@lyrahealth-inc/react-native-orientation-plugin
Config plugin to auto configure react-native-orientation on prebuild
react-native-orientation-locker
A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.
@bugsnag/plugin-react-native-orientation-breadcrumbs
@bugsnag/js plugin to create breadcrumbs when the device orientation changes in a React Native app