Gathering detailed insights and metrics for react-native-orientation
Gathering detailed insights and metrics for react-native-orientation
Gathering detailed insights and metrics for react-native-orientation
Gathering detailed insights and metrics for 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
npm install react-native-orientation
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,724 Stars
148 Commits
813 Forks
24 Watching
2 Branches
36 Contributors
Updated on 19 Nov 2024
Minified
Minified + Gzipped
Objective-C (44.98%)
Java (38.84%)
JavaScript (12.06%)
Ruby (4.12%)
Cumulative downloads
Total Downloads
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
1
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.
npm install react-native-orientation --save
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.
iOS
node_modules/react-native-orientation/iOS/RCTOrientation.xcodeproj
to your xcode project, usually under the Libraries
grouplibRCTOrientation.a
(from Products
under RCTOrientation.xcodeproj
) to build target's Linked Frameworks and Libraries
list$(SRCROOT)/node_modules/react-native-orientation/iOS/RCTOrientation/
to Project 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}
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 }
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}
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) => {});
lockToPortrait()
lockToLandscape()
lockToLandscapeLeft()
lockToLandscapeRight()
unlockAllOrientations()
getOrientation((err, orientation) => {})
getSpecificOrientation((err, specificOrientation) => {})
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
68 existing vulnerabilities detected
Details
Score
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 More