Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 2e6754d

Browse files
committed
Processed feedback
1 parent 9e5a60b commit 2e6754d

File tree

7 files changed

+53
-28
lines changed

7 files changed

+53
-28
lines changed

Xamarin.Forms.Controls/GalleryPages/PageWithTransparentBkgnd.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
x:Class="Xamarin.Forms.Controls.GalleryPages.PageWithTransparentBkgnd"
88
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
99
ios:Page.UseSafeArea="true"
10-
BackgroundColor="Transparent"
11-
ModalBackgroundColor="#700000FF"
10+
BackgroundColor="#700000FF"
1211
ios:Page.ModalPresentationStyle="OverFullScreen">
1312
<Frame VerticalOptions="Center"
1413
HorizontalOptions="Center"

Xamarin.Forms.Core/Page.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class Page : VisualElement, ILayout, IPageController, IElementConfigurati
4242
[EditorBrowsable(EditorBrowsableState.Never)]
4343
public static readonly BindableProperty IconProperty = IconImageSourceProperty;
4444

45-
public static readonly BindableProperty ModalBackgroundColorProperty = BindableProperty.Create(nameof(ModalBackgroundColor), typeof(Color), typeof(Page), Color.Default);
46-
4745
readonly Lazy<PlatformConfigurationRegistry<Page>> _platformConfigurationRegistry;
4846

4947
bool _allocatedFlag;
@@ -155,12 +153,6 @@ public bool IgnoresContainerArea
155153
[EditorBrowsable(EditorBrowsableState.Never)]
156154
public ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
157155

158-
public Color ModalBackgroundColor
159-
{
160-
get { return (Color)GetValue(ModalBackgroundColorProperty); }
161-
set { SetValue(ModalBackgroundColorProperty, value); }
162-
}
163-
164156
internal override IEnumerable<Element> ChildrenNotDrawnByThisElement
165157
{
166158
get

Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/UIModalPresentationStyle.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public enum UIModalPresentationStyle
44
{
55
FullScreen,
66
FormSheet,
7-
OverFullScreen
7+
OverFullScreen,
8+
PageSheet,
9+
Automatic
810
}
911
}

Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public static UIModalPresentationStyle ToNativeModalPresentationStyle(this Platf
8686
return UIModalPresentationStyle.FullScreen;
8787
case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.OverFullScreen:
8888
return UIModalPresentationStyle.OverFullScreen;
89+
case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.PageSheet:
90+
return UIModalPresentationStyle.PageSheet;
91+
case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.Automatic:
92+
return UIModalPresentationStyle.Automatic;
8993
default:
9094
throw new ArgumentOutOfRangeException(nameof(style));
9195
}

Xamarin.Forms.Platform.iOS/ModalWrapper.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,21 @@ public override UIViewController ChildViewControllerForStatusBarStyle()
123123

124124
void OnModalPagePropertyChanged(object sender, PropertyChangedEventArgs e)
125125
{
126-
if (e.PropertyName == Page.ModalBackgroundColorProperty.PropertyName)
126+
if (e.PropertyName == Page.BackgroundColorProperty.PropertyName)
127127
UpdateBackgroundColor();
128128
}
129129

130130
void UpdateBackgroundColor()
131131
{
132-
Color modalBkgndColor = ((Page)_modal.Element).ModalBackgroundColor;
133-
View.BackgroundColor = modalBkgndColor.IsDefault ? UIColor.White : modalBkgndColor.ToUIColor();
132+
if (ModalPresentationStyle == UIKit.UIModalPresentationStyle.FullScreen)
133+
{
134+
Color modalBkgndColor = ((Page)_modal.Element).BackgroundColor;
135+
View.BackgroundColor = modalBkgndColor.IsDefault ? UIColor.White : modalBkgndColor.ToUIColor();
136+
}
137+
else
138+
{
139+
View.BackgroundColor = UIColor.Clear;
140+
}
134141
}
135142
}
136143
}

Xamarin.Forms.Platform.iOS/PageExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using UIKit;
34

45
namespace Xamarin.Forms
@@ -39,5 +40,17 @@ public static UIViewController CreateViewController(this ContentPage page)
3940
{
4041
return Xamarin.Forms.PageExtensions.CreateViewController(page);
4142
}
43+
44+
internal static Page GetCurrentPage(this Page currentPage)
45+
{
46+
if (currentPage.NavigationProxy.ModalStack.LastOrDefault() is Page modal)
47+
return modal;
48+
else if (currentPage is MasterDetailPage mdp)
49+
return GetCurrentPage(mdp.Detail);
50+
else if (currentPage is IPageContainer<Page> pc)
51+
return GetCurrentPage(pc.CurrentPage);
52+
else
53+
return currentPage;
54+
}
4255
}
4356
}

Xamarin.Forms.Platform.iOS/Platform.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async Task<Page> INavigation.PopModalAsync(bool animated)
120120
modal.DisposeModalAndChildRenderers();
121121

122122
if (IsModalPresentedOverContext(modal))
123-
GetCurentPage(Page)?.SendAppearing();
123+
Page.GetCurrentPage()?.SendAppearing();
124124

125125
return modal;
126126
}
@@ -154,8 +154,27 @@ Task INavigation.PushModalAsync(Page modal, bool animated)
154154
{
155155
EndEditing();
156156

157-
if (_appeared && IsModalPresentedOverContext(modal))
158-
GetCurentPage(Page)?.SendDisappearing();
157+
var elementConfiguration = modal as IElementConfiguration<Page>;
158+
159+
var presentationStyle = elementConfiguration?.On<PlatformConfiguration.iOS>()?.ModalPresentationStyle().ToNativeModalPresentationStyle();
160+
161+
bool shouldFire = true;
162+
163+
if (Forms.IsiOS13OrNewer)
164+
{
165+
if (presentationStyle == UIKit.UIModalPresentationStyle.FullScreen)
166+
shouldFire = false; //this is mainly for backwards compatibility
167+
}
168+
else
169+
{
170+
if (presentationStyle == UIKit.UIModalPresentationStyle.Automatic)
171+
shouldFire = false;
172+
else if (presentationStyle == UIKit.UIModalPresentationStyle.FullScreen)
173+
shouldFire = false; //this is mainly for backwards compatibility
174+
}
175+
176+
if (_appeared && shouldFire)
177+
Page.GetCurrentPage()?.SendDisappearing();
159178

160179
_modals.Add(modal);
161180

@@ -605,17 +624,6 @@ internal void CleanUpPages()
605624
(Page.Parent as IDisposable)?.Dispose();
606625
}
607626

608-
Page GetCurentPage(Page currentPage)
609-
{
610-
if (_modals.LastOrDefault() is Page modal)
611-
return modal;
612-
else if (currentPage is MasterDetailPage mdp)
613-
return GetCurentPage(mdp.Detail);
614-
else if (currentPage is IPageContainer<Page> pc)
615-
return GetCurentPage(pc.CurrentPage);
616-
else
617-
return currentPage;
618-
}
619627

620628
static bool IsModalPresentedOverContext(Page modal)
621629
{

0 commit comments

Comments
 (0)