Skip to content

Commit 9968b17

Browse files
authored
Merge pull request #50 from FabriBertani/iPhoneSafeAreaSupport
Added support for iPhone X Safe Area.
2 parents 2fab17b + a49570c commit 9968b17

File tree

14 files changed

+190
-10
lines changed

14 files changed

+190
-10
lines changed

Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,41 @@ namespace Cirrious.FluentLayouts.Touch
1515
{
1616
public static class AdvancedFluentLayoutExtensions
1717
{
18-
const float DefaultMargin = 0;
19-
const float DefaultScale = 1;
18+
const float DefaultMargin = 0;
19+
const float DefaultScale = 1;
2020

2121
public static FluentLayout AtTopOf(this UIView view, UIView parentView, nfloat? margin = null) =>
22-
view.Top().EqualTo().TopOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin));
22+
view.Top().EqualTo().TopOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin));
23+
24+
public static FluentLayout AtTopOfWithSafeArea(this UIView view, UIView parentView, nfloat? margin = null) =>
25+
UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
26+
? view.Top().EqualTo().TopOf(parentView.SafeAreaLayoutGuide).Plus(margin.GetValueOrDefault(DefaultMargin))
27+
: view.AtTopOf(parentView, margin);
2328

2429
public static FluentLayout AtLeftOf(this UIView view, UIView parentView, nfloat? margin = null) =>
2530
view.Left().EqualTo().LeftOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin));
2631

32+
public static FluentLayout AtLeftOfWithSafeArea(this UIView view, UIView parentView, nfloat? margin = null) =>
33+
UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
34+
? view.Left().EqualTo().LeftOf(parentView.SafeAreaLayoutGuide).Plus(margin.GetValueOrDefault(DefaultMargin))
35+
: view.AtLeftOf(parentView, margin);
36+
2737
public static FluentLayout AtRightOf(this UIView view, UIView parentView, nfloat? margin = null) =>
2838
view.Right().EqualTo().RightOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin));
2939

40+
public static FluentLayout AtRightOfWithSafeArea(this UIView view, UIView parentView, nfloat? margin = null) =>
41+
UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
42+
? view.Right().EqualTo().RightOf(parentView.SafeAreaLayoutGuide).Minus(margin.GetValueOrDefault(DefaultMargin))
43+
: view.AtRightOf(parentView, margin);
44+
3045
public static FluentLayout AtBottomOf(this UIView view, UIView parentView, nfloat? margin = null) =>
3146
view.Bottom().EqualTo().BottomOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin));
3247

48+
public static FluentLayout AtBottomOfWithSafeArea(this UIView view, UIView parentView, nfloat? margin = null) =>
49+
UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
50+
? view.Bottom().EqualTo().BottomOf(parentView.SafeAreaLayoutGuide).Minus(margin.GetValueOrDefault(DefaultMargin))
51+
: view.AtBottomOf(parentView, margin);
52+
3353
public static FluentLayout AtLeadingOf(this UIView view, UIView parentView, nfloat? margin = null) =>
3454
view.Leading().EqualTo().LeadingOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin));
3555

QuickLayout.Core/QuickLayout.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="ViewModels\AdvancedVerticalStackViewModel.cs" />
5050
<Compile Include="ViewModels\DirectionFormViewModel.cs" />
5151
<Compile Include="ViewModels\RightToLeftViewModel.cs" />
52+
<Compile Include="ViewModels\ViewWithSafeAreaViewModel.cs" />
5253
</ItemGroup>
5354
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
5455
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

QuickLayout.Core/ViewModels/FirstViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ public class FirstViewModel
2424
public void GoDirectionForm() => ShowViewModel<DirectionFormViewModel>();
2525

2626
public void GoRightToLeft() => ShowViewModel<RightToLeftViewModel>();
27+
28+
public void GoViewWithSafeArea() => ShowViewModel<ViewWithSafeAreaViewModel>();
2729
}
2830
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using MvvmCross.Core.ViewModels;
3+
4+
namespace QuickLayout.Core.ViewModels
5+
{
6+
public class ViewWithSafeAreaViewModel
7+
: MvxViewModel
8+
{
9+
}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"images":[],"info":{"version":1,"author":"xcode"}}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"images": [
3+
{
4+
"orientation": "portrait",
5+
"idiom": "iphone",
6+
"extent": "full-screen",
7+
"filename": "Default.png",
8+
"size": "320x480",
9+
"scale": "1x"
10+
},
11+
{
12+
"orientation": "portrait",
13+
"idiom": "iphone",
14+
"extent": "full-screen",
15+
"filename": "[email protected]",
16+
"size": "320x480",
17+
"scale": "2x"
18+
},
19+
{
20+
"orientation": "portrait",
21+
"idiom": "iphone",
22+
"extent": "full-screen",
23+
"filename": "[email protected]",
24+
"size": "320x568",
25+
"subtype": "retina4",
26+
"scale": "2x"
27+
}
28+
],
29+
"info": {
30+
"version": 1,
31+
"author": "xcode"
32+
}
33+
}

QuickLayout.Touch/Info.plist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<string>UIInterfaceOrientationLandscapeRight</string>
1414
</array>
1515
<key>MinimumOSVersion</key>
16-
<string>7.0</string>
16+
<string>8.0</string>
1717
<key>CFBundleDisplayName</key>
1818
<string>QuickLayout</string>
1919
<key>CFBundleIdentifier</key>
@@ -24,5 +24,7 @@
2424
<string></string>
2525
<key>CFBundleName</key>
2626
<string>QuickLayout</string>
27+
<key>UILaunchStoryboardName</key>
28+
<string>LaunchScreen</string>
2729
</dict>
2830
</plist>

0 commit comments

Comments
 (0)