Skip to content

Commit c004621

Browse files
CopilotPureWeen
authored andcommitted
Revert "Revert formatting-only changes to focus on functional changes"
This reverts commit 534c071.
1 parent ab2c4a7 commit c004621

File tree

12 files changed

+349
-354
lines changed

12 files changed

+349
-354
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void OnFlyoutStateChanging(object sender, AndroidX.DrawerLayout.Widget.DrawerLay
8585
// - Keep this minimal.
8686
// - Will be replaced by the planned comprehensive window insets solution.
8787
// - Do not extend; add new logic to the forthcoming implementation instead.
88-
internal class WindowsListener : Java.Lang.Object, IOnApplyWindowInsetsListener
88+
internal class WindowsListener : MauiWindowInsetListener, IOnApplyWindowInsetsListener
8989
{
9090
private WeakReference<ImageView> _bgImageRef;
9191
private WeakReference<AView> _flyoutViewRef;
@@ -100,10 +100,10 @@ public AView FlyoutView
100100

101101
return null;
102102
}
103-
set
104-
{
103+
set
104+
{
105105
_flyoutViewRef = new WeakReference<AView>(value);
106-
}
106+
}
107107
}
108108
public AView FooterView
109109
{
@@ -114,62 +114,68 @@ public AView FooterView
114114

115115
return null;
116116
}
117-
set
118-
{
117+
set
118+
{
119119
_footerViewRef = new WeakReference<AView>(value);
120-
}
120+
}
121121
}
122122

123123
public WindowsListener(ImageView bgImage)
124124
{
125125
_bgImageRef = new WeakReference<ImageView>(bgImage);
126126
}
127127

128-
public WindowInsetsCompat OnApplyWindowInsets(AView v, WindowInsetsCompat insets)
128+
public override WindowInsetsCompat OnApplyWindowInsets(AView v, WindowInsetsCompat insets)
129129
{
130130
if (insets == null || v == null)
131131
return insets;
132132

133-
// The flyout overlaps the status bar so we don't really care about insetting it
134-
var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
135-
var displayCutout = insets.GetInsets(WindowInsetsCompat.Type.DisplayCutout());
136-
var topInset = Math.Max(systemBars?.Top ?? 0, displayCutout?.Top ?? 0);
137-
var bottomInset = Math.Max(systemBars?.Bottom ?? 0, displayCutout?.Bottom ?? 0);
138-
var appbarLayout = v.FindDescendantView<AppBarLayout>((v) => true);
133+
if (v is CoordinatorLayout)
134+
{
135+
// The flyout overlaps the status bar so we don't really care about insetting it
136+
var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
137+
var displayCutout = insets.GetInsets(WindowInsetsCompat.Type.DisplayCutout());
138+
var topInset = Math.Max(systemBars?.Top ?? 0, displayCutout?.Top ?? 0);
139+
var bottomInset = Math.Max(systemBars?.Bottom ?? 0, displayCutout?.Bottom ?? 0);
140+
var appbarLayout = v.FindDescendantView<AppBarLayout>((v) => true);
139141

140-
int flyoutViewBottomInset = 0;
142+
int flyoutViewBottomInset = 0;
141143

142-
if (FooterView is not null)
143-
{
144-
v.SetPadding(0, 0, 0, bottomInset);
145-
flyoutViewBottomInset = 0;
146-
}
147-
else
148-
{
149-
flyoutViewBottomInset = bottomInset;
150-
v.SetPadding(0, 0, 0, 0);
151-
}
144+
if (FooterView is not null)
145+
{
146+
v.SetPadding(0, 0, 0, bottomInset);
147+
flyoutViewBottomInset = 0;
148+
}
149+
else
150+
{
151+
flyoutViewBottomInset = bottomInset;
152+
v.SetPadding(0, 0, 0, 0);
153+
}
152154

153-
if (appbarLayout.MeasuredHeight > 0)
154-
{
155-
FlyoutView?.SetPadding(0, 0, 0, flyoutViewBottomInset);
156-
appbarLayout?.SetPadding(0, topInset, 0, 0);
157-
}
158-
else
159-
{
160-
FlyoutView?.SetPadding(0, topInset, 0, flyoutViewBottomInset);
161-
appbarLayout?.SetPadding(0, 0, 0, 0);
162-
}
155+
if (appbarLayout.MeasuredHeight > 0)
156+
{
157+
FlyoutView?.SetPadding(0, 0, 0, flyoutViewBottomInset);
158+
appbarLayout?.SetPadding(0, topInset, 0, 0);
159+
}
160+
else
161+
{
162+
FlyoutView?.SetPadding(0, topInset, 0, flyoutViewBottomInset);
163+
appbarLayout?.SetPadding(0, 0, 0, 0);
164+
}
163165

164-
if (_bgImageRef != null && _bgImageRef.TryGetTarget(out var bgImage) && bgImage != null)
165-
{
166-
bgImage.SetPadding(0, topInset, 0, bottomInset);
166+
if (_bgImageRef != null && _bgImageRef.TryGetTarget(out var bgImage) && bgImage != null)
167+
{
168+
bgImage.SetPadding(0, topInset, 0, bottomInset);
169+
}
170+
171+
return WindowInsetsCompat.Consumed;
167172
}
168173

169-
return WindowInsetsCompat.Consumed;
174+
175+
return base.OnApplyWindowInsets(v, insets);
170176
}
171177
}
172-
178+
173179
protected virtual void LoadView(IShellContext shellContext)
174180
{
175181
var context = shellContext.AndroidContext;
@@ -202,7 +208,7 @@ protected virtual void LoadView(IShellContext shellContext)
202208
};
203209

204210
_windowsListener = new WindowsListener(_bgImage);
205-
ViewCompat.SetOnApplyWindowInsetsListener(coordinator, _windowsListener);
211+
MauiWindowInsetListener.SetupViewWithLocalListener(coordinator, _windowsListener);
206212

207213
UpdateFlyoutHeaderBehavior();
208214
_shellContext.Shell.PropertyChanged += OnShellPropertyChanged;
@@ -718,6 +724,12 @@ public void OnOffsetChanged(AppBarLayout appBarLayout, int verticalOffset)
718724

719725
internal void Disconnect()
720726
{
727+
728+
if (_rootView is CoordinatorLayout coordinator)
729+
{
730+
MauiWindowInsetListener.RemoveViewWithLocalListener(coordinator);
731+
}
732+
721733
if (_shellContext?.Shell != null)
722734
_shellContext.Shell.PropertyChanged -= OnShellPropertyChanged;
723735

@@ -726,14 +738,12 @@ internal void Disconnect()
726738

727739
_flyoutHeader = null;
728740

729-
if (_footerView != null)
730-
_footerView.View = null;
741+
_footerView?.View = null;
731742

732743
_headerView?.Disconnect();
733744
DisconnectRecyclerView();
734745

735-
if (_contentView != null)
736-
_contentView.View = null;
746+
_contentView?.View = null;
737747
}
738748

739749
protected override void Dispose(bool disposing)
@@ -764,8 +774,7 @@ protected override void Dispose(bool disposing)
764774
if (_headerView != null)
765775
_headerView.LayoutChange -= OnHeaderViewLayoutChange;
766776

767-
if (_contentView != null)
768-
_contentView.View = null;
777+
_contentView?.View = null;
769778

770779
_flyoutContentView?.Dispose();
771780
_headerView?.Dispose();

src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,7 @@ protected virtual async void UpdateLeftBarButtonItem(Context context, AToolbar t
474474
defaultDrawerArrowDrawable = true;
475475
}
476476

477-
if (icon != null)
478-
icon.Progress = (CanNavigateBack) ? 1 : 0;
477+
icon?.Progress = (CanNavigateBack) ? 1 : 0;
479478

480479
if (command != null || CanNavigateBack)
481480
{

src/Core/src/Platform/Android/EditTextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ internal static bool HandleClearButtonTouched(this EditText? platformView, Touch
414414
// Android.Graphics.Rect has a Containts(x,y) method, but it only takes `int` and the coordinates from
415415
// the motion event are `float`. The we use GetX() and GetY() so our coordinates are relative to the
416416
// bounds of the EditText.
417-
static bool RectContainsMotionEvent(global::Android.Graphics.Rect rect, MotionEvent motionEvent)
417+
static bool RectContainsMotionEvent(global::Android.Graphics.Rect rect, MotionEvent motionEvent)
418418
{
419419
var x = motionEvent.GetX();
420420

src/Core/src/Platform/Android/IHandleWindowInsets.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33

44
namespace Microsoft.Maui.Platform
55
{
6-
/// <summary>
7-
/// Interface for views that need to handle their own window insets behavior
8-
/// </summary>
9-
internal interface IHandleWindowInsets
10-
{
11-
/// <summary>
12-
/// Handles window insets for this view
13-
/// </summary>
14-
/// <param name="view">The view receiving the insets</param>
15-
/// <param name="insets">The window insets</param>
16-
/// <returns>The processed window insets</returns>
17-
WindowInsetsCompat? HandleWindowInsets(AView view, WindowInsetsCompat insets);
6+
/// <summary>
7+
/// Interface for views that need to handle their own window insets behavior
8+
/// </summary>
9+
internal interface IHandleWindowInsets
10+
{
11+
/// <summary>
12+
/// Handles window insets for this view
13+
/// </summary>
14+
/// <param name="view">The view receiving the insets</param>
15+
/// <param name="insets">The window insets</param>
16+
/// <returns>The processed window insets</returns>
17+
WindowInsetsCompat? HandleWindowInsets(AView view, WindowInsetsCompat insets);
1818

19-
/// <summary>
20-
/// Resets any previously applied insets on this view
21-
/// </summary>
22-
/// <param name="view">The view to reset</param>
23-
void ResetWindowInsets(AView view);
24-
}
19+
/// <summary>
20+
/// Resets any previously applied insets on this view
21+
/// </summary>
22+
/// <param name="view">The view to reset</param>
23+
void ResetWindowInsets(AView view);
24+
}
2525
}

src/Core/src/Platform/Android/MauiPageControl.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ void UpdateShapes()
154154
shape.SetIntrinsicHeight((int)Context.ToPixels(indicatorSize));
155155
shape.SetIntrinsicWidth((int)Context.ToPixels(indicatorSize));
156156

157-
if (shape.Paint != null)
158-
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
159-
shape.Paint.Color = color;
157+
shape.Paint?.Color = color;
160158
#pragma warning restore CA1416
161159

162160
return shape;

src/Core/src/Platform/Android/MauiSwipeView.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,7 @@ static void ExecuteSwipeItem(ISwipeItem item)
13201320

13211321
void EnableParentGesture(bool isGestureEnabled)
13221322
{
1323-
if (_viewPagerParent != null)
1324-
_viewPagerParent.EnableGesture = isGestureEnabled;
1323+
_viewPagerParent?.EnableGesture = isGestureEnabled;
13251324
}
13261325

13271326
internal void OnOpenRequested(SwipeViewOpenRequest e)

src/Core/src/Platform/Android/MauiWebView.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public MauiWebView(WebViewHandler handler, Context context) : base(context)
1717

1818
void IWebViewDelegate.LoadHtml(string? html, string? baseUrl)
1919
{
20-
if (_handler != null)
21-
_handler.CurrentNavigationEvent = WebNavigationEvent.NewPage;
20+
_handler?.CurrentNavigationEvent = WebNavigationEvent.NewPage;
2221

2322
LoadDataWithBaseURL(baseUrl ?? AssetBaseUrl, html ?? string.Empty, "text/html", "UTF-8", null);
2423
}
@@ -27,10 +26,7 @@ void IWebViewDelegate.LoadUrl(string? url)
2726
{
2827
if (!_handler.NavigatingCanceled(url))
2928
{
30-
if (_handler != null)
31-
{
32-
_handler.CurrentNavigationEvent = WebNavigationEvent.NewPage;
33-
}
29+
_handler?.CurrentNavigationEvent = WebNavigationEvent.NewPage;
3430

3531
if (url is not null && !url.StartsWith('/') && !Uri.TryCreate(url, UriKind.Absolute, out _))
3632
{

src/Core/src/Platform/Android/PickerExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ internal static void UpdateFlowDirection(this AppCompatAlertDialog alertDialog,
5757
// Propagate the MauiPicker LayoutDirection to the AlertDialog
5858
var dv = alertDialog.Window?.DecorView;
5959

60-
if (dv is not null)
61-
dv.LayoutDirection = platformLayoutDirection;
60+
dv?.LayoutDirection = platformLayoutDirection;
6261

6362
var lv = alertDialog?.ListView;
6463

0 commit comments

Comments
 (0)