Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
capacitor-screen-orientation
Advanced tools
Readme
For detailed tutorial on how to use this plugin visit: https://medium.com/@hinddeep.purohit007/handling-screen-orientation-changes-in-capacitor-apps-19fe339578a6
Demo Application: https://github.com/hinddeep/Demo-Ionic-Screen_Orientation
Platforms Supported: Android, iOS
The Capacitor plugin I’ve developed can be used to detect the current of orientation of the screen, lock the screen in a particular orientation (disable auto-rotate) or unlock screen rotation (enable auto-rotate) and to listen for orientation changes.
npm install capacitor-screen-orientation
Open MainActivity.java and add the following code inside this.init()
add(ScreenOrientation.class);
Adding the above mentioned line will add the following import statement:
import com.bkon.capacitor.screenorientation.ScreenOrientation;
If you encounter errors, please add both the lines manually to MainActivity.java
If you want to listen for the orientation change event on Android:
Supported Orientations:
SPECIAL NOTE: Ionic has implicitly disabled PORTRAIT_SECONDARY.
If you want to lock the screen to the specified orientation on iOS:
var orientationLock = UIInterfaceOrientationMask.all
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
@objc func setOrientationLock(_ notification: Notification)
{
if let data = notification.userInfo as? [String: Int]
{
for (_, mask) in data
{
switch mask
{
case 1: self.orientationLock = UIInterfaceOrientationMask.portrait
break;
case 2: self.orientationLock = UIInterfaceOrientationMask.portraitUpsideDown
break;
case 3: self.orientationLock = UIInterfaceOrientationMask.landscapeRight
break;
case 4: self.orientationLock = UIInterfaceOrientationMask.landscapeLeft
break;
case 5: self.orientationLock = UIInterfaceOrientationMask.landscape
break;
default: self.orientationLock = UIInterfaceOrientationMask.all
}
}
}
}
Supported Orientations:
SPECIAL NOTE: Ionic has implicitly disabled portraitUpsideDown.
Open app.component.ts file and import the plugin as follows:
import { Plugins } from "@capacitor/core";
const { ScreenOrientation } = Plugins;
import 'capacitor-screen-orientation'
SPECIAL NOTE: Remove import 'capacitor-screen-orientation' when compiling app for Android and iOS. THe native plugin will not be invoked if you forget to remove the import statement before building for Android and iOS Platform.
Create a function to get the current screen orientation:
async getOrientation() {
let obj = await ScreenOrientation.getScreenOrientation();
this.screen_orientation = obj.orientation;
}
Create a function to lock the screen in a particular orientation:
async lockOrientation() {
await ScreenOrientation.lockScreenOrientation({
orientation: this.screen_orientation_lock,
});
}
Supported values for screen_orientation_lock variable:
Create a function to unlock screen rotation:
async UnlockOrientation() {
await ScreenOrientation.unlockScreenOrientation({});
}
Create a function that handles subscription to the orientation change event:
subscribeToOrientationChanges() {
ScreenOrientation.addListener("orientation_changed", (data) => {
this.screen_orientation_event = data.orientation;
});
}
NOTE: NOT supported on Android
async rotate() {
await ScreenOrientation.rotateTo({
orientation: this.rotateTo,
});
}
FAQs
Handle screen orientation of a mobile device.
The npm package capacitor-screen-orientation receives a total of 105 weekly downloads. As such, capacitor-screen-orientation popularity was classified as not popular.
We found that capacitor-screen-orientation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.