{"id":13693476,"url":"https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation","last_synced_at":"2025-05-02T21:32:08.332Z","repository":{"id":60774030,"uuid":"56459274","full_name":"wcoder/Xamarin.Plugin.DeviceOrientation","owner":"wcoder","description":"Cross-platform plugin to work with screen orientation of mobile device.","archived":true,"fork":false,"pushed_at":"2019-03-02T11:55:01.000Z","size":452,"stargazers_count":61,"open_issues_count":15,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-26T10:53:43.144Z","etag":null,"topics":["android","csharp-library","device-orientation","hacktoberfest","ios","netstandard","nuget","orientation-lock-plugin","screen-orientation","uwp","xamarin","xamarin-android","xamarin-forms","xamarin-ios","xamarin-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-17T21:23:19.000Z","updated_at":"2025-03-26T10:20:28.000Z","dependencies_parsed_at":"2022-10-04T15:30:54.880Z","dependency_job_id":null,"html_url":"https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcoder%2FXamarin.Plugin.DeviceOrientation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcoder%2FXamarin.Plugin.DeviceOrientation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcoder%2FXamarin.Plugin.DeviceOrientation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcoder%2FXamarin.Plugin.DeviceOrientation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wcoder","download_url":"https://codeload.github.com/wcoder/Xamarin.Plugin.DeviceOrientation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252109012,"owners_count":21696174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","csharp-library","device-orientation","hacktoberfest","ios","netstandard","nuget","orientation-lock-plugin","screen-orientation","uwp","xamarin","xamarin-android","xamarin-forms","xamarin-ios","xamarin-plugin"],"created_at":"2024-08-02T17:01:10.847Z","updated_at":"2025-05-02T21:32:07.583Z","avatar_url":"https://github.com/wcoder.png","language":"C#","readme":"## Device Orientation Plugin for Xamarin and Windows\n\nSimple cross-platform plugin to work with screen orientation of mobile device.\n\n[iOS demo](https://youtu.be/3eQDrHMPmE4)\n\n[Xamarin.Forms sample](https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation/tree/master/samples/Xamarin.Forms-sample)\n\n#### Setup\n\n* Available on NuGet: [![NuGet Badge](https://buildstats.info/nuget/Plugin.DeviceOrientation)](https://www.nuget.org/packages/Plugin.DeviceOrientation/)\n* Install into your PCL/NetStandard project and Platform Specific projects\n\n#### Platform Support\n\n|Platform|Version|\n| ------------------- | :------------------: |\n|Xamarin.iOS|iOS 10+|\n|Xamarin.Android|API 19+|\n|Windows 10 UWP|10.0.16299+|\n\nv2.0 updated to NetStandard 2.0\n\n#### Deprecated platforms\n\n* Windows Phone Silverlight\n* Windows Phone RT\n* Windows Store RT\n\nImplementations for unsupported platforms contains [here](https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation/tree/deprecated/src/DeviceOrientation/).\n\n## API Usage\n\nCall `CrossDeviceOrientation.Current` from any project or PCL to gain access to APIs.\n\n```csharp\n/// \u003csummary\u003e\n/// Gets current device orientation\n/// \u003c/summary\u003e\nDeviceOrientations CurrentOrientation { get; }\n```\n\nWhen device orientation is changed you can register for an event to fire:\n\n```csharp\n/// \u003csummary\u003e\n/// Event handler when orientation changes\n/// \u003c/summary\u003e\nevent OrientationChangedEventHandler OrientationChanged;\n```\n\nYou will get a `OrientationChangedEventArgs` with the orientation type:\n\n```csharp\npublic class OrientationChangedEventArgs : EventArgs\n{\n\tpublic DeviceOrientations Orientation { get; set; }\n}\n\npublic delegate void OrientationChangedEventHandler(object sender, OrientationChangedEventArgs e);\n```\n\nThe **DeviceOrientations** enumeration has these members.\n\n|Member|Value|Description|\n| :----------------: | :-----------: | :------------------ |\n|**Undefined**|0|No display orientation is specified.|\n|**Landscape**|1|Specifies that the monitor is oriented in landscape mode where the width of the display viewing area is greater than the height.|\n|**Portrait**|2|Specifies that the monitor rotated 90 degrees in the clockwise direction to orient the display in portrait mode where the height of the display viewing area is greater than the width.|\n|**LandscapeFlipped**|4|Specifies that the monitor rotated another 90 degrees in the clockwise direction (to equal 180 degrees) to orient the display in landscape mode where the width of the display viewing area is greater than the height. This landscape mode is flipped 180 degrees from the **Landscape** mode.|\n|**PortraitFlipped**|8|Specifies that the monitor rotated another 90 degrees in the clockwise direction (to equal 270 degrees) to orient the display in portrait mode where the height of the display viewing area is greater than the width. This portrait mode is flipped 180 degrees from the **Portrait** mode.|\n\nCall `LockOrientation` for set orientation and lock with disabling device auto-rotation:\n```csharp\n/// \u003csummary\u003e\n///     Lock orientation in the specified position\n/// \u003c/summary\u003e\n/// \u003cparam name=\"orientation\"\u003ePosition for lock.\u003c/param\u003e\nvoid LockOrientation(DeviceOrientations orientation);\n```\nFor disable the lock, call `UnlockOrientation` method:\n```csharp\n/// \u003csummary\u003e\n///     Unlock orientation\n/// \u003c/summary\u003e\nvoid UnlockOrientation();\n```\n\n### iOS Specific Support\n\nAdd this code for your ViewController where you want locking orientation:\n```csharp\npublic override bool ShouldAutorotate()\n{\n\t// set plugin for handle of this method\n\treturn DeviceOrientationImplementation.ShouldAutorotate;\n}\n\npublic override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()\n{\n\t// allow all orientations\n\treturn UIInterfaceOrientationMask.AllButUpsideDown;\n}\n```\nIn your `Info.plist` need set all device orientations.\n\n#### Xamarin.Forms iOS\n\nIf you want to lock orientation for the entire iOS application.\n\nAdd this code in your `AppDelegate.cs`:\n```csharp\n[Export(\"application:supportedInterfaceOrientationsForWindow:\")]\npublic UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)\n{\n    return DeviceOrientationImplementation.SupportedInterfaceOrientations;\n}\n```\n**Note:** In this case, to lock/unlock orientation on the one screen, you must use the `LockOrientation`/`UnlockOrientation` methods.\n\n#### Xamarin.Forms Android\n\nIn your `MainActivity.cs`, add overriding for changing orientation as here:\n\n```csharp\npublic override void OnConfigurationChanged(Configuration newConfig)\n{\n    base.OnConfigurationChanged(newConfig);\n\n    DeviceOrientationImplementation.NotifyOrientationChange(newConfig.Orientation);\n}\n```\n**Note:** This solution has only two state **Portrait** and **Landscape**.\n\n## Additional information\n* [Android - Handling Rotation](https://developer.xamarin.com/guides/android/application_fundamentals/handling_rotation/)\n* [Xamarin.Forms - Device Orientation](https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/device-orientation/)\n\n## Troubleshooting\n* [See in the issues](https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation/issues?q=label%3Afaq)\n\n\n\n## Contributors\n* [Yauheni Pakala](https://github.com/wcoder)\n\n---\n\u0026copy; 2016-2019 MIT License\n","funding_links":[],"categories":["Xamarin.Forms"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcoder%2FXamarin.Plugin.DeviceOrientation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwcoder%2FXamarin.Plugin.DeviceOrientation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcoder%2FXamarin.Plugin.DeviceOrientation/lists"}