Gathering detailed insights and metrics for react-native-orientation-locker
Gathering detailed insights and metrics for react-native-orientation-locker
Gathering detailed insights and metrics for react-native-orientation-locker
Gathering detailed insights and metrics for react-native-orientation-locker
A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.
npm install react-native-orientation-locker
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
762 Stars
297 Commits
274 Forks
10 Watching
1 Branches
46 Contributors
Updated on 27 Nov 2024
JavaScript (28.13%)
Java (28.03%)
C++ (21.05%)
Objective-C (17.39%)
Starlark (2.06%)
C (1.71%)
Ruby (1.63%)
Cumulative downloads
Total Downloads
Last day
-6.3%
19,744
Compared to previous day
Last week
-1.5%
98,408
Compared to previous week
Last month
11.3%
420,693
Compared to previous month
Last year
30%
4,218,889
Compared to previous year
3
3
A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation. (cross-platform support)
v1.6.0
v1.5.0
v1.4.0
v1.3.1
v1.3.0 BREAKING CHANGES
v1.2.0 BREAKING CHANGES
Please be sure to add to onCreate
of your MainApplication
import org.wonday.orientation.OrientationActivityLifecycle;
@Override
public void onCreate() {
...
+ registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance());
}
v1.1.8
v1.1.7
v1.1.6
v1.1.5
v1.1.4
v1.1.3
addLockListener
and removeLockListener
v1.1.2
v1.1.1
v1.1.0 BREAKING CHANGES
addOrientationListener(function(orientation, deviceOrientation))
to addOrientationListener(function(orientation))
and addDeviceOrientationListener(function(deviceOrientation))
RN 0.58 + Android target SDK 27 maybe cause
Issue: java.lang.IllegalStateException: Only fullscreen activities can request orientation
problem,
see [#55] for a solution.
orientationDidChange will be delayed on iPads if we set upside down to true. Simply disable upside down for iPad and everything works like a charm ([#78] Thanks truongluong1314520)
If you get the following build error on iOS:
ld: library not found for -lRCTOrientation-tvOS
Just remove it from linked libraries and frameworks
For Windows, locking to an orientation will only work on devices in tablet mode.
For Windows, getting information on device orientation and tracking its changes will only be possible on devices with an orientation sensor. If the device running your application does not have the appropriate hardware to support tracking device orientation, getDeviceOrientation()
will return UNKNOWN.
yarn add react-native-orientation-locker
yarn add react-native-orientation-locker
react-native link react-native-orientation-locker
For Windows, if you are using RNW v0.63.0 or higher, autolinking should link the module for you. Otherwise, you must follow the steps outlined here for linking module.
Add following to MainApplication.java (This will be added automatically by auto link. If not, please manually add the following )
1//... 2+import org.wonday.orientation.OrientationPackage; 3 @Override 4 protected List<ReactPackage> getPackages() { 5 @SuppressWarnings("UnnecessaryLocalVariable") 6 List<ReactPackage> packages = new PackageList(this).getPackages(); 7 // Packages that cannot be autolinked yet can be added manually here, for example: 8 // packages.add(new MyReactNativePackage()); 9+ packages.add(new OrientationPackage()); 10 return packages; 11 } 12//...
Run pod install
in the ios directory. Linking is not required in React Native 0.60 and above.
Add the following to your project's AppDelegate.m
:
1+#import "Orientation.h" 2 3@implementation AppDelegate 4 5// ... 6 7+- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 8+ return [Orientation getOrientation]; 9+} 10 11@end
Add following to android/app/src/main/AndroidManifest.xml
1 <activity 2 .... 3+ android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 4 android:windowSoftInputMode="adjustResize"> 5 6 .... 7 8 </activity> 9
Implement onConfigurationChanged method (in MainActivity.java
)
1// ... 2 3+import android.content.Intent; 4+import android.content.res.Configuration; 5 6public class MainActivity extends ReactActivity { 7 8+ @Override 9+ public void onConfigurationChanged(Configuration newConfig) { 10+ super.onConfigurationChanged(newConfig); 11+ Intent intent = new Intent("onConfigurationChanged"); 12+ intent.putExtra("newConfig", newConfig); 13+ this.sendBroadcast(intent); 14+ } 15 16 // ...... 17}
Add following to MainApplication.java
1+import org.wonday.orientation.OrientationActivityLifecycle; 2 @Override 3 public void onCreate() { 4+ registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance()); 5 }
Whenever you want to use it within React Native code now you can:
import Orientation from 'react-native-orientation-locker';
1 2import Orientation from 'react-native-orientation-locker'; 3 4 5 _onOrientationDidChange = (orientation) => { 6 if (orientation == 'LANDSCAPE-LEFT') { 7 //do something with landscape left layout 8 } else { 9 //do something with portrait layout 10 } 11 }; 12 13 componentWillMount() { 14 //The getOrientation method is async. It happens sometimes that 15 //you need the orientation at the moment the js starts running on device. 16 //getInitialOrientation returns directly because its a constant set at the 17 //beginning of the js code. 18 var initial = Orientation.getInitialOrientation(); 19 if (initial === 'PORTRAIT') { 20 //do stuff 21 } else { 22 //do other stuff 23 } 24 }, 25 26 componentDidMount() { 27 28 Orientation.getAutoRotateState((rotationLock) => this.setState({rotationLock})); 29 //this allows to check if the system autolock is enabled or not. 30 31 Orientation.lockToPortrait(); //this will lock the view to Portrait 32 //Orientation.lockToLandscapeLeft(); //this will lock the view to Landscape 33 //Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations 34 35 //get current UI orientation 36 /* 37 Orientation.getOrientation((orientation)=> { 38 console.log("Current UI Orientation: ", orientation); 39 }); 40 41 //get current device orientation 42 Orientation.getDeviceOrientation((deviceOrientation)=> { 43 console.log("Current Device Orientation: ", deviceOrientation); 44 }); 45 */ 46 47 Orientation.addOrientationListener(this._onOrientationDidChange); 48 }, 49 50 componentWillUnmount: function() { 51 Orientation.removeOrientationListener(this._onOrientationDidChange); 52 }
<OrientationLocker>
It is possible to have multiple OrientationLocker
components mounted at the same time. The props will be merged in the order the OrientationLocker
components were mounted. This follows the same usability of <StatusBar>.
1import React, { useState } from "react"; 2import { Text, View } from "react-native"; 3import { OrientationLocker, PORTRAIT, LANDSCAPE } from "react-native-orientation-locker"; 4 5export default function App() { 6 const [showVideo, setShowVideo] = useState(true); 7 return ( 8 <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> 9 <OrientationLocker 10 orientation={PORTRAIT} 11 onChange={orientation => console.log('onChange', orientation)} 12 onDeviceChange={orientation => console.log('onDeviceChange', orientation)} 13 /> 14 <Button title="Toggle Video" onPress={() => setShowVideo(!showVideo)} /> 15 {showVideo && ( 16 <View> 17 <OrientationLocker orientation={LANDSCAPE} /> 18 <View style={{ width: 320, height: 180, backgroundColor: '#ccc' }}> 19 <Text>Landscape video goes here</Text> 20 </View> 21 </View> 22 )} 23 </View> 24 ); 25};
useOrientationChange
: hook for addOrientationListener
eventuseDeviceOrientationChange
: hook for addDeviceOrientationListener
eventfunction SomeComponent() {
useOrientationChange((o) => {
// Handle orientation change
});
useDeviceOrientationChange((o) => {
// Handle device orientation change
});
}
addOrientationListener(function(orientation))
When UI orientation changed, callback function will be called.
But if lockToXXX is called , callback function will be not called untill unlockAllOrientations.
It can return either PORTRAIT
LANDSCAPE-LEFT
LANDSCAPE-RIGHT
PORTRAIT-UPSIDEDOWN
UNKNOWN
When lockToXXX/unlockAllOrientations, it will force resend UI orientation changed event.
removeOrientationListener(function(orientation))
addDeviceOrientationListener(function(deviceOrientation))
When device orientation changed, callback function will be called.
When lockToXXX is called, callback function also can be called.
It can return either PORTRAIT
LANDSCAPE-LEFT
LANDSCAPE-RIGHT
PORTRAIT-UPSIDEDOWN
UNKNOWN
removeDeviceOrientationListener(function(deviceOrientation))
addLockListener(function(orientation))
When call lockToXXX/unlockAllOrientations, callback function will be called.
It can return either PORTRAIT
LANDSCAPE-LEFT
LANDSCAPE-RIGHT
UNKNOWN
UNKNOWN
means not be locked.
removeLockListener(function(orientation))
removeAllListeners()
configure({ disableFaceUpDown: boolean })
(ios only)lockToPortrait()
lockToLandscape()
lockToLandscapeLeft()
this will lock to camera left home button rightlockToLandscapeRight()
this will lock to camera right home button leftlockToPortraitUpsideDown
only support android and WindowslockToAllOrientationsButUpsideDown
only iosunlockAllOrientations()
getOrientation(function(orientation))
getDeviceOrientation(function(deviceOrientation))
getAutoRotateState(function(state))
(android only)isLocked()
(lock status by this library)orientation can return one of:
PORTRAIT
LANDSCAPE-LEFT
camera left home button rightLANDSCAPE-RIGHT
camera right home button leftPORTRAIT-UPSIDEDOWN
FACE-UP
FACE-DOWN
UNKNOWN
Notice: PORTRAIT-UPSIDEDOWN is currently not supported on iOS at the moment. FACE-UP and FACE-DOWN are only supported on iOS and Windows.
No vulnerabilities found.
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 16/21 approved changesets -- score normalized to 7
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
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 Moreexpo-screen-orientation
Expo universal module for managing device's screen orientation
@bugsnag/plugin-react-native-orientation-breadcrumbs
@bugsnag/js plugin to create breadcrumbs when the device orientation changes in a React Native app
react-native-orientation-locker-cn
A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.
react-native-orientation
Listen to device orientation changes in React Native applications and programmatically set preferred orientations on a per screen basis