|
1 | 1 | using System;
|
| 2 | +using System.Drawing; |
2 | 3 | using Microsoft.Maui.Controls;
|
| 4 | +using Microsoft.Maui.Controls.PlatformConfiguration; |
| 5 | +using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific; |
3 | 6 |
|
4 | 7 | namespace Maui.Controls.Sample.Pages
|
5 | 8 | {
|
6 | 9 | public partial class iOSModalPagePresentationStyle : ContentPage
|
7 | 10 | {
|
| 11 | + bool isChildPage; |
| 12 | + |
| 13 | + public Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.UIModalPresentationStyle presentationStyle = |
| 14 | + Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.Automatic; |
| 15 | + |
8 | 16 | public iOSModalPagePresentationStyle()
|
9 | 17 | {
|
10 | 18 | InitializeComponent();
|
11 | 19 | }
|
12 | 20 |
|
| 21 | + public iOSModalPagePresentationStyle(UIModalPresentationStyle presentationStyle, bool isChildPage = true, |
| 22 | + View? modalOrigin = null, Rectangle? rectangle = null) |
| 23 | + { |
| 24 | + InitializeComponent(); |
| 25 | + |
| 26 | + if(modalOrigin is not null) |
| 27 | + { |
| 28 | + On<iOS>().SetModalPopoverView(modalOrigin); |
| 29 | + } |
| 30 | + |
| 31 | + if(rectangle is not null) |
| 32 | + { |
| 33 | + On<iOS>().SetModalPopoverRect(rectangle.Value); |
| 34 | + } |
| 35 | + |
| 36 | + On<iOS>().SetModalPresentationStyle(presentationStyle); |
| 37 | + |
| 38 | + this.isChildPage = isChildPage; |
| 39 | + } |
| 40 | + |
| 41 | + async void OnPushFormSheetClicked(object sender, EventArgs e) |
| 42 | + { |
| 43 | + Microsoft.Maui.Controls.Page pushMe = new iOSModalPagePresentationStyle(UIModalPresentationStyle.FormSheet, true); |
| 44 | + await Navigation.PushModalAsync(pushMe); |
| 45 | + } |
| 46 | + |
| 47 | + async void OnPushPopoverClicked(object sender, EventArgs e) |
| 48 | + { |
| 49 | + Microsoft.Maui.Controls.Page pushMe = new iOSModalPagePresentationStyle(UIModalPresentationStyle.Popover, true, originButton); |
| 50 | + await Navigation.PushModalAsync(pushMe); |
| 51 | + } |
| 52 | + |
| 53 | + async void OnPushPopoverOffsetClicked(object sender, EventArgs e) |
| 54 | + { |
| 55 | + var offset = new System.Drawing.Rectangle(0, 0, 100, 10); |
| 56 | + Microsoft.Maui.Controls.Page pushMe = new iOSModalPagePresentationStyle(UIModalPresentationStyle.Popover, true, originButton2, offset); |
| 57 | + await Navigation.PushModalAsync(pushMe); |
| 58 | + } |
| 59 | + |
13 | 60 | async void OnReturnButtonClicked(object sender, EventArgs e)
|
14 | 61 | {
|
15 |
| - await Navigation.PopModalAsync(); |
| 62 | + if (isChildPage) |
| 63 | + { |
| 64 | + await Navigation.PopModalAsync(); |
| 65 | + } |
| 66 | + else |
| 67 | + { |
| 68 | + await Navigation.PopAsync(); |
| 69 | + } |
16 | 70 | }
|
17 | 71 | }
|
18 | 72 | }
|
0 commit comments