Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Version 1.0.5 #4

Merged
merged 6 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
```
In your `Info.plist` need set all device orientations.

#### Xamarin.Forms iOS

If you want to lock orientation for the entire iOS application.

Add this code in your `AppDelegate.cs`:
```csharp
[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
{
return DeviceOrientationImplementation.SupportedInterfaceOrientations;
}
```
**Note:** In this case, to lock/unlock orientation on the one screen, you must use the `LockOrientation`/`UnlockOrientation` methods.

## Additional information
* [Android - Handling Rotation](https://developer.xamarin.com/guides/android/application_fundamentals/handling_rotation/)
* [Xamarin.Forms - Device Orientation](https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/device-orientation/)
Expand Down
2 changes: 1 addition & 1 deletion nuget/DeviceOrientation.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.1">
<id>Plugin.DeviceOrientation</id>
<version>1.0.4</version>
<version>1.0.5</version>
<title>Device Orientation Plugin for Xamarin and Windows</title>
<authors>Yauheni Pakala</authors>
<owners>Yauheni Pakala</owners>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)

return base.FinishedLaunching(app, options);
}


// Details: https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation#xamarinforms-ios
[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
{
return Plugin.DeviceOrientation.DeviceOrientationImplementation.SupportedInterfaceOrientations;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
xmlns:local="clr-namespace:TestNugetDeviceOrientationPlugin"
x:Class="TestNugetDeviceOrientationPlugin.MainPage">

<Label x:Name="OrientationLabel" Text="..."
VerticalOptions="Center"
HorizontalOptions="Center" />
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Click for lock/unlock:" />
<Button x:Name="OrientationLabel" Text="..." />
</StackLayout>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
using Xamarin.Forms;

using Plugin.DeviceOrientation;

namespace TestNugetDeviceOrientationPlugin
{
public partial class MainPage : ContentPage
{
private bool _isLocked;

public MainPage()
{
InitializeComponent();

OrientationLabel.Text = CrossDeviceOrientation.Current.CurrentOrientation.ToString();
CrossDeviceOrientation.Current.OrientationChanged += Current_OrientationChanged;
}

private void Current_OrientationChanged(object sender, Plugin.DeviceOrientation.Abstractions.OrientationChangedEventArgs e)
{
OrientationLabel.Text = e.Orientation.ToString();
// sample of screen orientation lock
OrientationLabel.Clicked += (sender, args) =>
{
_isLocked = !_isLocked;

if (_isLocked)
CrossDeviceOrientation.Current.LockOrientation(CrossDeviceOrientation.Current.CurrentOrientation);
else
CrossDeviceOrientation.Current.UnlockOrientation();
};

// the sample of the event handler when screen orientation will change
CrossDeviceOrientation.Current.OrientationChanged += (sender, args) =>
{
OrientationLabel.Text = args.Orientation.ToString();
};
}
}
}
27 changes: 15 additions & 12 deletions src/DeviceOrientation.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.DeviceOrientation", "DeviceOrientation\Plugin.DeviceOrientation\Plugin.DeviceOrientation.csproj", "{A6FCEF44-D2BA-42C7-B3CB-13667BCD7B54}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.DeviceOrientation", "DeviceOrientation\Plugin.DeviceOrientation\Plugin.DeviceOrientation.csproj", "{A6FCEF44-D2BA-42C7-B3CB-13667BCD7B54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.DeviceOrientation.Abstractions", "DeviceOrientation\Plugin.DeviceOrientation.Abstractions\Plugin.DeviceOrientation.Abstractions.csproj", "{6EDB0588-FFC5-4EF5-8A99-9E241D0F878D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.DeviceOrientation.Abstractions", "DeviceOrientation\Plugin.DeviceOrientation.Abstractions\Plugin.DeviceOrientation.Abstractions.csproj", "{6EDB0588-FFC5-4EF5-8A99-9E241D0F878D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.DeviceOrientation.iOS", "DeviceOrientation\Plugin.DeviceOrientation.iOS\Plugin.DeviceOrientation.iOS.csproj", "{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}"
EndProject
Expand Down Expand Up @@ -83,14 +83,14 @@ Global
{6EDB0588-FFC5-4EF5-8A99-9E241D0F878D}.Release|x64.Build.0 = Release|Any CPU
{6EDB0588-FFC5-4EF5-8A99-9E241D0F878D}.Release|x86.ActiveCfg = Release|Any CPU
{6EDB0588-FFC5-4EF5-8A99-9E241D0F878D}.Release|x86.Build.0 = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|Any CPU.ActiveCfg = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|Any CPU.Build.0 = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|ARM.ActiveCfg = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|ARM.Build.0 = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x64.ActiveCfg = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x64.Build.0 = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x86.ActiveCfg = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x86.Build.0 = AppStore|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|Any CPU.Build.0 = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|ARM.ActiveCfg = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|ARM.Build.0 = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x64.ActiveCfg = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x64.Build.0 = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x86.ActiveCfg = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.AppStore|x86.Build.0 = Release|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}.Debug|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -231,4 +231,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9D655DC-088A-4F34-AE25-491866568F90}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -40,7 +40,7 @@
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="Plugin.CurrentActivity, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\samples\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
<HintPath>..\..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid71" />
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid80" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static bool ShouldAutorotate
public override DeviceOrientations CurrentOrientation =>
Convert(UIApplication.SharedApplication.StatusBarOrientation);

public static UIInterfaceOrientationMask SupportedInterfaceOrientations =>
ConvertToMask(_lockedOrientation);

public override void LockOrientation(DeviceOrientations orientation)
{
Expand Down Expand Up @@ -106,6 +108,23 @@ private void SetDeviceOrientation(DeviceOrientations orientation)
});
}

private static UIInterfaceOrientationMask ConvertToMask(DeviceOrientations orientation)
{
switch (orientation)
{
case DeviceOrientations.Portrait:
return UIInterfaceOrientationMask.Portrait;
case DeviceOrientations.PortraitFlipped:
return UIInterfaceOrientationMask.PortraitUpsideDown;
case DeviceOrientations.LandscapeFlipped:
return UIInterfaceOrientationMask.LandscapeRight;
case DeviceOrientations.Landscape:
return UIInterfaceOrientationMask.LandscapeLeft;
default:
return UIInterfaceOrientationMask.AllButUpsideDown;
}
}

private UIInterfaceOrientation Convert(DeviceOrientations orientation)
{
switch (orientation)
Expand Down