|
1 |
| -using MauiReactor.Internals; |
2 |
| - |
3 |
| -namespace MauiReactor; |
4 |
| - |
5 |
| -public partial class ContentPage<T> : TemplatedPage<T>, IContentPage where T : Microsoft.Maui.Controls.ContentPage, new() |
6 |
| -{ |
7 |
| - protected override void OnAddChild(VisualNode widget, BindableObject childControl) |
8 |
| - { |
9 |
| - Validate.EnsureNotNull(NativeControl); |
10 |
| - |
11 |
| - if (childControl is View view) |
12 |
| - { |
13 |
| - NativeControl.Content = view; |
14 |
| - } |
15 |
| - |
16 |
| - base.OnAddChild(widget, childControl); |
17 |
| - } |
18 |
| - |
19 |
| - protected override void OnRemoveChild(VisualNode widget, BindableObject childControl) |
20 |
| - { |
21 |
| - Validate.EnsureNotNull(NativeControl); |
22 |
| - |
23 |
| - if (childControl is View) |
24 |
| - { |
25 |
| - NativeControl.Content = null; |
26 |
| - } |
27 |
| - |
28 |
| - base.OnRemoveChild(widget, childControl); |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| - |
33 |
| -public partial class ContentPage |
34 |
| -{ |
35 |
| - private class ContentPageWithBackButtonPressedOverriden : Microsoft.Maui.Controls.ContentPage |
36 |
| - { |
37 |
| - protected override bool OnBackButtonPressed() |
38 |
| - { |
39 |
| - var backButtonBehavior = (BackButtonBehavior?)this.GetValue(Microsoft.Maui.Controls.Shell.BackButtonBehaviorProperty); |
40 |
| - |
41 |
| - if (backButtonBehavior != null && |
42 |
| - backButtonBehavior.Command != null && |
43 |
| - backButtonBehavior.Command.CanExecute(null)) |
44 |
| - { |
45 |
| - //we want to handle back button pressed event (including physical button on Android) |
46 |
| - backButtonBehavior.Command.Execute(null); |
47 |
| - return true; |
48 |
| - } |
49 |
| - |
50 |
| - return base.OnBackButtonPressed(); |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - public ContentPage(string title) => this.Title(title); |
55 |
| - |
56 |
| - protected override void OnMount() |
57 |
| - { |
58 |
| - _nativeControl ??= new ContentPageWithBackButtonPressedOverriden(); |
59 |
| - |
60 |
| - base.OnMount(); |
61 |
| - } |
62 |
| - |
63 |
| -} |
64 |
| - |
65 |
| - |
66 |
| -public partial class Component |
67 |
| -{ |
68 |
| - public static ContentPage ContentPage(string title) |
69 |
| - => new ContentPage().Title(title); |
70 |
| - |
71 |
| - public static ContentPage ContentPage(string title, params IEnumerable<VisualNode?>? children) |
72 |
| - => ContentPage(children).Title(title); |
73 |
| -} |
74 |
| - |
75 |
| -public static partial class ContentPageExtensions |
76 |
| -{ |
77 |
| - public static T HasNavigationBar<T>(this T contentPage, bool hasNavigationBar) |
78 |
| - where T : IContentPage, IVisualNodeWithAttachedProperties |
79 |
| - { |
80 |
| - contentPage.Set(Microsoft.Maui.Controls.NavigationPage.HasNavigationBarProperty, hasNavigationBar); |
81 |
| - return contentPage; |
82 |
| - } |
83 |
| - |
84 |
| -} |
| 1 | +using MauiReactor.Internals; |
| 2 | + |
| 3 | +namespace MauiReactor; |
| 4 | + |
| 5 | +public partial class ContentPage<T> : TemplatedPage<T>, IContentPage where T : Microsoft.Maui.Controls.ContentPage, new() |
| 6 | +{ |
| 7 | + protected override void OnAddChild(VisualNode widget, BindableObject childControl) |
| 8 | + { |
| 9 | + Validate.EnsureNotNull(NativeControl); |
| 10 | + |
| 11 | + if (childControl is View view) |
| 12 | + { |
| 13 | + NativeControl.Content = view; |
| 14 | + } |
| 15 | + |
| 16 | + base.OnAddChild(widget, childControl); |
| 17 | + } |
| 18 | + |
| 19 | + protected override void OnRemoveChild(VisualNode widget, BindableObject childControl) |
| 20 | + { |
| 21 | + Validate.EnsureNotNull(NativeControl); |
| 22 | + |
| 23 | + if (childControl is View) |
| 24 | + { |
| 25 | + NativeControl.Content = null; |
| 26 | + } |
| 27 | + |
| 28 | + base.OnRemoveChild(widget, childControl); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +public partial class ContentPage |
| 34 | +{ |
| 35 | + partial class ContentPageWithBackButtonPressedOverriden : Microsoft.Maui.Controls.ContentPage |
| 36 | + { |
| 37 | + protected override bool OnBackButtonPressed() |
| 38 | + { |
| 39 | + var backButtonBehavior = (BackButtonBehavior?)this.GetValue(Microsoft.Maui.Controls.Shell.BackButtonBehaviorProperty); |
| 40 | + |
| 41 | + if (backButtonBehavior != null && |
| 42 | + backButtonBehavior.Command != null && |
| 43 | + backButtonBehavior.Command.CanExecute(null)) |
| 44 | + { |
| 45 | + //we want to handle back button pressed event (including physical button on Android) |
| 46 | + backButtonBehavior.Command.Execute(null); |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + return base.OnBackButtonPressed(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public ContentPage(string title) => this.Title(title); |
| 55 | + |
| 56 | + protected override void OnMount() |
| 57 | + { |
| 58 | + _nativeControl ??= new ContentPageWithBackButtonPressedOverriden(); |
| 59 | + |
| 60 | + base.OnMount(); |
| 61 | + } |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +public partial class Component |
| 67 | +{ |
| 68 | + public static ContentPage ContentPage(string title) |
| 69 | + => new ContentPage().Title(title); |
| 70 | + |
| 71 | + public static ContentPage ContentPage(string title, params IEnumerable<VisualNode?>? children) |
| 72 | + => ContentPage(children).Title(title); |
| 73 | +} |
| 74 | + |
| 75 | +public static partial class ContentPageExtensions |
| 76 | +{ |
| 77 | + public static T HasNavigationBar<T>(this T contentPage, bool hasNavigationBar) |
| 78 | + where T : IContentPage, IVisualNodeWithAttachedProperties |
| 79 | + { |
| 80 | + contentPage.Set(Microsoft.Maui.Controls.NavigationPage.HasNavigationBarProperty, hasNavigationBar); |
| 81 | + return contentPage; |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments